更新Eclipse(Help -> Check for Updates
)和Android-SDK-Manager後,我總是得到「......無法解析爲類型」或「...無法解析到一個可變的「消息。我在每個已經創建的項目以及新的項目中都收到了這個錯誤消息。Eclipse(Android):無法解析爲類型/變量等
我已經嘗試過這些事情,但他們沒有制定出對我來說:
Project -> Clean...
Right click at the project -> Properties -> Java Build Path -> Libraries -> Add Library... -> JRE System Library
my apps dont run after update eclipse & adtWindow -> Preferences -> Java -> Compiler -> Building -> [x] Rebuild class files modified by others
所有這些三個步驟並沒有解決這些錯誤消息...也許別人有一個想法該怎麼辦?重新安裝Eclipse的應該是最後的選擇......它完全TOKE我永遠Eclipse中的GitHub :(
示例代碼連接:
package com.example.test;
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.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
錯誤消息:
ActionBarActivity cannot be resolved to a type MainActivity.java /TestProject/src/com/example/test line 7 Java Problem
ActionBarActivity cannot be resolved to a type MainActivity.java /TestProject/src/com/example/test line 11 Java Problem
ActionBarActivity cannot be resolved to a type MainActivity.java /TestProject/src/com/example/test line 31 Java Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. styles.xml /TestProject/res/values-v14 line 8 Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. styles.xml /TestProject/res/values line 7 Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. styles.xml /TestProject/res/values-v11 line 7 Android AAPT Problem
R cannot be resolved to a variable MainActivity.java /TestProject/src/com/example/test line 12 Java Problem
R cannot be resolved to a variable MainActivity.java /TestProject/src/com/example/test line 18 Java Problem
R cannot be resolved to a variable MainActivity.java /TestProject/src/com/example/test line 28 Java Problem
The method getMenuInflater() is undefined for the type MainActivity MainActivity.java /TestProject/src/com/example/test line 18 Java Problem
The method onCreate(Bundle) of type MainActivity must override or implement a supertype method MainActivity.java /TestProject/src/com/example/test line 10 Java Problem
The method onCreateOptionsMenu(Menu) of type MainActivity must override or implement a supertype method MainActivity.java /TestProject/src/com/example/test line 16 Java Problem
The method onOptionsItemSelected(MenuItem) of type MainActivity must override or implement a supertype method MainActivity.java /TestProject/src/com/example/test line 23 Java Problem
您是否刪除了appcompat_v7文件夾? – ridvanzoro 2014-10-06 21:09:13
嘗試在清潔模式下運行eclipse http://stackoverflow.com/questions/2030064/how-to-run-eclipse-in-clean-mode-and-what-happens-if-we-do-so – 2014-10-06 21:29:47
@ridvanzoro刪除appcompat_v7文件夾解決了新項目的問題。我現在可以嘗試刪除所有舊項目並導入它們。謝謝:) – 3dDi92 2014-10-07 07:18:52