2

我正在使用 AppCompatActivity 库来支持所有设备。更新图书馆后,android-support-v7-appcompat我面临问题。但是我在运行时遇到错误。我正在使用 Eclipse Studio 为 android 项目编写代码。任何帮助将不胜感激。

以下是我的错误,我不知道我哪里出错了。

** 错误 **

     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

    <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>

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

     }
 }

样式.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>

4

3 回答 3

1

ActionBar 在材料设计中用作工具栏。所以添加没有操作栏的主题并使用以下在xml中使用工具栏。

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:iosched="http://schemas.android.com/apk/res-auto"
style="@style/HeaderBar"
iosched:theme="@style/ActionBarThemeOverlay"
iosched:popupTheme="@style/ActionBarPopupThemeOverlay"
android:id="@+id/toolbar_actionbar"
iosched:titleTextAppearance="@style/ActionBar.TitleText"
iosched:contentInsetStart="?actionBarInsetStart"
android:layout_width="match_parent"
android:layout_height="?actionBarSize" />
于 2015-08-06T07:36:42.357 回答
1

implements我找到了可能错误的解决方案,我必须添加appCompatActivity. 下面是我修复它的代码。

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

我可以添加状态栏以及操作栏。:)

在此处输入图像描述

于 2015-08-06T07:48:02.847 回答
0

你有没有尝试在你的 gradle 文件中添加这个代码示例?

   android {
         configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
    all*.exclude group: 'com.android.support', module: 'support-annotations'
} }
于 2017-04-14T11:12:56.847 回答