【问题标题】:Making an Application on eclipse(Android/Java)在 Eclipse 上制作应用程序(Android/Java)
【发布时间】: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;
}

}

请帮帮我!! 我必须在明天之前消除错误,因为我必须在周一向我的主管展示界面,而我的最后一年项目的辩护是下周。 我将非常感谢。

【问题讨论】:

  • 第一个和第二个错误:在&lt;requestFocus /&gt;之前加上一个结束&gt;
  • 第三、第四个错误:需要导入R类。
  • 第三次和第四次我写了一个声明:import com.example.watcharound.R;在我的主要,但它没有工作
  • @AndyTurner 补充说 > 也有帮助:(
  • @AndyTurner:不,如果com.example.watcharound 是应用程序的基础包,则不会。 R文件是在这个包中生成的,因此不需要导入

标签: java android xml eclipse layout


【解决方案1】:

否 1. 您忘记关闭第一个 EditText 标记。在 requestfocus 标签前添加 >。

<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 />  
    </EditText>

No 2。与 No 1 相同的错误。

<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 />
</EditText>

没有 3 和 4 是由于不正确的 xml 导致的构建错误。更正错误 1 ​​和 2 并重建项目。

【讨论】:

  • 之前??
  • 如果我在 之前添加 /> 它会在其下方的 Text> 中给出警告:此文本字段未指定 inputType 或提示,并且错误仍然那里
  • 正确的格式是 。请尝试使用我在答案中添加的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-16
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-08
相关资源
最近更新 更多