0

カメラキーのクリックでもカメラビューから画像をキャプチャしようとしています。それは正常に動作していましたが、UI を変更し、ボタンを使用してキャプチャをクリックしたいので、main.xml プログラムに配置されたボタンはエラーを表示しませんが、プログラムを実行すると、行 button.setOnClickListener(new View. OnClickListener(). ボタン ID 名のスペルを間違えていないか確認しましたが、同じです。

    //make the screen full screen
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //remove the title bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    mResultView=new ResultView(this);
    mPreview = new Preview(this);

    //set Content View as the preview
    setContentView(mPreview);

    //add result view  to the content View
    addContentView(mResultView,new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

    //set the orientation as landscape
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);    
    //Button capture_Button = (Button) findViewById(id.button_click);
    button = (Button) findViewById(R.id.button_click);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mCameraReadyFlag = false;
            mPreview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
        }
    });


}`

これは私の主な活動コードです

enter code here

02-11 19:21:58.367: I/Process(5729): Sending signal. PID: 5729 SIG: 9
02-11 19:22:04.987: D/AndroidRuntime(6006): Shutting down VM
02-11 19:22:04.987: W/dalvikvm(6006): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-11 19:22:04.987: E/AndroidRuntime(6006): FATAL EXCEPTION: main
02-11 19:22:04.987: E/AndroidRuntime(6006): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ee368.siftexample/com.ee368.siftexample.SIFTExampleActivity}: java.lang.NullPointerException
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.os.Looper.loop(Looper.java:130)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.app.ActivityThread.main(ActivityThread.java:3683)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at java.lang.reflect.Method.invokeNative(Native Method)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at java.lang.reflect.Method.invoke(Method.java:507)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at dalvik.system.NativeStart.main(Native Method)
02-11 19:22:04.987: E/AndroidRuntime(6006): Caused by: java.lang.NullPointerException
02-11 19:22:04.987: E/AndroidRuntime(6006):     at com.ee368.siftexample.SIFTExampleActivity.onCreate(SIFTExampleActivity.java:89)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-11 19:22:04.987: E/AndroidRuntime(6006):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-11 19:22:04.987: E/AndroidRuntime(6006):     ... 11 more
02-11 19:22:09.097: I/Process(6006): Sending signal. PID: 6006 SIG: 9'

これは私のログウィンドウです

これはxmlレイアウトです

 ?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <Button
        android:id="@+id/button_click"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Capture" />

</LinearLayout>

誰かがこのエラーを解決するのを手伝ってくれますか? また、onkeydown() の代わりにボタンを使用するにはどうすればよいですか? 事前に感謝

4

2 に答える 2