See the Integer class and the static parseInt()
method:
http://developer.android.com/reference/java/lang/Integer.html
Integer.parseInt(et.getText().toString());
You will need to catch NumberFormatException
though in case of problems whilst parsing, so:
int myNum = 0; try { myNum = Integer.parseInt(et.getText().toString()); } catch(NumberFormatException nfe) { System.out.println("Could not parse " + nfe); }
Related Posts:
- How to convert any Object to String?
- int cannot be converted to string?
- Converting String Array to an Integer Array
- The specified child already has a parent. You must call removeView() on the child’s parent first (Android)
- Cannot invoke toString() on the primitive type int
- Why cannot cast Integer to String in java?
- How do I convert a String to an int in Java?
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- How to format strings in Java
- Java – Convert integer to string [duplicate]
- How to split a string in Java
- How do I compare strings in Java?
- How to convert a char to a String?
- How to convert/parse from String to char in java?
- Reverse a string in Java
- Reverse a string in Java
- Java String Split by “|”
- Convert String to double in Java
- Converting double to string
- Java String new line
- How to check if a String contains another String in a case insensitive manner in Java?
- Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
- Java split string to array [duplicate]
- String concatenation: concat() vs “+” operator
- How to remove the last character from a string?
- Error parsing data org.json.JSONException: Value
- Java string to date conversion
- How to replace � in a string
- Change date format in a Java string
- What does “|=” mean? (pipe equal operator)
- What are all the escape characters?
- Converting String to “Character” array in Java
- How do I generate random integers within a specific range in Java?
- Best way to convert an ArrayList to a string
- How do I generate random integers within a specific range in Java?
- Best way to convert an ArrayList to a string
- How to split a String by space
- What is a StringIndexOutOfBoundsException? How can I fix it?
- String interpolation in Java 14 or 15
- How do popBackStack() and replace() operations differ?
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- How to remove single character from a String
- @ converted to %40 in HTTPPost request
- Unfortunately MyApp has stopped. How can I solve this?
- How to parse this string in Java?
- Unfortunately MyApp has stopped. How can I solve this?
- How can I properly compare two Integers in Java?
- How to split a string in Java
- Illegal Escape Character “\”
- Can I multiply strings in Java to repeat sequences?
- Calculating the angle between the line defined by two points
- What does regular expression \\s*,\\s* do?
- How to convert a Binary String to a base 10 integer in Java
- Left Hand Side of an Assignment must be a Variable CharAt
- How to capitalize the first letter of a String in Java?
- catDog string problem at Codingbat.com
- Java way to check if a string is palindrome
- Return string Input with parse.string
- What is the difference between String.subString() and String.subSequence()
- Android ListView headers
- How do I apply the for-each loop to every character in a String?
- Java – removing first character of a string
- Java compressing Strings
- Explain the use of a bit vector for determining if all characters are unique
- Explain the use of a bit vector for determining if all characters are unique
- Convert array of strings into a string in Java
- How to check whether a int is not null or empty?
- Attempt to invoke virtual method ‘…’ on a null object reference
- Declaring an unsigned int in Java
- Sort a single String in Java
- How to remove single character from a String
- How to remove single character from a String
- Getting java.net.SocketTimeoutException: Connection timed out in android
- What is Java String interning?
- What is Java String interning?
- What is Java String interning?
- Why is there no String.Empty in Java?
- This view is not constrained
- Java split string to array
- Using ADB to capture the screen
- Using Enum values as String literals
- How to use VisibleForTesting for pure JUnit tests
- What is the easiest/best/most correct way to iterate through the characters of a string in Java?
- Exception in thread “main” java.lang.NumberFormatException: For input string: “S”
- How to parse JSON boolean value?
- ADK vs JDK vs SDK difference?
- How to check if my string is equal to null?
- what is Ljava.lang.String;@
- Android java.lang.IllegalStateException: Could not execute method of the activity
- How can I fix ‘android.os.NetworkOnMainThreadException’?
- Default keystore file does not exist?
- Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio
- Convert String to int array in java
- How to print to the console in Android Studio?
- The activity must be exported or contain an intent-filter
- align text center with android
- How can I convert integer into float in Java?
- Pause the timer and then continue it
- Variable is accessed within inner class. Needs to be declared final
- How to implement infinity in Java?