想要解决xml InflateException

时间:2014-01-25 14:43:53

标签: android xml

我有设置壁纸的应用程序我在每个活动中都有活动我在xml布局中设置了10个图像。但是当我按意图改变我的活动时,我会收到这样的错误:

java.lang.RuntimeException:无法启动活动componentInfo android.view.InflateException:二进制XML文件行#70:错误导致类未知

在我的布局文件中,有一个简单的标签。请帮帮我,因为我是android的初学者。

这是我的xml代码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bk1"
android:orientation="vertical"
android:weightSum="1"
tools:context=".X2" >

<ImageView
    android:id="@+id/z2image"
    android:layout_width="fill_parent"
    android:layout_height="350dp"
    android:layout_gravity="center"
    android:layout_weight="1"
    tools:ignore="ContentDescription" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dp"
    android:orientation="horizontal"
    android:weightSum="1" >

<Button
android:id="@+id/save2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:layout_weight="0.3"
        android:background="@drawable/red_selector"
        android:paddingBottom="15dp"
        android:paddingTop="15dp"
        android:text="Save" />

    <Button
        android:id="@+id/set2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:layout_weight="0.4"
        android:background="@drawable/green_selector"
        android:paddingBottom="15dp"
        android:paddingTop="15dp"
        android:text="Set" />

    <Button
        android:id="@+id/rate2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:layout_weight="0.3"
        android:background="@drawable/blue_selector"
        android:paddingBottom="15dp"
        android:paddingTop="15dp"
        android:text="Rate" />
</LinearLayout>

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1" >

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:orientation="horizontal" >

<ImageView
            android:id="@+id/x11"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x11"
            tools:ignore="ContentDescription" />

<ImageView
            android:id="@+id/x12"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x12"
            tools:ignore="ContentDescription" />

<ImageView
            android:id="@+id/x13"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x13" />

<ImageView
            android:id="@+id/x14"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x14" />

<ImageView
            android:id="@+id/x15"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x15" />

<ImageView
            android:id="@+id/x16"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x16" />
<ImageView
            android:id="@+id/x17"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x17" />
<ImageView
            android:id="@+id/x18"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x18" />
<ImageView
            android:id="@+id/x19"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x19" />
<ImageView
            android:id="@+id/x20"
            android:layout_width="120dp"
            android:layout_height="98dp"
            android:src="@drawable/x20" />
</LinearLayout>
</HorizontalScrollView>

</LinearLayout> 

这是我在其中设置此布局的java文件。

public class X2 extends Activity implements OnClickListener {

ImageView display, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10;
int to;
Button set, save,rate;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.x2);

to = R.drawable.x11;

display = (ImageView) findViewById(R.id.z2image);
    c1 = (ImageView) findViewById(R.id.x11);
    c2 = (ImageView) findViewById(R.id.x12);
    c3 = (ImageView) findViewById(R.id.x13);
    c4 = (ImageView) findViewById(R.id.x14);
    c5 = (ImageView) findViewById(R.id.x15);
    c6 = (ImageView) findViewById(R.id.x16);
    c7 = (ImageView) findViewById(R.id.x17);
    c8 = (ImageView) findViewById(R.id.x18);
    c9 = (ImageView) findViewById(R.id.x19);
    c10 = (ImageView) findViewById(R.id.x20);

    rate = (Button) findViewById(R.id.rate2);
    set = (Button) findViewById(R.id.set2);
    save = (Button) findViewById(R.id.save2);

    c1.setOnClickListener(this);
    c2.setOnClickListener(this);
    c3.setOnClickListener(this);
    c4.setOnClickListener(this);
    c5.setOnClickListener(this);
    c6.setOnClickListener(this);
    c7.setOnClickListener(this);
    c8.setOnClickListener(this);
    c9.setOnClickListener(this);
    c10.setOnClickListener(this);

    set.setOnClickListener(this);
    rate.setOnClickListener(this);
    save.setOnClickListener(this);

}

public void onClick(View v) {

    String fName;
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.x11:
        display.setImageResource(R.drawable.x11);
        to = R.drawable.x11;
        break;
    case R.id.x12:
        display.setImageResource(R.drawable.x12);
        to = R.drawable.x12;
        break;
    case R.id.x13:
        display.setImageResource(R.drawable.x13);
        to = R.drawable.x13;
        break;
    case R.id.x14:
        display.setImageResource(R.drawable.x14);
        to = R.drawable.x14;
        break;
    case R.id.x15:
        display.setImageResource(R.drawable.x15);
        to = R.drawable.x15;
        break;
    case R.id.x16:
        display.setImageResource(R.drawable.x16);
        to = R.drawable.x16;
        break;
    case R.id.x17:
        display.setImageResource(R.drawable.x17);
        to = R.drawable.x17;
        break;
    case R.id.x18:
        display.setImageResource(R.drawable.x18);
        to = R.drawable.x18;
        break;
    case R.id.x19:
        display.setImageResource(R.drawable.x19);
        to = R.drawable.x19;
        break;
    case R.id.x20:
        display.setImageResource(R.drawable.x20);
        to = R.drawable.x20;
        break;


    case R.id.set2:

    case R.id.save2:

    case R.id.rate2:


}
}

}

0 个答案:

没有答案