【发布时间】:2015-09-13 15:57:11
【问题描述】:
我的问题是我已经解决了所有警告,现在生成了 4 个错误,2 个在 xml 文件中,2 个在 Main
错误 1:(signup.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/signup">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:ems="10"
android:text="@string/my_strings"
android:hint="@string/my_strings"
<requestFocus /> // Error parsing XML: not well-formed (invalid token)
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10"
android:hint="@string/my_stringss" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_below="@+id/editText2"
android:layout_marginTop="28dp"
android:ems="10"
android:hint="@string/my_stringsss" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:text="@string/my_stringssss" />
错误 2(search.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/search" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="37dp"
android:layout_marginTop="41dp"
android:src="@drawable/shopping"
android:contentDescription="@string/desc" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageButton1"
android:layout_marginLeft="81dp"
android:layout_toRightOf="@+id/imageButton1"
android:src="@drawable/historicalplacees"
android:contentDescription="@string/desc"/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageButton1"
android:layout_marginLeft="19dp"
android:layout_toLeftOf="@+id/imageButton3"
android:ems="10"
android:text="@string/my_stringz"
android:hint="@string/my_stringzx" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignLeft="@+id/imageButton2"
android:layout_alignParentRight="true"
android:ems="10"
android:text="@string/my_stringzz"
android:hint="@string/my_stringzxx"
<requestFocus /> //Error parsing XML: not well-formed (invalid token)
</EditText>
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:src="@drawable/food"
android:contentDescription="@string/desc" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageButton3"
android:layout_below="@+id/imageButton3"
android:layout_toLeftOf="@+id/editText2"
android:ems="10"
android:text="@string/my_stringzzz"
android:hint="@string/my_stringzxxx" />
</RelativeLayout>
错误号 3 和 4(在 MainActivityjava 中)
package com.example.watcharound;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);// Error :R cannot be resolved to a variable
}
@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);// Error :R cannot be resolved to avariable
return true;
}
}
请帮帮我!! 我必须在明天之前消除错误,因为我必须在周一向我的主管展示界面,而我的最后一年项目的辩护是下周。 我将非常感谢。
【问题讨论】:
-
第一个和第二个错误:在
<requestFocus />之前加上一个结束>。 -
第三、第四个错误:需要导入
R类。 -
第三次和第四次我写了一个声明:import com.example.watcharound.R;在我的主要,但它没有工作
-
@AndyTurner 补充说 > 也有帮助:(
-
@AndyTurner:不,如果
com.example.watcharound是应用程序的基础包,则不会。 R文件是在这个包中生成的,因此不需要导入
标签: java android xml eclipse layout