【发布时间】: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的导入并再次导入