0

My app, heavily based on the OpenCV sample (Sample 2 with camera) links to OpenCV 2.4.0. After trouble-free work for a month or so I suddenly suffered from the dreaded "Dalvik error 1" problem. When the usual fixes didn't work, I decided to build a new project from scratch with the same source files hoping that would solve the problem...

Well it builds, but crashes on launch. Here's the console content:

06-07 14:01:01.383: D/dalvikvm(20915): Trying to load lib /data/data/barry.opencvdemo/lib/libopencv_java.so 0x4051c988
06-07 14:01:02.204: D/dalvikvm(20915): Added shared lib /data/data/barry.opencvdemo/lib/libopencv_java.so 0x4051c988
06-07 14:01:02.354: D/AndroidRuntime(20915): Shutting down VM
06-07 14:01:02.354: W/dalvikvm(20915): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
06-07 14:01:02.374: E/AndroidRuntime(20915): FATAL EXCEPTION: main
06-07 14:01:02.374: E/AndroidRuntime(20915): java.lang.RuntimeException: Unable to start activity ComponentInfo{barry.opencvdemo/barry.opencvdemo.Sample2NativeCamera}: java.lang.NullPointerException
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.os.Looper.loop(Looper.java:150)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.app.ActivityThread.main(ActivityThread.java:4385)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at java.lang.reflect.Method.invokeNative(Native Method)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at java.lang.reflect.Method.invoke(Method.java:507)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at dalvik.system.NativeStart.main(Native Method)
06-07 14:01:02.374: E/AndroidRuntime(20915): Caused by: java.lang.NullPointerException
06-07 14:01:02.374: E/AndroidRuntime(20915):    at barry.opencvdemo.Sample2NativeCamera.onCreate(Sample2NativeCamera.java:47)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
06-07 14:01:02.374: E/AndroidRuntime(20915):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
06-07 14:01:02.374: E/AndroidRuntime(20915):    ... 11 more

Everything seems to be in the right place and with the right names, but something is not working. Is the above enough for someone to point out something obvious I'm missing or should I post some source code? The code itself was working... it's something about the settings for the build or the link I fear.

When the gods do something about the whole Dalvik Error 1 business I for one will be very happy.

Many thanks for any suggestions.

Community
  • 1
  • 1
Barry
  • 1,258
  • 3
  • 13
  • 27
  • please post the code it's crashing on! – Thkru Jun 07 '12 at 13:49
  • please provide Sample2NativeCamera.java code here – Dheeresh Singh Jun 07 '12 at 13:49
  • 2
    put a try catch block around the code in onCreate and put a breakpoint in the catch. You will catch the exception. From the exception log it looks like you are using an object/variable that is not yet initialized. – Asdfg Jun 07 '12 at 13:55
  • Mea Culpa. I was so focussed on whether the Dalvik error might occur again I was omitting to look at my own code. A bit of standard debugging and stepping through my own code was the answer. @Asdfg you were right. Put your gentle reminder as an answer and I'll accept it and use it as a reminder to self to look for the easy stuff before worrying about the big stuff. Many thanks. Anyway - when is the Dalvik Error 1 thing going to be comprehensively solved by the gods ;) – Barry Jun 07 '12 at 14:59

2 Answers2

0

put a try catch block around the code in onCreate and put a breakpoint in the catch. You will catch the exception. From the exception log it looks like you are using an object/variable that is not yet initialized.

Asdfg
  • 11,362
  • 24
  • 98
  • 175
0

This happens when your app encounters an unexpected error and doesn't know how to respond to it. As it was said before you can surround parts of your code with try/catch blocks.

Moreover: 06-07 14:01:02.374: E/AndroidRuntime(20915): java.lang.RuntimeException: Unable to start activity ComponentInfo{barry.opencvdemo/barry.opencvdemo.Sample2NativeCamera}: java.lang.NullPointerException

This is the clue to solve the problem you have. NullPointerException means a class was expecting an object somewhere but got a null instead.

You can try to surround the part of your code related to it with try/catch or just put some System.out.println() around to see where the run stops working.

Hope this helps!

Loic O.
  • 486
  • 2
  • 7
  • 22