eclipse中的appcompat_v7错误

时间:2014-11-17 16:47:36

标签: android eclipse

我刚接触到android编程。我刚刚安装了eclipse和sdk以及adt插件。当我导入其他项目时,正常工作正常。但是当我创建一个新项目时,它会给我带来很多错误。

这里是错误:

*Description    Resource    Path    Location    Type
Unknown error: java.lang.NullPointerException   appcompat_v7        Unknown Android Packaging Problem

*ActionBarActivity cannot be resolved to a type MainActivity.java   /Testsaid/src/com/example/testsaid  line 32 Java Problem

*The method getMenuInflater() is undefined for the type MainActivity    MainActivity.java   /Testsaid/src/com/example/testsaid  line 19 Java Problem

*R cannot be resolved to a variable MainActivity.java   /Testsaid/src/com/example/testsaid  line 19 Java Problem

*The method onOptionsItemSelected(MenuItem) of type MainActivity must override or implement a supertype method  MainActivity.java   /Testsaid/src/com/example/testsaid  line 24 Java Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. styles.xml  /Testsaid/res/values    line 7  Android AAPT Problem
*R cannot be resolved to a variable MainActivity.java   /Testsaid/src/com/example/testsaid  line 29 Java Problem
*The method onCreateOptionsMenu(Menu) of type MainActivity must override or implement a supertype method    MainActivity.java   /Testsaid/src/com/example/testsaid  line 17 Java Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. styles.xml  /Testsaid/res/values-v11    line 7  Android AAPT Problem
*R cannot be resolved to a variable MainActivity.java   /Testsaid/src/com/example/testsaid  line 13 Java Problem
*ActionBarActivity cannot be resolved to a type MainActivity.java   /Testsaid/src/com/example/testsaid  line 12 Java Problem
*The method onCreate(Bundle) of type MainActivity must override or implement a supertype method MainActivity.java   /Testsaid/src/com/example/testsaid  line 11 Java Problem
*ActionBarActivity cannot be resolved to a type MainActivity.java   /Testsaid/src/com/example/testsaid  line 8  Java Problem
*The import android.support.v7 cannot be resolved   MainActivity.java   /Testsaid/src/com/example/testsaid  line 3  Java Problem
*error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.  styles.xml  /Testsaid/res/values-v14    line 8  Android AAPT Problem

这是主要活动的代码:

package com.example.saidg;

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

我注意到他们中的大多数都来自于值文件夹。它们标有一个小红叉

我还注意到已经创建了一个名为appcompat的新项目。我看到有关此问题的其他帖子,但他们没有帮助。目标sdk已在项目属性文件中设置为android 21。

感谢

2 个答案:

答案 0 :(得分:2)

转到

Right click your Project --> Properties --> Android --> 
(on the right side Library Section) (Click) Add --> Select appcompat_v7 (click ok and Apply)

现在清理并构建所有项目。

答案 1 :(得分:0)

您可以在不创建活动的情况下创建新项目。 - >解开创建活动。

或正常创建项目。这将创建新的Appcompat文件夹。然后,您可以删除新的库,并从项目的属性将库更改为旧库。

另一种错误可能性与Android支持库相冲突。您可以从项目文件夹中的libs文件夹中删除它。