java - android.view.InflateException : Binary XML file line #52: Error inflating class <unknown>

标签 java android eclipse android-intent android-activity

当我选择 ImageButton 在 logcat 中获取下一个 Activty 时出现错误:

E/AndroidRuntime(820): FATAL EXCEPTION: main
E/AndroidRuntime(820): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pengendalipagar/com.ta.pengendalipagar.MnUtama}: android.view.InflateException: Binary XML file line #52: Error inflating class <unknown>

E/AndroidRuntime(820):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

E/AndroidRuntime(820):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

E/AndroidRuntime(820):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(820):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(820):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(820):  at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(820):  at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(820):  at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(820):  at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(820):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(820):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(820):  at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(820): Caused by: android.view.InflateException: Binary XML file line #52: Error inflating class <unknown>
E/AndroidRuntime(820):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
E/AndroidRuntime(820):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime(820):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
E/AndroidRuntime(820):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)

这是我的代码activity1 Activity_login.xml:

<?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:background="@drawable/cover" >

    <TextView
        android:id="@+id/txtPasscode"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/editText1"
        android:layout_alignLeft="@+id/editText1"
        android:layout_marginBottom="42dp"
        android:text="@string/passcode"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/imbLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/txtPasscode"
        android:layout_marginLeft="26dp"
        android:layout_marginTop="22dp"
        android:src="@drawable/login"/>

    <ImageButton
        android:id="@+id/imbExit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imbLogin"
        android:layout_marginLeft="18dp"
        android:layout_toRightOf="@+id/imbLogin"
        android:src="@drawable/exit"/>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="28dp"
        android:src="@drawable/logo" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imbLogin"
        android:layout_alignRight="@+id/imbExit"
        android:layout_below="@+id/imageView1"
        android:layout_marginTop="69dp"
        android:ems="10"
        android:inputType="numberPassword" >

        <requestFocus />
    </EditText>

</RelativeLayout>

这是我的 Activity1 LoginActivity.java 代码:

package com.ta.pengendalipagar;

import com.example.pengendalipagar.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;

public class LoginActivity extends Activity{

/*private ImageButton Login;
private ImageButton Exit;
private EditText Passcode;*/

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    ImageButton Login = (ImageButton)findViewById(R.id.imbLogin);
    ImageButton Exit = (ImageButton)findViewById(R.id.imbExit);
    //EditText Passcode = (EditText)findViewById(R.id.txtPasscode);

    Login.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            callLogin();
            }
    });
    Exit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            callKeluar();
            }
    });
}

public void callLogin(){
    Intent myMenu = new Intent(this, MnUtama.class);
    startActivity(myMenu);
}
public void callKeluar(){
    finish();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.login, menu);
    return true;
}

  }

这是我的代码 Activity2 Activity_mnutama.xml

<RelativeLayout 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/cover">

    <ImageButton
        android:id="@+id/imbOpen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="26dp"
        android:layout_marginTop="141dp"
        android:src="@drawable/open" />

    <ImageButton
        android:id="@+id/imbClose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imbOpen"
        android:layout_marginLeft="18dp"
        android:layout_toRightOf="@+id/imbOpen"
        android:src="@drawable/close" />

    <ImageButton
        android:id="@+id/imbSetting"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imbOpen"
        android:layout_below="@+id/imbOpen"
        android:layout_marginTop="25dp"
        android:src="@drawable/setting" />

    <ImageButton
        android:id="@+id/imbExit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/imbClose"
        android:layout_alignTop="@+id/imbSetting"
        android:src="@drawable/exit"/>

    <EditText
        android:id="@+id/txtStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imbClose"
        android:layout_alignLeft="@+id/imbOpen"
        android:layout_alignRight="@+id/imbClose"
        android:layout_marginBottom="16dp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="22dp"
        android:text="@string/main_menu"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@style/AppBaseTheme"
        android:textSize="15pt"
        android:textStyle="bold" />

</RelativeLayout>

这是我的 Activity2 MnUtama.java 代码:

package com.ta.pengendalipagar;

import com.example.pengendalipagar.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;

public class MnUtama extends Activity {

/*private ImageButton Open;
private ImageButton Close;
private ImageButton Setting;
private ImageButton Exit;
private EditText Status;*/

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mnutama);

    ImageButton Open = (ImageButton)findViewById(R.id.imbOpen);
    ImageButton Close = (ImageButton)findViewById(R.id.imbClose);
    ImageButton Setting = (ImageButton)findViewById(R.id.imbSetting);
    ImageButton Exit = (ImageButton)findViewById(R.id.imbExit);
    EditText Status = (EditText)findViewById(R.id.txtStatus);

    Exit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            callKeluar();
            }
    });
}

public void callKeluar(){
    finish();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.login, menu);
    return true;
}

}

这是我的 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pengendalipagar"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.ta.pengendalipagar.LoginActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
   <activity
        android:name="com.ta.pengendalipagar.MnUtama"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    </application>

    </manifest>

最佳答案

我认为问题出在 activity_mnutama.xml 的最后一个 TextView 的以下字符串:

 android:textColor="@style/AppBaseTheme"

你的做法不对,删除这一行。要通过样式设置 textColor,您应该将此行添加到 TextView 声明中:

 style="@style/AppBaseTheme"

其中AppBaseTheme如下所示:

<style name="AppBaseTheme">
    <item name="android:textColor">#FFF</item>
</style>

关于java - android.view.InflateException : Binary XML file line #52: Error inflating class <unknown>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23289865/

相关文章:

android - 根据服务器响应动态加载图像列表

Eclipse Egit : Update a github fork to merge changes of master repo?

eclipse - 新 Eclipse : Error while downloading 'http://maven.apache.org/xsd/maven-4.0.0.xsd' to C:\Users\Fabian. Meier\.lsp4xml\

eclipse - GWT:对多个页面使用相同的 UI 模板?

java - ConcurrentHashMap修饰符的同步

java - 寻找一个支持 django 风格的 url 处理的 java web 框架

java - 动态创建的 ImageView 在创建时被拉伸(stretch)

java - ionic 构建 Android 失败

android - 为自定义 View 添加圆角

android - 在 Android 中从 AsyncTask 检索返回的字符串