1

私はxmlファイルを書きましたが、書くたびに:

    setContentView(R.layout.all_items);

エラーが表示され、アプリが終了します (InflateException)。

xml ファイルに問題はありませんでした

これは xml ファイル (all_items) です。

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:gravity="center" >

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

            <Button
                android:id="@+id/itemsAllItemsBtn"
                android:layout_width="158dp"
                android:layout_height="122dp"
                android:background="@drawable/allthings" />

            <TextView
                android:id="@+id/itemsAllItemsText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="All items" >

                <requestFocus />
            </TextView>

        </LinearLayout>

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

            <Button
                android:id="@+id/items1Btn"
                android:layout_width="wrap_content"
                android:layout_height="122dp"
                android:layout_weight="4"
                android:background="@drawable/1_image_item" />

            <TextView
                android:id="@+id/items1Text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="1" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

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

            <Button
                android:id="@+id/items2Btn"
                android:layout_width="158dp"
                android:layout_height="131dp"
                android:layout_marginTop="20dp"
                android:background="@drawable/2" />

            <TextView
                android:id="@+id/items2Text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="2" >

                <requestFocus />
            </TextView>

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="182dp"
            android:orientation="vertical" >

            <Button
                android:id="@+id/items3Btn"
                android:layout_width="wrap_content"
                android:layout_height="131dp"
                android:layout_marginTop="20dp"
                android:background="@drawable/3" />

            <TextView
                android:id="@+id/items3Text"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" 
                android:text="3"/>

        </LinearLayout>

    </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:gravity="center" >

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

            <Button
                android:id="@+id/items4Btn"
                android:layout_width="158dp"
                android:layout_height="130dp"
                android:background="@drawable/4" />

            <TextView
                android:id="@+id/items4Text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="4" >

                <requestFocus />
            </TextView>

        </LinearLayout>

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

            <Button
                android:id="@+id/itemsAuctionBtn"
                android:layout_width="wrap_content"
                android:layout_height="131dp"
                android:background="@drawable/auction_reduced"
                 />

            <TextView
                android:id="@+id/itemsAuctionText"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" 
                android:text="Auction"/>

        </LinearLayout>

    </LinearLayout>





</LinearLayout>

128行目は次のとおりです。

  <Button
            android:id="@+id/itemsAuctionBtn"
            android:layout_width="wrap_content"
            android:layout_height="131dp"
            android:background="@drawable/auction_reduced"
             />

これはlogcatです:

03-30 12:43:28.550: E/AndroidRuntime(1319): FATAL EXCEPTION: main
03-30 12:43:28.550: E/AndroidRuntime(1319): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sal/com.example.sal.AllItemsActivity}: android.view.InflateException: Binary XML file line #128: Error inflating class <unknown>
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.os.Looper.loop(Looper.java:137)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.ActivityThread.main(ActivityThread.java:5041)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at java.lang.reflect.Method.invokeNative(Native Method)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at java.lang.reflect.Method.invoke(Method.java:511)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at dalvik.system.NativeStart.main(Native Method)
03-30 12:43:28.550: E/AndroidRuntime(1319): Caused by: android.view.InflateException: Binary XML file line #128: Error inflating class <unknown>
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.Activity.setContentView(Activity.java:1881)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at com.example.sal.AllItemsActivity.onCreate(AllItemsActivity.java:23)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.Activity.performCreate(Activity.java:5104)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-30 12:43:28.550: E/AndroidRuntime(1319):     ... 11 more
03-30 12:43:28.550: E/AndroidRuntime(1319): Caused by: java.lang.reflect.InvocationTargetException
03-30 12:43:28.550: E/AndroidRuntime(1319):     at java.lang.reflect.Constructor.constructNative(Native Method)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-30 12:43:28.550: E/AndroidRuntime(1319):     ... 26 more
03-30 12:43:28.550: E/AndroidRuntime(1319): Caused by: java.lang.OutOfMemoryError
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.content.res.Resources.loadDrawable(Resources.java:1965)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.view.View.<init>(View.java:3330)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.widget.TextView.<init>(TextView.java:583)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.widget.Button.<init>(Button.java:107)
03-30 12:43:28.550: E/AndroidRuntime(1319):     at android.widget.Button.<init>(Button.java:103)
03-30 12:43:28.550: E/AndroidRuntime(1319):     ... 29 more
03-30 12:43:33.146: I/Process(1319): Sending signal. PID: 1319 SIG: 9
03-30 12:43:34.251: E/Trace(1405): error opening trace file: No such file or directory (2)

これは私のコードです:

public class AllItemsActivity extends Activity {

    private Button allItemsButton;
    private Button 1Btn,2Btn,auctionBtn,3Btn,4Btn;


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

        setContentView(R.layout.all_items);

        allItemsButton =(Button) findViewById(R.id.itemsAllItemsBtn);
        saleBtn =(Button) findViewById(R.id.items1Btn);
        2Btn =(Button) findViewById(R.id.items2Btn);
        3Btn =(Button) findViewById(R.id.items3Btn);
        4Btn =(Button) findViewById(R.id.items4Btn);
        auctionBtn =(Button) findViewById(R.id.itemsAuctionBtn);
        }
}

23行目は次のとおりです。

    setContentView(R.layout.all_items);
4

1 に答える 1

1

あなたの問題はこれだと思います:

Caused by: java.lang.OutOfMemoryError

おそらく、ドローアブルに保存されている画像のサイズが大きく、正しく膨らませることができません。drawable を削除して、何が起こるかを観察してみてください。

于 2013-03-30T12:58:57.470 に答える