我知道这个问题已经问过几次了,但是由于我的上下文,没有答案是有用的。问题是,我只是打开了第一个项目(在我的实际计算机中),而没有编辑所有的“ R”。在mainActivity.java中变为红色。有谁知道这个问题的原因是什么以及如何解决?
这是.java的主要活动
package com.nico.calc_02;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是.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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
我没有修改代码或任何东西。我正在使用Android Studio。有谁知道如何修理它?
可能有几件事:
1. You may need to do a clean & build 2. You may need to update the SDK (Go into your SDK manager, and make sure that all your files are up to date)
我发现这种情况主要发生在我更新AS时,并且在执行AS更新时,还需要通过SDK管理器更新SDK。确保您的工具也是最新的,而不仅仅是API。之类的东西com.android.support:support
,并com.google.android.gms:play-services
会导致此错误。检查Run
左下角的标签,这样可以使您了解是否已过期,并且需要进行更新。如果您使用的是库,则它们可能也已更新。
您还希望build.gradle
在mobile
目录中检查文件,并通过SDK管理器确保依赖关系与SDK内联。这通常是我的罪魁祸首,尤其是当我更新AS时。
不幸的是,对此没有“简单”的解决方案。在找到它之前,您将不得不尝试不同的方法,因为它可能与执行“清理并构建”一样简单。
祝好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句