【问题标题】:appcompat_v7 errors in eclipseeclipse 中的 appcompat_v7 错误
【发布时间】:2014-12-24 02:45:14
【问题描述】:

我是 android 编程新手。我刚刚安装了 eclipse、sdk 和 adt 插件。当我导入其他项目时,evereting 工作正常。但是当我创建一个新项目时,它给了我很多错误。

以下是错误:

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

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

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

谢谢

【问题讨论】:

  • 添加错误消息可能会帮助任何试图帮助你的人
  • 请在错误所在的地方发布一些代码......以及什么错误消息? Logcat... appcompat_v7 是一个创建的支持库。
  • 好的,我会添加错误
  • 还贴一些代码,尤其是出现错误的导入语句..
  • 尝试删除从appcompat库中导入的menu、menu item、inflater的导入并再次导入

标签: android eclipse


【解决方案1】:

前往

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

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

【讨论】:

  • 我在 appcompat 库旁边发现了一个红十字标记。我重新导入了它,它变成了绿色,但是错误仍然存​​在。我再次检查了图书馆部分。我又发现它是红色的。
  • 你为什么不发布代码...?至少显示您的 MainActivity.java!如果您想获得帮助。
  • 好的。我会添加执行我,但它只是一个默认的 hello world 项目。使用默认设置。我将在描述中发布它
  • 导入 ActionBarActivity 时出错...?和? ActionBarActivity 无法解析为 MainActivity.java 类型;当无法导入 ActionBarActivity 或有两个 android-support-v7-appcompat.jar 实例时会出现这种情况
  • 我的项目 lib/ 文件夹中有一个额外的 apcompat jar,我将其删除。并清理项目并构建。该项目现在正在运行
【解决方案2】:

您可以在不创建活动的情况下创建新项目。 --> 取消勾选创建活动。

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

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

【讨论】:

  • 我很喜欢这个。这样做时,它不会创建 appcompat 文件夹,但相同的错误仍然存​​在
  • 三种方法都试过了吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-27
  • 1970-01-01
  • 1970-01-01
  • 2015-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多