gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 13:05:39 24 4
gpt4 key购买 nike

当我选择 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com