dmarnel
dmarnel

Reputation: 4456

Android app won't crash with Eclipse

Yep, that's right. Despite introducing some bad code the app continues to run. I'm really new to Android and Eclipse development so I am wondering if there is some setting that is causing the app to not crash? The reason I am trying to cause a crash is so I can test some crash reporting code.

Here is how I created the exception. In one of my button event handlers I added this line:

int i = 1 / 0; // Divide by zero is bad!

Here is the LogCat output after encountering the above line:

04-25 15:50:39.880: W/System.err(2786): java.lang.reflect.InvocationTargetException
04-25 15:50:39.880: W/System.err(2786):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 15:50:39.880: W/System.err(2786):     at java.lang.reflect.Method.invoke(Method.java:507)
04-25 15:50:39.880: W/System.err(2786):     at com.mystuff.android.ReflectiveAction.run(Unknown Source)
04-25 15:50:39.880: W/System.err(2786):     at com.mystuff.android.Command.onClick(Unknown Source)
04-25 15:50:39.890: W/System.err(2786):     at android.view.View.performClick(View.java:2532)
04-25 15:50:39.890: W/System.err(2786):     at android.view.View$PerformClick.run(View.java:9293)
04-25 15:50:39.890: W/System.err(2786):     at android.os.Handler.handleCallback(Handler.java:587)
04-25 15:50:39.890: W/System.err(2786):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-25 15:50:39.890: W/System.err(2786):     at android.os.Looper.loop(Looper.java:143)
04-25 15:50:39.890: W/System.err(2786):     at android.app.ActivityThread.main(ActivityThread.java:4263)
04-25 15:50:39.890: W/System.err(2786):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 15:50:39.890: W/System.err(2786):     at java.lang.reflect.Method.invoke(Method.java:507)
04-25 15:50:39.890: W/System.err(2786):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-25 15:50:39.890: W/System.err(2786):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-25 15:50:39.890: W/System.err(2786):     at dalvik.system.NativeStart.main(Native Method)
04-25 15:50:39.890: W/System.err(2786): Caused by: java.lang.ArithmeticException: divide by zero
04-25 15:50:39.890: W/System.err(2786):     at com.mystuff.theapp.HomePage.evSurprise(HomePage.java:209)
04-25 15:50:39.890: W/System.err(2786):     ... 15 more

Thanks for any and all help!

EDIT - Here is the entire event handler with the bad line of code:

public void evSurprise () {
    int i = 1 / 0;

    cpanel.animateGoButtonWhole();
    cpanel.showThrobber();

    Helper.startActivity( this, Actions.VENUE, Actions.SEARCH, false );
}

BTW, this code was written by an outside contractor for our company. I am an objective-c programmer who is trying to understand java and Android development. There may very well be an exception handler that I am unaware of with my limited knowledge of this code. If this is the case, what should I be looking for?

Upvotes: 0

Views: 164

Answers (1)

tjPark
tjPark

Reputation: 308

You might catching the error.

If you do 1/0 without catching an error, log would look like

E/AndroidRuntime(27801)

E - error. but urs is

W/System.err(2786)

W - warning. You are catching the error and printing it.

so remove the try/catch somewhere in your code, which would looks like this:

try{
    //your code
}catch(Exception e){
    e.printStackTrace(e)
}

only use //your code part

Upvotes: 1

Related Questions