Android Studio:无法解析符号“ R”

尼古拉斯

我知道这个问题已经问过几次了,但是由于我的上下文,没有答案是有用的。问题是,我只是打开了第一个项目(在我的实际计算机中),而没有编辑所有的“ 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.gradlemobile目录中检查文件,并通过SDK管理器确保依赖关系与SDK内联。这通常是我的罪魁祸首,尤其是当我更新AS时。

不幸的是,对此没有“简单”的解决方案。在找到它之前,您将不得不尝试不同的方法,因为它可能与执行“清理并构建”一样简单。

祝好运!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Android Studio:无法解析符号“原始”

Android Studio错误:无法解析符号“视图”

无法解析符号textView-Android Studio

Android Studio无法解析符号“ GradleException”

Android Studio 3.0无法解析符号主题

Android Studio突然无法解析符号

Android Studio将R标记为红色,并显示错误消息“无法解析符号R”,但构建成功

Android-无法解析符号“ R”

Android Studio 2.1无法解析符号“ R”

无法在Android Studio中解析符号“ LocationClient”

在Android Studio中无法解析符号“ R”:“清单合并失败,出现多个错误,请参阅日志”

无法在Android Studio中解析符号WebRTC

Android Studio无法解析AAR中的符号

Android Studio“无法解析符号R”,但项目会编译并运行

在Android Studio中更新到Gradle 3.3.2时出错:无法解析符号R

无法在Android Studio中解析符号“注释”?

无法解析符号'Paint'Android Studio

Android Studio出现问题!无法解析符号R,找不到与给定名称匹配的资源

Android Studio 0.9.0-无法解析符号

Android Studio(1.1.0):-无法解析符号“ R”

Android Studio:无法解析R

无法解析符号R Android DialogFragment

无法解析符号Android Studio

Android Studio无法解析符号

Android studio 无法解析 R.xxx 后的符号

Android Studio:错误:无效的恶魔和“R”符号无法解析

新的 Android Studio:无法解析符号“ContextCompat”

Android Studio:从 Github 导入项目并使用 gradle 文件重建/清理/同步后“无法解析符号 R”

无法在 android studio 中解析符号“coordinatorlayout”