【问题标题】:error :activity_main can not be resolved or not a field错误:activity_main 无法解析或不是字段
【发布时间】:2013-08-17 14:33:16
【问题描述】:

遇到上述错误。followed this

但没有找到解决方案。检查了我的资源文件,但几乎没有任何用处建议我解决这个问题。这里放置 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" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="87dp"
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button1"
    android:layout_centerVertical="true"
    android:text="Button2" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button2"
    android:layout_below="@+id/button2"
    android:layout_marginTop="52dp"
    android:text="Button" />

</RelativeLayout>

【问题讨论】:

  • actity_main.xml 只是问题中的拼写错误还是文件的真实名称?
  • 你能在Java中显示你在哪里使用它,错误在哪里。另外,尝试清理你的项目,“Project --> Clean...”
  • @codeMagic 附上截图,右击查看图片
  • @codeMagic 是的,也尝试过清理并重新启动 eclipse

标签: android layout


【解决方案1】:

改变

setContentView(R.id.activity_main);

setContentView(R.layout.activity_main);

From the DocssetContentView()

从布局资源中设置活动内容。资源将被膨胀,将所有顶级视图添加到活动中。

如果您在gen 文件夹中查看R.java,则有不同的类。 R.id 是一个id,你给了一个特定的ViewR.layout 用于您创建的layout 文件.setContentVieweither takes alayoutor aView. Not anidof aView`。

【讨论】:

  • 不,目前还没有。不是一个愚蠢的问题...我见过更糟糕的情况,我们都从某个地方开始。
猜你喜欢
  • 1970-01-01
  • 2013-06-04
  • 2019-08-13
  • 2016-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-28
相关资源
最近更新 更多