Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Length Finding Problem

 
prazannag Kumar
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I tried the following method but these doesn't works. Can anyone tell me is any other methods available to find the string length. ?
Method:
string.length()
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I seeing things or are you having problems with finding String length?? If you are having problems with that, then the question doesn't belong to Android forum.
I tried the following method but these doesn't works.

ItDoesntWorkIsUseless tell us what happened when you called length() method. The length() method is the most straight forward way of finding String length...
 
prazannag Kumar
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I tried the following code to find the string length, but the message shows "FORCE TO CLOSE". let me know what i did wrong.
code:

EditText s1=(EditText)findViewById(R.id.EditText01);
int j = s1.getText().toString().length();


 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Force to Close thing would be displayed on the android simulator right?? My guess would be that s1.getText is returning null so you are getting a NullPointerException. Are you developing your program on Eclipse?? If yes then you can find any exceptions that are coming in the LogCat view in eclipse. Go to Window -> Show View -> Other -> Open the Android category in the tree -> LogCat, this will show the LogCat view, then run your program, if any exception comes you'll be able to see it here. Alternatively you can go to the tools folder of your android SDK installation and run the command "adb logcat" after the simulator is running...
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prazannag Kumar wrote:Hi,

I tried the following code to find the string length, but the message shows "FORCE TO CLOSE". let me know what i did wrong.
code:

EditText s1=(EditText)findViewById(R.id.EditText01);
int j = s1.getText().toString().length();




"Force Close" is something you'll see every time something goes wrong in your code; you should post log dump, which would be more useful in diagnosis.

Questions:

Are you getting NullPointerException in logs?
Where are you calling findViewById(..)?
Are you certain that when you are calling this function the View has even been drawn?
 
prazannag Kumar
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks it works great now.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic