在android中从一种方法切换到另一种方法时,应用程序崩溃

时间:2015-04-17 08:02:33

标签: android android-activity crash

每当onCreate完成时,应用程序在转到另一个方法时崩溃。在调试中它显示icicle=null:为什么?

   public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.face_detect_surface_view);
     result =(TextView)findViewById(R.id.textView1);

     ((Button)findViewById(R.id.take_picture)).setOnClickListener(btnClick);
     -------------
       ----------------
       ------------------
   }
       @override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(TAKE_PICTURE_CODE == requestCode){
            processCameraImage(data);
        }
    }

enter image description here

Log Cat:

04-17 18:00:30.819: D/dalvikvm(15842): GC_FOR_ALLOC freed 1592K (22183), 37% free 3060K/4852K, paused 35ms, total 35ms
04-17 18:00:30.851: D/AndroidRuntime(15842): Shutting down VM
04-17 18:00:30.851: W/dalvikvm(15842): threadid=1: thread exiting with uncaught exception (group=0x40e789a8)
04-17 18:00:30.851: W/dalvikvm(15842): threadid=1: uncaught exception occurred
04-17 18:00:30.851: W/System.err(15842): java.lang.NullPointerException
04-17 18:00:30.851: W/System.err(15842):    at org.opencv.javacv.facerecognition.FdActivity$3$1.run(FdActivity.java:132)
04-17 18:00:30.851: W/System.err(15842):    at android.os.Handler.handleCallback(Handler.java:800)
04-17 18:00:30.852: W/System.err(15842):    at android.os.Handler.dispatchMessage(Handler.java:100)
04-17 18:00:30.852: W/System.err(15842):    at android.os.Looper.loop(Looper.java:194)
04-17 18:00:30.852: W/System.err(15842):    at android.app.ActivityThread.main(ActivityThread.java:5377)
04-17 18:00:30.852: W/System.err(15842):    at java.lang.reflect.Method.invokeNative(Native Method)
04-17 18:00:30.852: W/System.err(15842):    at java.lang.reflect.Method.invoke(Method.java:525)
04-17 18:00:30.852: W/System.err(15842):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-17 18:00:30.852: W/System.err(15842):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
04-17 18:00:30.852: W/System.err(15842):    at dalvik.system.NativeStart.main(Native Method)
04-17 18:00:30.853: W/dalvikvm(15842): threadid=1: calling UncaughtExceptionHandler
04-17 18:00:30.855: E/AndroidRuntime(15842): FATAL EXCEPTION: main
04-17 18:00:30.855: E/AndroidRuntime(15842): java.lang.NullPointerException
04-17 18:00:30.855: E/AndroidRuntime(15842):    at org.opencv.javacv.facerecognition.FdActivity$3$1.run(FdActivity.java:132)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at android.os.Handler.handleCallback(Handler.java:800)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at android.os.Handler.dispatchMessage(Handler.java:100)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at android.os.Looper.loop(Looper.java:194)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at android.app.ActivityThread.main(ActivityThread.java:5377)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at java.lang.reflect.Method.invokeNative(Native Method)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at java.lang.reflect.Method.invoke(Method.java:525)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
04-17 18:00:30.855: E/AndroidRuntime(15842):    at dalvik.system.NativeStart.main(Native Method)
04-17 18:00:30.927: I/Process(15842): Sending signal. PID: 15842 SIG: 9

1 个答案:

答案 0 :(得分:0)

您确定布局R.layout.face_detect_surface_view包含ID为Button的{​​{1}}类型视图。看起来像一个缺失的视图。