• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

String Length Finding Problem

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()
 
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks it works great now.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic