我是ActionBarActivity的新手,我的应用程序在eclipse中运行以下代码时崩溃了 公共类登录扩展ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, 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);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment{
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_login,
container, false);
return rootView;
}
}
}
我已导入的地方
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
但我仍然在LogCat中遇到如下错误:
01-27 16:47:13.091: E/AndroidRuntime(320): FATAL EXCEPTION: main
01-27 16:47:13.091: E/AndroidRuntime(320): Process: com.element45.android.localsale.activities, PID: 320
01-27 16:47:13.091: E/AndroidRuntime(320): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/appcompat/R$styleable;
01-27 16:47:13.091: E/AndroidRuntime(320): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
01-27 16:47:13.091: E/AndroidRuntime(320): at com.element45.android.localsale.activities.Login.onCreate(Login.java:18)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.app.Activity.performCreate(Activity.java:6289)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.app.ActivityThread.access$900(ActivityThread.java:177)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.os.Handler.dispatchMessage(Handler.java:102)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.os.Looper.loop(Looper.java:145)
01-27 16:47:13.091: E/AndroidRuntime(320): at android.app.ActivityThread.main(ActivityThread.java:5942)
01-27 16:47:13.091: E/AndroidRuntime(320): at java.lang.reflect.Method.invoke(Native Method)
01-27 16:47:13.091: E/AndroidRuntime(320): at java.lang.reflect.Method.invoke(Method.java:372)
01-27 16:47:13.091: E/AndroidRuntime(320): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
01-27 16:47:13.091: E/AndroidRuntime(320): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
01-27 16:47:13.091: E/AndroidRuntime(320): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.appcompat.R$styleable" on path: DexPathList[[zip file "/data/app/com.element45.android.localsale.activities-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
01-27 16:47:13.091: E/AndroidRuntime(320): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-27 16:47:13.091: E/AndroidRuntime(320): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-27 16:47:13.091: E/AndroidRuntime(320): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
01-27 16:47:13.091: E/AndroidRuntime(320): ... 17 more
01-27 16:47:13.091: E/AndroidRuntime(320): Suppressed: java.lang.ClassNotFoundException: android.support.v7.appcompat.R$styleable
01-27 16:47:13.091: E/AndroidRuntime(320): at java.lang.Class.classForName(Native Method)
01-27 16:47:13.091: E/AndroidRuntime(320): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
01-27 16:47:13.091: E/AndroidRuntime(320): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
01-27 16:47:13.091: E/AndroidRuntime(320): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
01-27 16:47:13.091: E/AndroidRuntime(320): ... 18 more
01-27 16:47:13.091: E/AndroidRuntime(320): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
谢谢
答案 0 :(得分:2)
您应该使用 #Android Studio而不是Eclipse 。
当Java虚拟机(JVM)或ClassLoader类的实例尝试加载类的定义但无法找到定义时,将引发01-27 16:47:13.091:E / AndroidRuntime(320):引起: java.lang.ClassNotFoundException:没找到类 路径上的“android.support.v7.appcompat.R $ styleable”:DexPathList [[zip 文件 “/data/app/com.element45.android.localsale.activities-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, / system / lib]] 01-27 16:47:13.091:E / AndroidRuntime(320):at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 01-27 16:47:13.091:E / AndroidRuntime(320):at java.lang.ClassLoader.loadClass(ClassLoader.java:511)01-27 16:47:13.091:E / AndroidRuntime(320):at java.lang.ClassLoader.loadClass(ClassLoader.java:469)01-27 16:47:13.091:E / AndroidRuntime(320):... 17更多01-27 16:47:13.091: E / AndroidRuntime(320):抑制:java.lang.ClassNotFoundException: android.support.v7.appcompat.R $设置样式
NoClassDefFoundError 错误。
错误方法: 使用不推荐使用的代码(ActionBarActivity)。
首先扩展 AppCompatActivity而不是ActionBarActivity 。
public class Login extends AppCompatActivity {
// ...
}
<强>建议强>
设置android:minSdkVersion
版本。
<uses-sdk android:minSdkVersion="15" />
尝试这种方式,希望它能够成功。
答案 1 :(得分:0)
在Android SDK Manager中安装Android支持包 Android SDK Manager
将AppCompatActivity包添加到您的gradle配置
编译'com.android.support:appcompat-v7:23.1.0'
检查min SDK版本