我刚开始通过Java开发Android(我以前只使用PosiGAP)。
我用一个简单的表单文本字段和send按钮创建了我的第一个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)

由于有很多文件,我不确定哪一个最好提供的代码。告诉我哪个文件,我就把代码复制到这里。
main活动.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;
}

}

活动\主.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并从日志中搜索错误条目来修复。它将对应于一个变量。如果你看看这个条目的包含方法,它会告诉你它是一个字符串,id,dimen等等。
然后,您可以在项目中搜索此变量,并查找它是否已在资源文件中声明。

10-07 19:52
查看更多