Can't Catch Exception - Emulator Force-closes app instead

Put your problem here if it does not fit any of the other categories.

Can't Catch Exception - Emulator Force-closes app instead

Postby Ultimate Chicken » Thu Jun 04, 2009 11:35 am

Hi, my first post here.

I'm currently trying to code a simple text file reader in Android. Well, I got the thing to compile in Eclipse with no red errors - but the emulator won't let it run; it will simply Force Close the app without another word. Error is "The Application <Appname> has stopped unexpectedly".

The following is a snippet from my application, which counts the number of lines in a text file. I have no idea why NOTHING is caught at this point since i've utilitzed General Exception Handlers, which is supposed to return *something* no matter what the exception type is - the console seems to point me to a NullPointerException.

public void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initControls();
readFile();
}
catch (Exception e) {
txtField.setText(e.toString()); //The exception should be output to the program's text box or field
}
}

private void readFile() {
int lineCount = 0;
try {

InputStreamReader isr = new InputStreamReader(getResources().openRawResource (R.raw.textfile));
BufferedReader br = new BufferedReader(isr);
while (br.readLine()!= null) {
lineCount ++;
}
br.close();
isr.close();
linesInFile = lineCount;

}catch (Exception e) {
txtField.setText(e.toString()); //The exception should be output to the program's text box or field
}

My emulator settings: Android 1.5r2, QVGAP, 128MB SD card

Thanks in advance.
Ultimate Chicken
Freshman
Freshman
 
Posts: 2
Joined: Thu Jun 04, 2009 11:21 am

Top

Postby Ultimate Chicken » Thu Jun 04, 2009 4:57 pm

ok, i've actually discovered what was causing those NullPointerExceptions - I accidentially tried to cast to EditText instead of TextView. And because I was outputting the Exception to TextView the program threw another unhandled and crashed. Doh!

Thanks anyway.
Ultimate Chicken
Freshman
Freshman
 
Posts: 2
Joined: Thu Jun 04, 2009 11:21 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 23 guests