我很困惑。今天,我刚刚重新安装Android的工作室版本1.0.2(和Android SDK),因为我昨天遇到了一些问题,当我创建了一个新的项目。我希望我能解决这些问题,只需重新安装了一切,但实际上问题依然存在,我不知道如何解决它。
I’m very confused. Today I just reinstalled Android Studio Version 1.0.2 (and the Android SDK) because I had some problems yesterday when I created a new project. I hoped that I could solve them by just reinstall everything, but actually the problem still exists and I don’t know how to solve it.
在我创建了Android的Studio中的一个新项目,并切换到我的MainActivity(我没有在文件中的一个改变任何东西),我总是在文件中显示以下错误。
After I created a new project in Android Studio and switch to my MainActivity (I didn't changed anything in one of the files), I always get the following errors displayed in the file.
MainActivity.class:
package com.android.testapplication;
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);
}
}
错误:
在无法解析符号ActionBarActivity 在无法解析的方法的onCreate(android.os.Bundle) 在无法解析的方法的setContentView(int)的 在无法解析法getMenuInflater() 在无法解析的方法的setContentView(int)的 在无法解析法onOptionsItemSelected(android.view.MenuItem)项目:build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
模块:build.gradle
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.android.testapplication"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
我已经重建和清理我的项目,同步工程与摇篮文件
但他们没有固定的我的问题。
I already rebuild and cleaned my project and 'Sync Project with Gradle Files'
but none of them fixed my issues.
有趣的是,我可以编译和我的智能手机上运行我的项目...
The funny thing is, that I can compile and run my project on my smartphone…
PS:我想这似乎是一个摇篮的问题,因为每当我添加一个新的库,例如'com.google.android.gms:玩-服务:87年6月5日
,然后尝试导入'进口com.google.android.gms.gcm.GoogleCloudMessaging;
。我也得到了无法解析符号......显示
错误。我没有与GCM服务符合它...
PS: I guess it seems to be a gradle issue, because whenever I add a new library such as 'com.google.android.gms:play-services:6.5.87'
and then try to import it 'import com.google.android.gms.gcm.GoogleCloudMessaging;'
. I also get the 'Cannot resolve symbol…'
error displayed. I didn’t complied it with the GCM Service…
感谢您的帮助提前:)
我是pretty的在这个新的,但我推英里的想象力发挥到极致,并发现了一个古老的问题的答案是doydoy。
I'm pretty new at this, but I pushed mi imagination to the limit and found the answer in an old question by "doydoy".
对于大家谁需要它,你可以在这里找到它:
For everyone who needs it, you can find it here:
Android工作室说"不能解析符号"但项目编译
但对于懒惰的,它是:
文件
> 无效缓存/重新启动......
和无效并重新启动
来解决这个问题。
File
> Invalidate Caches / Restart...
and Invalidate and Restart
to solve the issue.