2014-10-06 34 views
1

更新Eclipse(Help -> Check for Updates)和Android-SDK-Manager後,我總是得到「......無法解析爲類型」或「...無法解析到一個可變的「消息。我在每個已經創建的項目以及新的項目中都收到了這個錯誤消息。Eclipse(Android):無法解析爲類型/變量等

我已經嘗試過這些事情,但他們沒有制定出對我來說:

  1. Project -> Clean...
  2. Right click at the project -> Properties -> Java Build Path -> Libraries -> Add Library... -> JRE System Librarymy apps dont run after update eclipse & adt
  3. Window -> 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 
+0

您是否刪除了appcompat_v7文件夾? – ridvanzoro 2014-10-06 21:09:13

+0

嘗試在清潔模式下運行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

+0

@ridvanzoro刪除appcompat_v7文件夾解決了新項目的問題。我現在可以嘗試刪除所有舊項目並導入它們。謝謝:) – 3dDi92 2014-10-07 07:18:52

回答

0
@ridvanzoro Deleting the appcompat_v7 folder fixed the problem for new projects. I now can try to remove all of my old projects and import them. Thanks :) 

你不需要刪除appcompat_v7,這個文件夾裏面有很好的xml文件,動畫,你可以使用它們。要更改或刪除項目中的appcompat_v7文件夾,請參閱

Right click at project->Build Path->Configure Build Path->Lİbraries Tab->Android Dependencies 
0

對不起,我不能放但是我沒有這樣的聲望,試着去窗口 - >顯示視圖 - >問題。

它應該顯示所有與日蝕有關的問題作爲你的代碼的問題。如果有任何與日食有關的問題,你可以發佈嗎?我知道我的android-eclipse軟件包有問題 - 即使我使用的是64位操作系統,我也不得不下載32位庫。它之後立即起作用,並且只需檢查問題視圖。其次,如果你已經嘗試了project - > clean,並且沒有修復它,那麼它可能與被刪除的自動文件生成文件無關,比如appcompat_v7文件夾,因爲它會重新生成清潔。這很可能是缺失的圖書館問題。

請發佈此操作的結果。

+0

我已經在我的第一篇文章中列出了這個視圖中出現的所有問題('問題')。 – 3dDi92 2014-10-07 07:25:15

+0

我沒有意識到這些是問題視圖的輸出,因爲我認爲它們是編譯/運行時的錯誤。如果這些文件所在的軟件包不是默認軟件包,請嘗試導入R.java。 (如果它們來自默認包,請嘗試導入com.example.test.R,但這本身很可能會導致一些錯誤。) – Nerdizzle 2014-10-09 00:04:01