I have this code for an event handler:
rbM.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
try {
Double.parseDouble(etAmm.getText().toString());
if (etPerc.getText().toString() != null
&& etPerc.getText().toString() != "") {
etRis.setText(new Double(
Double.parseDouble(etAmm.getText()
.toString()) - percentuale())
.toString());
etPercTot.setText(new Double(percentuale())
.toString() + "%");
}
et30.setText(new Double(Double.parseDouble(etAmm
.getText().toString()) - percentuale(30))
.toString());
etPerc30.setText(new Double(percentuale(30))
.toString() + "%");
et50.setText(new Double(Double.parseDouble(etAmm
.getText().toString()) - percentuale(50))
.toString());
etPerc50.setText(new Double(percentuale(50))
.toString() + "%");
et70.setText(new Double(Double.parseDouble(etAmm
.getText().toString()) - percentuale(70))
.toString());
etPerc70.setText(new Double(percentuale(70))
.toString() + "%");
} catch (Exception ex) {
}
}
}
});
I have it in the onCreate method, but when I start the application it crushes. Why??? Eclipse doesn’t give me any error and if I put a try catch block that tries everything in that method I get null as exception. My layout is correct because if I launch the application without any java code edited by me, it loads on the screen perfectly. Help me please!!!!!
p.s.
I have other event handlers but this is the shortest and I don’t think it might change from handler to handler, it’s always just a declaration.
Here’s the logcat as someone asked:
03-20 15:03:13.775: D/AndroidRuntime(262): Shutting down VM
03-20 15:03:13.775: W/dalvikvm(262): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
03-20 15:03:13.895: E/AndroidRuntime(262): FATAL EXCEPTION: main
03-20 15:03:13.895: E/AndroidRuntime(262): java.lang.RuntimeException: Unable to start activity ComponentInfo{ciprianis.genius.percentuali/ciprianis.genius.percentuali.PercentualiActivity}: java.lang.NullPointerException
03-20 15:03:13.895: E/AndroidRuntime(262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-20 15:03:13.895: E/AndroidRuntime(262): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-20 15:03:13.895: E/AndroidRuntime(262): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-20 15:03:13.895: E/AndroidRuntime(262): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-20 15:03:13.895: E/AndroidRuntime(262): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 15:03:13.895: E/AndroidRuntime(262): at android.os.Looper.loop(Looper.java:123)
03-20 15:03:13.895: E/AndroidRuntime(262): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-20 15:03:13.895: E/AndroidRuntime(262): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 15:03:13.895: E/AndroidRuntime(262): at java.lang.reflect.Method.invoke(Method.java:521)
03-20 15:03:13.895: E/AndroidRuntime(262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-20 15:03:13.895: E/AndroidRuntime(262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-20 15:03:13.895: E/AndroidRuntime(262): at dalvik.system.NativeStart.main(Native Method)
03-20 15:03:13.895: E/AndroidRuntime(262): Caused by: java.lang.NullPointerException
03-20 15:03:13.895: E/AndroidRuntime(262): at ciprianis.genius.percentuali.PercentualiActivity.onCreate(PercentualiActivity.java:62)
03-20 15:03:13.895: E/AndroidRuntime(262): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-20 15:03:13.895: E/AndroidRuntime(262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-20 15:03:13.895: E/AndroidRuntime(262): ... 11 more
From what you say about line 62 it sounds like
etAmmis null. Either you didn’t initialize it orFindViewById()couldn’t find it in your layout.