• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EditText force closing with getText().toString()

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have searched and tried all the solutions....and nothing seems to work. help please!!

here is the offending snippet, pulled out of the rest of my code. any way i try to use


creates a force close. If I comment out that line, it works fine.



update: Any form of getText() or setText() that I call within the void onClick causes a force close
 
Saloon Keeper
Posts: 7597
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start by examining the logcat output to figure out the actual exception that is being thrown. Have you made sure that "ET" is not null?
 
dani alex
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I test if it is null if getText() causes the force close?
 
Tim Moores
Saloon Keeper
Posts: 7597
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't do that, then :-) Output the value of ET before calling any method on it.

But this is just shooting in the dark - you really need to take a look at the logcat output to see what the exception is.
 
Ranch Hand
Posts: 154
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Dani can you post the complete code

-zoheb
 
Tim Moores
Saloon Keeper
Posts: 7597
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

zoheb hassan wrote:Hey Dani can you post the complete code


What for? It's pretty clear what's happening, is it not?
 
zoheb hassan
Ranch Hand
Posts: 154
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:

zoheb hassan wrote:Hey Dani can you post the complete code


What for? It's pretty clear what's happening, is it not?



No Tim its not clear whats happening or going wrong over here, would you care to explain it

Thanks
Zoheb
 
Tim Moores
Saloon Keeper
Posts: 7597
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's happening is that there's an exception, all the details of which can be found in the logcat output. So the next step is for dani alex to examine the logcat output, and -if further help is needed- post it here. For us to see the rest of the code doesn't help with that.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what you are trying to do here. Just remove the line finish(); under the OnClickListener and the code should run.
You are forcing the activity to close by calling finish();.

Button sB;
EditText ET;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.writestory);

ET = (EditText)findViewById(R.id.story);

sB = (Button)findViewById(R.id.sb);

sB.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
Log.v("EditText", ET.getText().toString());
//finish(); Remove this line
}
});
 
zoheb hassan
Ranch Hand
Posts: 154
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you call finish(), you will be exiting the activity not force closing the activity.So i don't think the finish() method is the culprit here. We cannot comment on whats wrong until he posts the complete code or puts himself what was wrong.Let's wait for him to respond

-Zoheb
 
dani alex
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. So I fixed it. Not quite sure why this worked though.

If I put the editString = getText().toString() inside the onFocusChange for the edit text field, instead of the onclick of the button it works fine. Then I just have the button do it's own thing with the editString.

Thanks for the replys!

I am new at Android and just learning how to work with it. The debug and exception systems make sense now. It is actually quite lovely.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic