Eclipse (Android):不能解析为类型/变量等

时间:2022-05-22 15:49:32

Hey guys after updating Eclipse (Help -> Check for Updates) and Android-SDK-Manager I always get the "…cannot be resolved to a type" or "…cannot be resolved to a variable" message. I get this Error-Message at every single project I already had created as well as on new ones.

嘿,伙计们,在更新了Eclipse(帮助->检查更新)和Android-SDK-Manager之后,我总是得到“……不能解析为类型”或“……不能解析为变量”消息。我在我已经创建的每个项目以及新项目中都得到了这个错误消息。

I have already tried those things but none of them worked out for me:

我已经尝试过这些东西,但没有一个对我有用:

  1. Project -> Clean...
  2. 项目- >干净……
  3. Right click at the project -> Properties -> Java Build Path -> Libraries -> Add Library... -> JRE System Library my apps dont run after update eclipse & adt
  4. 右键点击项目->属性-> Java构建路径->库->添加库…-> JRE系统库我的应用程序在更新eclipse & adt之后不运行。
  5. Window -> Preferences -> Java -> Compiler -> Building -> [x] Rebuild class files modified by others
  6. 窗口->首选项-> Java ->编译器->构建-> [x]重建被其他人修改的类文件

All those three steps didn't solve those error messages...maybe someone else has an idea what to do? Reinstall Eclipse should be the last option…it totally toke me forever to connect Eclipse with GitHub :(

这三个步骤并没有解决这些错误消息……也许有人知道该怎么做?重新安装Eclipse应该是最后一个选项…它完全可以让我永久地连接Eclipse和GitHub:(

Example Code:

示例代码:

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);
    }
}

Error messages:

错误消息:

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 个解决方案

#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 :)

You do not need to delete appcompat_v7, there are good xml files , animations inside this folder, you may want use them. To change or remove appcompat_v7 folder from your project,

您不需要删除appcompat_v7,这个文件夹中有很好的xml文件和动画,您可能需要使用它们。要从项目中更改或删除appcompat_v7文件夹,

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

#2


0  

Sorry I can't put this into a comment, but I don't have the reputation required to do so. Try to go to window -> show view -> problems.

对不起,我不能对此发表评论,但我没有必要这样做。尝试去窗口->显示视图->问题。

It should display all eclipse-related problems as well as the problems with your code. If there are any eclipse related issues, could you post them? I know I had a problem with the android-eclipse bundle -- I ended up having to download the 32 bit libraries even though I am using a 64 bit OS. It worked immediately afterwards, and all it took was checking the problems view.

它应该显示所有与eclipse相关的问题以及代码中的问题。如果有任何与eclipse相关的问题,您可以发布它们吗?我知道我对android-eclipse包有一个问题——我最终不得不下载了32位的库,尽管我使用的是64位操作系统。之后立即开始工作,只需要检查problems视图。

Secondly, if you've tried project -> clean, and that didn't fix it, then it probably has nothing to do with the automatic file generation files being deleted, like the appcompat_v7 folder, as it would regenerate upon clean. It is most likely a missing library issue.

其次,如果您尝试过project -> clean,并且没有修复它,那么它可能与被删除的自动文件生成文件(比如appcompat_v7文件夹)没有关系,因为它会在干净的情况下重新生成。这很有可能是图书馆丢失的问题。

Please post the results of this operation.

请公布这次操作的结果。

#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 :)

You do not need to delete appcompat_v7, there are good xml files , animations inside this folder, you may want use them. To change or remove appcompat_v7 folder from your project,

您不需要删除appcompat_v7,这个文件夹中有很好的xml文件和动画,您可能需要使用它们。要从项目中更改或删除appcompat_v7文件夹,

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

#2


0  

Sorry I can't put this into a comment, but I don't have the reputation required to do so. Try to go to window -> show view -> problems.

对不起,我不能对此发表评论,但我没有必要这样做。尝试去窗口->显示视图->问题。

It should display all eclipse-related problems as well as the problems with your code. If there are any eclipse related issues, could you post them? I know I had a problem with the android-eclipse bundle -- I ended up having to download the 32 bit libraries even though I am using a 64 bit OS. It worked immediately afterwards, and all it took was checking the problems view.

它应该显示所有与eclipse相关的问题以及代码中的问题。如果有任何与eclipse相关的问题,您可以发布它们吗?我知道我对android-eclipse包有一个问题——我最终不得不下载了32位的库,尽管我使用的是64位操作系统。之后立即开始工作,只需要检查problems视图。

Secondly, if you've tried project -> clean, and that didn't fix it, then it probably has nothing to do with the automatic file generation files being deleted, like the appcompat_v7 folder, as it would regenerate upon clean. It is most likely a missing library issue.

其次,如果您尝试过project -> clean,并且没有修复它,那么它可能与被删除的自动文件生成文件(比如appcompat_v7文件夹)没有关系,因为它会在干净的情况下重新生成。这很有可能是图书馆丢失的问题。

Please post the results of this operation.

请公布这次操作的结果。