我刚开始通过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)
由于存在大量文件,我不确定哪种文件最好提供。让我知道哪个文件,我将在这里复制代码。
MainActivity.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>
如果有帮助,我可以发布任何代码
答案 0 :(得分:8)
可以通过转到文件R.java
并从日志中搜索错误条目(例如0x7f0201f2
)来修复此类错误。它将对应一个变量。如果你看一下这个条目的包含方法,它会告诉你它是字符串,id,dimen等。
然后,您可以在项目中搜索此变量,并查找它是否已在资源文件中声明。
答案 1 :(得分:0)
您没有关闭布局中的<RelativeLayout>
标记。
在xml文件的末尾添加</RelativeLayout>
。
答案 2 :(得分:0)
使用RelativeLayout
</RelativeLayout>
标记