问题描述
我正在使用AppCompatActivity库来支持所有设备.升级android-support-v7-appcompat
库后,我面临问题.但是我在运行时遇到错误.我正在使用Eclipse Studio为Android项目编写代码.任何帮助将不胜感激.
I am using the AppCompatActivity library to make support all the devices. After upadting the android-support-v7-appcompat
library i am facing issue. But i am facing an error during run-time. I am using eclipse studio to code for android project. Any help will be appreciated.
下面是我的错误,我不知道我要去哪里.
Below is my error ,and i am getting no idea where i am going wrong.
**错误**
E/AndroidRuntime(6899): FATAL EXCEPTION: main
E/AndroidRuntime(6899): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.drawer.sample/com.drawer.sample.MainActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.internal.widget.NativeActionModeAwareLayout
E/AndroidRuntime(6899): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
E/AndroidRuntime(6899): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime(6899): at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime(6899): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime(6899): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(6899): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(6899): at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime(6899): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(6899): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(6899): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime(6899): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime(6899): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.internal.widget.NativeActionModeAwareLayout
E/AndroidRuntime(6899): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
E/AndroidRuntime(6899): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
E/AndroidRuntime(6899): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:890)
E/AndroidRuntime(6899): at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
E/AndroidRuntime(6899): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
E/AndroidRuntime(6899): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
E/AndroidRuntime(6899): at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
E/AndroidRuntime(6899): at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:299)
E/AndroidRuntime(6899): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
E/AndroidRuntime(6899): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
E/AndroidRuntime(6899): at com.drawer.sample.MainActivity.onCreate(MainActivity.java:12)
E/AndroidRuntime(6899): at android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime(6899): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime(6899): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
E/AndroidRuntime(6899): ... 10 more
E/AndroidRuntime(6899): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.internal.widget.NativeActionModeAwareLayout" on path: DexPathList[[zip file "/data/app/com.drawer.sample-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(6899): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(6899): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(6899): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(6899): at android.view.LayoutInflater.createView(LayoutInflater.java:571)
E/AndroidRuntime(6899): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
E/AndroidRuntime(6899): ... 23 more
E/AndroidRuntime(6899): Suppressed: java.lang.ClassNotFoundException: android.support.v7.internal.widget.NativeActionModeAwareLayout
E/AndroidRuntime(6899): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(6899): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(6899): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(6899): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(6899): ... 26 more
E/AndroidRuntime(6899): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
activity_main.xml
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_layout"/>
<TextView
android:text="@string/app_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_marginTop="110dp"/>
</LinearLayout>
MainActivty.java
MainActivty.java
package com.drawer.sample;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
}
Style.xml
Style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent = "Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
</style>
推荐答案
我发现了may错误的解决方案,我必须添加appCompatActivity
的implements
覆盖方法.下面是我修复它的代码.
I found the solution of may error, i have to add the implements
override methods of appCompatActivity
. Below is the code by which i have fix it.
package com.drawer.sample;
import android.os.Bundle;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.Toolbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatCallback;
public class MainActivity extends AppCompatActivity implements AppCompatCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
@Override
public void onSupportActionModeFinished(ActionMode mode) {
// TODO Auto-generated method stub
super.onSupportActionModeFinished(mode);
}
@Override
public void onSupportActionModeStarted(ActionMode mode) {
// TODO Auto-generated method stub
super.onSupportActionModeStarted(mode);
}
}
我可以添加状态栏以及动作栏. :)
And i can add the statusbar as well actionbar. :)
这篇关于使用AppCompatActivity而不是Actionbar时发生运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!