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?
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- Reverse a string in Java
- Reverse a string in Java
- Java String Split by “|”
- 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?
- How to replace � in a string
- Change date format in a Java string
- What are all the escape characters?
- Converting String to “Character” array 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?
- How do popBackStack() and replace() operations differ?
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- @ converted to %40 in HTTPPost request
- Unfortunately MyApp has stopped. How can I solve this?
- How to split a string in Java
- Can I multiply strings in Java to repeat sequences?
- 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 do I apply the for-each loop to every character in a String?
- Java – removing first character of a string
- Explain the use of a bit vector for determining if all characters are unique
- Attempt to invoke virtual method ‘…’ on a null object reference
- Sort a single String in Java
- Getting java.net.SocketTimeoutException: Connection timed out in android
- What is Java String interning?
- What is Java String interning?
- This view is not constrained
- Exception in thread “main” java.lang.NumberFormatException: For input string: “S”
- How to parse JSON boolean value?
- Android java.lang.IllegalStateException: Could not execute method of the activity
- How can I fix ‘android.os.NetworkOnMainThreadException’?
- Default keystore file does not exist?
- 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?
- Variable is accessed within inner class. Needs to be declared final
- How to implement infinity in Java?
- Extending from two classes
- Android – SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
- How to sort an array of objects in Java?
- How to compress a String in Java?
- java.lang.NumberFormatException: empty String
- How to check if a String is numeric in Java
- Cannot resolve symbol “Intent”
- Eclipse error, “The selection cannot be launched, and there are no recent launches”
- RecyclerView onClick
- Display Animated GIF
- Java end of file
- Unclosed Character Literal error
- method does not override method in its superclass
- How to create JSON Object using String?
- Add String Array to ArrayList
- Why doesn’t RecyclerView have onItemClickListener()?
- StringIndexOutOfBoundsException String index out of range: 0
- How can I check if a single character appears in a string?
- Difference between String replace() and replaceAll()
- “Field can be converted to a local variable” message appearing when setting Android ActionBar colour
- Convert an integer to an array of digits
- Google firebase check if child exists
- How to Get JSON Array Within JSON Object?
- How can I check if a value is of type Integer?
- How can I remove a substring from a given String?
- Java get String CompareTo as a comparator object
- E/AndroidRuntime﹕ FATAL EXCEPTION: main
- Get an OutputStream into a String
- Android Color Picker
- “Integer number too large” error message for 600851475143
- Android Emulator: Unfortunately App has stopped
- How to convert a String into an ArrayList?
- why android studio show error of “Missing constraints in constraintlayout”?
- How do I get the last character of a string?
- void is an invalid type for this variable
- syntax error: insert } to complete ClassBody
- java.lang.ClassNotFoundException: org.postgresql.Driver, Android
- Eclipse: JVM terminated. Exit code=2
- Append a single character to a string or char array in java?
- Getting a “no interface expected here” when I try to subclass ServiceConnection [duplicate]
- Why int[] a = new int[1] instead of just int a?
- How to insert multiple tabs string in java?
- Removing double quotes from a string in Java
- Append a single character to a string or char array in java?
- Quotation marks inside a string
- In Java, how do I parse XML as a String instead of a file?
- set background color: Android
- No content to map due to end-of-input jackson parser