2015-09-06 161 views
1

我最近决定将我的工作环境从Eclipse 更改为Android Studio。我决定通过Android Studio导入我的Eclipse项目。Android Studio找不到现有的符号

问题是,当我编译我的代码时,遇到2个错误,它说它找不到两个现有的符号。这些符号实际上是保存在res <可绘制的< hdpi中的两个png图片。但是,程序仍然无法找到这两张照片。我有一堆其他图片可以在同一个文件夹中完美地工作。我通过删除导致错误的两张图片控制了这一点,并以成功的结果测试了应用程序。

这里是整个错误消息:

(1)

Error:(101, 32) error: cannot find symbol variable thegodfather 
Error:(101, 78) error: cannot find symbol variable kingofcomedy 
Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

(2)

/Users/rawandsultani/Documents/ANDROID/V1/v11/app/src/main/java/com/exple/top100/Top100Activity.java:101: error: cannot find symbol 
      flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy, 
             ^
    symbol: variable thegodfather 
    location: class drawable 
/Users/rawandsultani/Documents/ANDROID/V1/v11/app/src/main/java/com/exple/top100/Top100Activity.java:101: error: cannot find symbol 
      flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy, 
                        ^
    symbol: variable kingofcomedy 
    location: class drawable 
Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
2 errors 

FAILED 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

(3)

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0. 
     Searched in the following locations: 
     file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom 
     file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.jar 
     https://jcenter.bintray.com/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom 
     https://jcenter.bintray.com/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.jar 
     Required by: 
     :v11:unspecified 
     Consult IDE log for more details (Help | Show Log) 

的图像保存在一个数组,这里是数组:

flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy, 
        R.drawable.drstrangelove} 

两个不工作的R.drawables是.godfather和.kingofcomedy。

我检查了资源确实存在,甚至删除并替换它们,没有任何运气。

我环顾四周堆栈来寻找答案,发现了很多类似的问题,但这些人的被清洗或者项目,无效并重新启动或重建,甚至重新启动该程序解决。这些都没有为我工作。

这里是我的gradle.build代码:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 


    defaultConfig { 
     applicationId "com.exple.v1" 
     minSdkVersion 15 
     targetSdkVersion 23 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
     } 
    } 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_7 
     targetCompatibility JavaVersion.VERSION_1_7 
    } 
} 

dependencies { 
    compile 'com.android.support:appcompat-v7:23.0.1' 
    compile fileTree(dir: 'libs', include: ['*.jar']) 

} 

这里是我的清单文件,以防万一有人开始需要看看它:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.exple.v1" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="15" 
     android:targetSdkVersion="23" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
     > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 

环顾四周后有点,我想我已经找到了我的problem,但我不确定在哪里实施解决方案代码,如果您点击链接,链接位于链接中。它是上限还是下限?

+0

你确定你已经下载了构建工具和最新版本的android sdk吗? –

+0

是的,我确定,我已经下载了几乎所有的东西。 – Rawand

回答

0

这是你的问题之一。我不知道它是否会解决其他问题。

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0. 

这个版本不存在

检查您的顶级build.gradle。您应该使用版本1.3.0而不是23.0.0。

buildscript { 
    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:1.3.0' 
    } 
} 

这是Android的gradle插件,它与sdk无关。

+0

我正在显示的gradle.build是较低的级别,但是我检查了较高级别并且它是正确的,就像您已经显示的那样 – Rawand

0

您的问题不在于资源。问题是,你的构建工具无法找到:

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0. 

生成您的资源文件(包含所有资源的ID)所需的工具无法找到,这意味着永远不会产生你R类,并因此Java编译器抱怨找不到这些符号。

您已经表明您拥有所有最新的Android SDK更新,但您确定Android Studio指向正确的Android SDK位置吗? 假设你使用的是Android SDK的一些实例 - 但Android Studio自带了它自己的Android SDK实例,可能不会使用你认为的那个。

有错误看看路径:

Searched in the following locations: 
     file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom 

这是否路径您的计算机上存在吗?它是在哪里安装您的Android SDK?你能找到那个地方的23.0.1构建工具文件夹吗?如果没有,你可能需要解决这个问题来解决你的问题 - this question可能会帮助你。

+0

您突出显示的错误不再接收。因此,我假定SDK路径是有序的。我已经检查过,所以你知道。 – Rawand