wood burning stoves 2.0*
The moose likes Android and the fly likes String Length Finding Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "String Length Finding Problem" Watch "String Length Finding Problem" New topic
Author

String Length Finding Problem

prazannag Kumar
Greenhorn

Joined: Feb 25, 2010
Posts: 12
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
prazannag Kumar
Greenhorn

Joined: Feb 25, 2010
Posts: 12
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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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

Joined: Oct 12, 2008
Posts: 1369
    
    1

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?

[List of FAQs] | [Android FAQ] | [Samuh Varta]
prazannag Kumar
Greenhorn

Joined: Feb 25, 2010
Posts: 12
thanks it works great now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Length Finding Problem
 
Similar Threads
Adding strings together
Array of Strings
get the length of the string
HI!!!
Local variable