2

アプリケーションに 3 つのタブがあるアプリケーションに zxing qr コード スキャナーを統合したいと考えています。

現在、タブバーのボタンの 1 つが押されたときに、zxing qr コードの scann アクティビティを呼び出していますが、呼び出すたびに以下のようなエラーが表示されます。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.beepz/com.google.zxing.client.android.CaptureActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

むしろ、私のコードにはタブ ホスト コントロールの両方があり、以下に示すようにアクティビティ呼び出しでタブ ホストをインスタンス化しています。

XML ファイル (Capture.xml) :

<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <SurfaceView
        android:id="@+id/preview_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true" >

        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </TabWidget>

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <LinearLayout
                        android:id="@+id/tab1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/tab2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/tab3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
                    </LinearLayout>
                </FrameLayout>
            </LinearLayout>
        </TabHost>

      <com.google.zxing.client.android.ViewfinderView
            android:id="@+id/viewfinder_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/transparent" />
    
    </SurfaceView>
</FrameLayout>

</merge>

Java ファイル: (CaptureActivity.java)

public final class CaptureActivity extends TabActivity implements
    SurfaceHolder.Callback {

private TabHost tabHost;

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    window.setFormat(PixelFormat.TRANSLUCENT);
    
    setContentView(R.layout.capture);

    tabHost = getTabHost();
    Intent intent = new Intent().setClass(this, first.class);      
    TabSpec spec = tabHost.newTabSpec("First Tab").setIndicator("First Tab",getResources().getDrawable(R.drawable.iconinfo)).setContent(intent); 
    tabHost.addTab(spec);
    .
    .
    .

}

マニフェスト ファイルの何かを変更する必要がありますか、それとも他に何かする必要がありますか?

4

1 に答える 1

1

ついに私は自分の問題を解決しました。問題は、メイン プロジェクトに CaptureActivity.java ファイルがあったことです。そして、メイン プロジェクトの CaptureActivity.java ファイルに TabHost を追加することで問題が解決しました。

于 2013-06-10T05:15:52.947 に答える