0

dispatchTakePictureIntent写真を撮る関数を呼び出しています。しかし、写真を撮って保存した後、アプリケーションが実際のアクティビティに正しく戻らず、アプリケーションがクラッシュします。

私のボタンが押されたとき、私は電話をかけます

dispatchTakePictureIntent(1);

それから:

public void dispatchTakePictureIntent(int actionCode) {

        try {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File f = createImageFile();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
            startActivityForResult(takePictureIntent, actionCode);


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    /*  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(takePictureIntent, actionCode);*/
    }

    public File createImageFile() throws IOException {
        // Create an image file name
        final String nomeForm = "teste";    
        String imageFileName = nomeForm +".jpeg";


       File path = getExternalFilesDir(Environment.DIRECTORY_DCIM);
       File image = new File(path,imageFileName );

       // String getAbsolutePath = image.getAbsolutePath();
        Toast.makeText(this, "Image saved to:\n" +  image, Toast.LENGTH_LONG).show();
        return image;
    }

私のlogcatエラーレポート:

java.lang.RuntimeException: Unable to stop activity {com.example.sform/com.example.sform.mainRisco}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sform/com.example.sform.risco1}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.CompoundButton$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/0x1. Make sure other views do not use the same id.

ここにすべての私のレイアウト:

タブ ホスト レイアウト:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/layout_riscos">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</TabHost>

タブ1:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/risco1"
>

<RelativeLayout
    android:id="@+id/geral_risco1"
    android:layout_width="match_parent"
    android:layout_height="739dp"
    android:orientation="vertical"
    android:screenOrientation="nosensor" >

    <Button
        android:id="@+id/pelicula_risco1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="36dp"
        android:text="Take a Picture ;)"
        android:textSize="30dp" />

    <ImageView
        android:id="@+id/imageView_risco1"
        android:layout_width="9000dp"
        android:layout_height="500dp"
        android:layout_alignLeft="@+id/pelicula"
        android:layout_marginTop="100dp"
        android:layout_alignParentTop="true" >

    </ImageView>


    <RelativeLayout
         android:id="@+id/riscoQ1_risco1"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" 
         android:layout_alignParentTop="true" >
    </RelativeLayout>

</RelativeLayout>
</ScrollView>

タブ2:

  <TextView android:text="risco 2"
            android:padding="15dip"
            android:textSize="18dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
             android:id="@+id/text_risco2"/>
</RelativeLayout>

Tab3:

  <TextView android:text="risco 3"
            android:padding="15dip"
            android:textSize="18dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/text_risco3"/>
</RelativeLayout>

Tab4:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:id="@+id/geral_risco4">

  <TextView android:text="risco 4"
            android:padding="15dip"
            android:textSize="18dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/text_risco4"/>
</RelativeLayout>

タブ5:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/geral_risco5" >

  <TextView android:text="risco 5"
            android:padding="15dip"
            android:textSize="18dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/text_risco5"/>
</RelativeLayout>

主な活動:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/info"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:screenOrientation="nosensor" 
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
  >

</RelativeLayout>

別の画面:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
    android:orientation="vertical"
    android:screenOrientation="nosensor" 
android:id="@+id/scroll_tela_form"
>

<RelativeLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"

     android:id="@+id/info2"
>
    <EditText
        android:id="@+id/dataAnalise"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="false"
        android:layout_alignWithParentIfMissing="false"
        android:layout_below="@+id/textView3"
        android:layout_centerInParent="false"
        android:layout_centerVertical="false"
        android:layout_toLeftOf="@+id/getDate"
        android:ems="10" />

    <TextView
        android:id="@+id/horaAnaliseFixo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/horaAnalise"
        android:layout_below="@+id/dataAnalise"
        android:layout_marginTop="8dp"
        android:text="Hora de Inicio da Análise"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/nomeForm"
        android:layout_marginTop="40dp"
        android:text="Data da Análise"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/nomeForm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="35dp"
        android:layout_toLeftOf="@+id/getDate"
        android:layout_toRightOf="@+id/textView3"
        android:text="NomeForm"
        android:textSize="34dp"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/horaAnalise"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/horaAnaliseFixo"
        android:layout_toLeftOf="@+id/getDate"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/getDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/horaAnaliseFixo"
        android:layout_alignParentRight="true"
        android:layout_marginRight="41dp"
        android:text="Get Date" />

    <Button
        android:id="@+id/getTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/getDate"
        android:layout_alignParentBottom="true"
        android:text="Get Time" />

</RelativeLayout>
</ScrollView>
4

3 に答える 3

0

この問題のもう 1 つの理由はlayoutlayout-landlayout-w600dpなどに格納されている同じレイアウトの 2 つ (またはそれ以上) のレイアウト ファイルである可能性があります。これらのレイアウトに、同じ ID を共有する異なるタイプのビューがある場合、この例外 2 が発生する可能性があります。例外を再現するには、 function を呼び出しdispatchTakePictureIntent()、デバイスを回転させてから、写真を撮って元に戻す必要があります。それは役に立ちますか?

于 2013-08-19T14:53:01.980 に答える
0

id2 つの異なるビューに同じものを使用しました。

レイアウトを確認し、ビューごとに異なるものをXML使用してください。ids

于 2013-08-19T13:25:17.923 に答える
0

異なるビューに同じ ID を使用しており、ID は 0x1 であることが示されています。それは疑わしいように見えます

a) ビュー ID が期待されている場所、他の何かが指定されている、または

b) R.java が正しく生成されていません。どこかに 1 の ID があるかどうかを確認してください。

の値を確認しましたか

@android:id/tabs
@android:id/tabcontent

?

于 2013-08-19T14:35:13.243 に答える