在R类型中创建字段布局/ main - 无法解析

问题描述:

我是Android编程的新手,并且即将运行Android应用程序。 我得到了R.layout无法解析为变量错误。当我导入com.package.r;并删除了android.r它没有做任何事情。在清理项目后错误消失了,但是它在r.layout.activity_main上发生了错误(转换为activity_list ...)。该代码片段已附加。在R类型中创建字段布局/ main - 无法解析

import android.app.Activity; 
import android.content.pm.ActivityInfo; 
import android.os.Bundle; 
import android.view.Menu; 
import com.procedure.culture.R; 


public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
} 

@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);` 

我已重新启动eclipse并清理了一百万次项目,但徒劳无功。 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: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" 
android:background="#A1F5F8" > 

<!-- 
<TextView 
    android:id="@+id/tv_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/title" 
    android:textColor="#000000" 
    android:textSize="30dp" 
    /> 
    --> 
+0

您关闭了标记吗? – Robert 2014-08-28 11:58:30

+0

是@Robert,多数民众赞成在关闭! – CSA 2014-08-28 12:02:59

+0

检查:http://www.tutorialspoint.com/android/android_hello_world_example.htm – 2014-08-28 12:03:40

尝试以下操作:

1.check whether there are bugs in XML files. 

2.Try to rebulid your application 

3.Check for any missing library files. 
从你的问题

也不要导入[R包。它的自动生成文件。删除所有关于r的输入。

可能是您的XML文件中存在一些错误。检查..

+0

检查错误。没有在XML中。重建也完成了。没有帮助。 :( – CSA 2014-08-28 12:04:20

+0

如何检查lib文件? – CSA 2014-08-28 12:06:54

+0

右键项目,转到属性 – Subburaj 2014-08-28 12:07:51

有时清洗多次android失去对R的引用(例如R.id ...) 也避免运行其他方的应用程序并在您创建的应用程序中复制代码。

避免清单文件setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),而不是设置方向:

<activity 
    android:name=".activity.MainActivity" 
    android:label="@string/app_name" 
    android:screenOrientation="portrait" 
    android:configChanges="orientation"> 

虽然我正在寻找R上的错误,我读的地方取消选中Java的生成器。我这样做,但它给了我在这个问题线程中的错误。所以现在当我检查Java构建器时,错误已经消失。另外,我试图在错误开始弹出时在xml中添加imageview。我评论过它,但没有发生任何事情。现在,当错误消失后,我对它进行了评论,但在应用程序中无法看到图像。 无论如何,感谢您的帮助! :)

+0

这是类型R已经定义错误 http://stackoverflow.com/questions/5283414/type-r-is -already定义的误差 – CSA 2014-08-28 12:26:29