Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “R”类不重新编码_Java_Android_Eclipse - Fatal编程技术网

Java “R”类不重新编码

Java “R”类不重新编码,java,android,eclipse,Java,Android,Eclipse,我的布局和视图的ID,eclipse无法识别它们并在它们下面加红线。 我建造了所有的项目,也清理了它们,但问题仍然存在。请提供任何建议 更新: 更新后的问题是,R类以红色突出显示 Java代码: setContentView(R.layout.mplmenu_activity); mMainMenuListView = (ListView) findViewById(R.id.ListView_Menu); String [] items = { getResource

我的布局和视图的ID,eclipse无法识别它们并在它们下面加红线。 我建造了所有的项目,也清理了它们,但问题仍然存在。请提供任何建议

更新:

更新后的问题是,R类以红色突出显示

Java代码:

setContentView(R.layout.mplmenu_activity);

    mMainMenuListView = (ListView) findViewById(R.id.ListView_Menu);
    String [] items = {   
 getResources().getString(R.string.menuItem_AddNewLocation),

 getResources().getString(R.string.menuItem_MySavedLocation),
                        getResources().getString(R.string.menuItem_GPSReadings),

 getResources().getString(R.string.menuItem_OpenCameraSurface)
                      };
    ArrayAdapter<String> adapt =new ArrayAdapter<String>(this,  
R.layout.mainMenuItems, items);
mplu activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" 
android:layout_width="match_parent">

      <LinearLayout 
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          android:background="@color/mplMenuActivityBackGroundColor" >              
          <RelativeLayout 
              android:id="@+id/RelativeLayout01"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top|center_horizontal">
              <TextView
                  android:id="@+id/TextView01"
                  android:layout_height="wrap_content"
                  android:text="@string/menu"
                  android:textSize="@dimen/mainMenuTextSize"
                  android:layout_marginLeft="18dp"
                  android:shadowDx="0"
                  android:shadowDy="0"
                  android:shadowRadius="10"
                  android:layout_width="wrap_content"
                  android:shadowColor="@android:color/white"
                  android:textColor="@color/mainMenuTextColor">
              </TextView>    
          </RelativeLayout>

          <RelativeLayout
              android:id="@+id/RelativeLayout02"
              android:layout_height="fill_parent"
              android:layout_width="fill_parent"
              android:layout_gravity="center">
              <ListView
                  android:layout_height="wrap_content"
                  android:id="@+id/ListView_Menu"
                  android:layout_width="wrap_content"
                  android:divider="@drawable/dividerline"
                  android:layout_alignParentTop="true">
              </ListView>
          </RelativeLayout>    
      </LinearLayout>
检查生成的R.java文件是否确实存在。您的一些XML资源文件中可能存在错误,从而阻止Android构建工具aapt生成R.java文件。根据我的经验,这通常就是找不到资源ID的原因


要修复此问题,您必须修复XML错误。

如果在活动类中有类似于导入\u package\u name.R的内容,请将其删除,然后清理项目,然后重新构建它。

请确保在XML中使用+id而不仅仅是id来标识它们

像这样: android:id=+id/btn1

不是这个:
android:id=id/btn1

我修复了xml的错误,但问题仍然存在:R.java文件是否存在?你可能需要清理你的项目。如果它不存在,那么您可能没有发现所有的XML问题。R.Layout被识别,但是任何布局的id都不存在。请确保您的布局的id是布局XML文件的名称,没有.XML扩展名。例如,如果布局文件名为foo.xml,则其ID为R.layout.foo。如果这不能解决您的问题,请提供您的布局XML,以及导致显示错误的代码。mplmmenu_activity.XML在最末端缺少end标记。实际文件是否缺少结束标记?如果这不是真正的问题,那么您需要修复eclipse报告的XML错误,我假设您使用的是eclipse?。eclipse问题视图窗口| Show view | Other…| General | Problems将显示所有错误。是否只有listview出错。可能会尝试在xml中重命名它,并查看新名称是否仍然出错。