java - Android 错误 - 类膨胀错误

标签 java android

我刚刚开始通过 Java 进行 android 开发(我以前只使用过 phonegap)。

我用一个简单的表单文本字段和发送按钮创建了我的第一个 hello world 项目,但它无法运行。

我的错误日志如下:

12-06 20:31:11.482: E/AndroidRuntime(32656): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thesurvivor2299/com.example.thesurvivor2299.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
12-06 20:31:11.482: E/AndroidRuntime(32656): Caused by: android.view.InflateException: 

Binary XML file line #1: Error inflating class android.widget.RelativeLayout
12-06 22:32:31.304: W/ResourceType(804): Failure getting entry for 0x7f0201f2 (t=1 e=498) in package 0 (error -2147483647)
12-06 22:32:31.305: W/ResourceType(804): Failure getting entry for 0x7f0201f3 (t=1 e=499) in package 0 (error -2147483647)
12-06 22:32:31.305: W/ResourceType(804): Failure getting entry for 0x7f0201f4 (t=1 e=500) in package 0 (error -2147483647)
12-06 22:32:31.580: W/ResourceType(804): Failure getting entry for 0x7f020609 (t=1 e=1545) in package 0 (error -2147483647)
12-06 22:32:31.581: W/ResourceType(804): Failure getting entry for 0x7f020627 (t=1 e=1575) in package 0 (error -2147483647)
12-06 22:32:31.624: W/ResourceType(804): Failure getting entry for 0x7f0201f2 (t=1 e=498) in package 0 (error -2147483647)
12-06 22:32:31.624: W/ResourceType(804): Failure getting entry for 0x7f0201f3 (t=1 e=499) in package 0 (error -2147483647)
12-06 22:32:31.624: W/ResourceType(804): Failure getting entry for 0x7f0201f4 (t=1 e=500) in package 0 (error -2147483647)
12-06 22:32:31.646: W/ResourceType(804): Failure getting entry for 0x7f020609 (t=1 e=1545) in package 0 (error -2147483647)
12-06 22:32:31.646: W/ResourceType(804): Failure getting entry for 0x7f020627 (t=1 e=1575) in package 0 (error -2147483647)

由于有很多文件,我不确定最好提供哪个文件的代码。让我知道是哪个文件,我会将代码复制到这里。

主要 Activity .java:

public class MainActivity extends Activity {

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

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

}

activity_main.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="@style/AppTheme"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="35dp"
    android:ems="10"
    android:inputType="textWebEditText"
    android:singleLine="true" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/textView1"
    android:layout_below="@+id/editText1"
    android:layout_marginTop="36dp"
    android:text="Send" />

</RelativeLayout>

如果有帮助,我可以发布任何代码

最佳答案

可以通过转到文件 R.java 并从您的日志中搜索错误条目(例如 0x7f0201f2)来修复此类错误。它将对应于一个变量。如果你查看这个条目的包含方法,它会告诉你它是否是一个字符串、id、dimen 等。 然后你可以在你的项目中搜索这个变量,看看它是否已经在你的资源文件中声明。

关于java - Android 错误 - 类膨胀错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20433115/

相关文章:

java - 对取对数空间的快速排序的混淆

java - Android:检查 SMTP 服务器是否已启动并正在运行

android - 返回类型为 () -> MultipartBody.Part!而不是 MultipartBody.Part

android - Visual Studio cordova 工具 - 无法运行/调试/部署到 Android。亚行挂起

java - 有没有一种简单的方法可以使用 Jackson 展平 JSON 对象属性?

java - Java/J2EE 和 .NET for Coldfusion 中有哪些库?

java - 更改去电号码,添加前缀

android - Android 应用之间的单点登录

java - 在 Android 应用程序中使用 SSL

java - 在不启动接收 Activity 的情况下将数据传递给 Activity (Android)