3

次の実行時エラーが発生しました。エラーを修正するのを手伝ってもらえますか?こちらが丸太猫です。

11-06 14:28:06.262: E/AndroidRuntime(398): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx.xxx/com.xxxx.xxx..Page1SubActivity}: android.view.InflateException: Binary XML file line #76: Error inflating class <unknown>
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.os.Looper.loop(Looper.java:123)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.app.ActivityThread.main(ActivityThread.java:3683)
11-06 14:28:06.262: E/AndroidRuntime(398):  at java.lang.reflect.Method.invokeNative(Native Method)
11-06 14:28:06.262: E/AndroidRuntime(398):  at java.lang.reflect.Method.invoke(Method.java:507)
11-06 14:28:06.262: E/AndroidRuntime(398):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-06 14:28:06.262: E/AndroidRuntime(398):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-06 14:28:06.262: E/AndroidRuntime(398):  at dalvik.system.NativeStart.main(Native Method)
11-06 14:28:06.262: E/AndroidRuntime(398): Caused by: android.view.InflateException: Binary XML file line #76: Error inflating class <unknown>
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
11-06 14:28:06.262: E/AndroidRuntime(398):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-06 14:28:06.262: E/AndroidRuntime(398):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.app.Activity.setContentView(Activity.java:1657)
11-06 14:28:06.262: E/AndroidRuntime(398):  at com.xxxx.xxx.Page1SubActivity.onCreate(Page1SubActivity.java:30)
11-06 14:28:06.262: E/AndroidRuntime(398):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

これはJavaファイルです

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

public class Page1SubActivity extends Activity {

    /** Called when the activity is first created. */

    private EditText edit1;
    private EditText edit2;
    private TextView textview;
    private TextView titleview ;
    private TextView tview1 ;
    private TextView tview2;
    private TextView tview3 ;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // this activity is used for button 1 and button 4 in the main menu
        /*
         * String titles; String texts1; String texts2; String texts3;
         */

        setContentView(R.layout.page1sub);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        Intent intent = getIntent();
        int id = intent.getIntExtra("id", 0);

         titleview = (TextView) findViewById(R.id.textView1);
         tview1 = (TextView) findViewById(R.id.textView2);
         tview2 = (TextView) findViewById(R.id.textView3);
         tview3 = (TextView) findViewById(R.id.textView4);

        if (id == 1)// gold page
        {

            addTranslate(R.string.page1subgoldtitle, titleview);
            addTranslate(R.string.page1subgoldtext1, tview1);
            addTranslate(R.string.page1subgoldtext2, tview2);
            addTranslate(R.string.page1subgoldtext3, tview3);

            ImageButton rightbuton = (ImageButton) findViewById(R.id.rightbutton);
            ImageButton imb = (ImageButton) findViewById(R.id.back_arrow);
            imb.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    // if the user come through 1 st button he will be navigate
                    // page1activity with id =1
                    Intent intent = new Intent(Page1SubActivity.this,
                            Page1Activity.class);
                    intent.putExtra("id", 1);
                    startActivity(intent);

                }
            });

            rightbuton.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    edit1 = (EditText) findViewById(R.id.editText1);
                    edit2 = (EditText) findViewById(R.id.editText2);
                    textview = (TextView) findViewById(R.id.textView5);

                    Double number2 = Double.parseDouble(edit1.getText()
                            .toString());
                    Double number3 = Double.parseDouble(edit2.getText()
                            .toString());
                    number3 = number2 * number3;

                    int number2int = (int) (number2 * number3);
                    int number3int = (int) (number3 / 40);

                    number2 = number2 * number3;
                    number3 = number3 / 40;

                    if (number2int - number2 != 0) {
                        String number2val = Double.toString(number2);
                        textview.setText(number2val);

                    } else {
                        String number2val = Integer.toString(number2int);
                        textview.setText(number2val);
                        // label.text = [NSString stringWithFormat:@"%d",
                        // number2int];

                    }

                    if (number3int - number3 != 0) {
                        String number3val = Double.toString(number3);
                        textview.setText(number3val);

                    } else {

                        String number3val = Integer.toString(number3int);
                        textview.setText(number3val);

                    }

                }
            });

        } else if (id == 4)// silver
        {

            addTranslate(R.string.page1subsilvertitle, titleview);
            addTranslate(R.string.page1subsilvertext1, tview1);
            addTranslate(R.string.page1subsilvertext2, tview2);
            addTranslate(R.string.page1subsilvertext3, tview3);

            ImageButton imb = (ImageButton) findViewById(R.id.back_arrow);

            imb.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    // if the user come through 4th button he will be navigate
                    // page1activity with id =4
                    Intent intent = new Intent(Page1SubActivity.this,
                            Page1Activity.class);
                    intent.putExtra("id", 4);
                    startActivity(intent);

                }
            });

        }

    }

    private void addTranslate(int rid, TextView txt1) {
        String textv = getResources().getString(rid);
        txt1.setText(Farsi.Convert(textv));
    }

    public void onClickBtn(View v) {

        int butid = v.getId();
        switch (butid) {
        case R.id.leftbutton:
            edit1 = (EditText) findViewById(R.id.editText1);
            edit2 = (EditText) findViewById(R.id.editText2);

            edit1.setText("");
            edit2.setText("");
            textview.setText("");
            break;

        }

    }
}

これはxmlファイルです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/page1background"
    android:paddingRight="@dimen/padding_large" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="@dimen/padding_Xlarge"
        android:text="@string/text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/textbody" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/textbody" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="262dp"
            android:layout_height="45dp"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/textbg"
            android:inputType="numberDecimal"
            android:paddingLeft="@dimen/padding_small" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/textbody" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="262dp"
            android:layout_height="45dp"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/textbg"
            android:inputType="numberDecimal"
            android:paddingLeft="@dimen/padding_small" >
        </EditText>

        <TextView
            android:id="@+id/textView4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/textbody" />


        <TextView
            android:id="@+id/textView5"
            android:layout_width="262dp"
            android:layout_height="45dp"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/textbg"
            android:paddingLeft="@dimen/padding_small"
            android:paddingTop="@dimen/padding_small"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="?android:attr/editTextColor" />




        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="horizontal" >

            <ImageButton
                android:id="@+id/leftbutton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="25dp"
                android:background="@drawable/leftbutton"
                android:contentDescription="@string/Description"
                android:onClick="onClickBtn" />

            <ImageButton
                android:id="@+id/rightbutton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/rightbutton"
                android:contentDescription="@string/Description"
                android:onClick="onClickBtn" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:weightSum="10" >

        <View
            android:id="@+id/view10"
            android:layout_width="0dip"
            android:layout_height="10dp"
            android:layout_marginBottom="35dp"
            android:layout_weight="4.5" />

        <ImageButton
            android:id="@+id/back_arrow"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="30dp"
            android:layout_weight="1"
            android:background="@drawable/backbut"
            android:contentDescription="@string/Description"
            android:onClick="onClickBtn"
            android:src="@drawable/backarrowpress" />

        <View
            android:id="@+id/view20"
            android:layout_width="0dip"
            android:layout_height="10dp"
            android:layout_marginBottom="35dp"
            android:layout_weight="4.5" />
    </LinearLayout>

</RelativeLayout>

質問にxmlファイルとjavaファイルを追加しました。これはうまくいきました。コードを更新した後、エラーが発生しました。これを修正するのを手伝ってください。前もって感謝します..

4

2 に答える 2

1

android:textColor="?android:attr/editTextColor"txtview5の行を削除すると、 そのまま動作するようになりました。ただし、その問題はこの行を削除することで解決されます。しかし、私はそれについてクールな気持ちはありません。

于 2012-11-06T10:00:39.540 に答える