Eclipse(Android):无法解析为类型/变量等

时间:2014-10-06 21:01:37

标签: java android eclipse types resolve

在更新Eclipse(Help -> Check for Updates)和Android-SDK-Manager之后,嘿伙计们总是得到“......无法解析为某种类型”或“......无法解析为变量”消息。我在已经创建的每个项目以及新项目上都会收到此错误消息。

我已经尝试过这些东西,但没有一个能为我效劳:

  1. Project -> Clean...
  2. Right click at the project -> Properties -> Java Build Path -> Libraries -> Add Library... -> JRE System Library my apps dont run after update eclipse & adt
  3. Window -> Preferences -> Java -> Compiler -> Building -> [x] Rebuild class files modified by others
  4. 所有这三个步骤都没有解决这些错误消息......也许其他人知道该怎么做?重新安装Eclipse应该是最后一个选项......它总是让我永远地将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
    

2 个答案:

答案 0 :(得分:0)

很抱歉,我无法对此发表评论,但我不具备这样做的声誉。尝试去窗口 - >显示视图 - >问题。

它应该显示所有与eclipse相关的问题以及代码的问题。如果有任何与日食相关的问题,你可以发布它们吗?我知道android-eclipse包有问题 - 我最终不得不下载32位库,即使我使用的是64位操作系统。它之后立即起作用,所有这一切都是检查问题视图。

其次,如果您尝试过项目 - >干净,并没有解决它,那么它可能与被删除的自动文件生成文件无关,如appcompat_v7文件夹,因为它将在清理时重新生成。这很可能是一个缺少库的问题。

请发布此操作的结果。

答案 1 :(得分: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