启动时出错 activity android

Getting error in starting activity android

当我 运行 和 Mainactivity 时,我收到错误,在 content_main.xml 中显示错误(错误膨胀 class com.algolia.instantsearch.ui.views.Hits)。我无法解决它。我也改变了风格。请帮助我。

10-29 16:26:35.405 20712-20712/com.google.tho.oe E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
10-29 16:26:35.405 20712-20712/com.google.tho.oe W/dalvikvm: VFY: unable to resolve instanceof 354 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
10-29 16:26:35.415 20712-20712/com.google.tho.oe D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
10-29 16:26:36.055 20712-20712/com.google.tho.oe D/dalvikvm: GC_FOR_ALLOC freed 1340K, 26% free 11327K/15299K, paused 115ms, total 148ms
10-29 16:26:36.655 20712-20712/com.google.tho.oe I/dalvikvm: Could not find method org.greenrobot.eventbus.EventBus.getDefault, referenced from method com.algolia.instantsearch.ui.views.Hits.<init>
10-29 16:26:36.665 20712-20712/com.google.tho.oe W/dalvikvm: VFY: unable to resolve static method 64964: Lorg/greenrobot/eventbus/EventBus;.getDefault ()Lorg/greenrobot/eventbus/EventBus;
10-29 16:26:36.665 20712-20712/com.google.tho.oe D/dalvikvm: VFY: replacing opcode 0x71 at 0x00a6
10-29 16:26:36.675 20712-20712/com.google.tho.oe I/dalvikvm: Could not find method android.app.Activity.isDestroyed, referenced from method com.algolia.instantsearch.ui.views.Hits$HitsAdapter.onBindViewHolder
10-29 16:26:36.715 20712-20712/com.google.tho.oe W/dalvikvm: VFY: unable to resolve virtual method 111: Landroid/app/Activity;.isDestroyed ()Z
10-29 16:26:36.715 20712-20712/com.google.tho.oe D/dalvikvm: VFY: replacing opcode 0x6e at 0x00c4
10-29 16:26:36.745 20712-20712/com.google.tho.oe D/AndroidRuntime: Shutting down VM
10-29 16:26:36.745 20712-20712/com.google.tho.oe W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40e30438)
10-29 16:26:36.885 20712-20712/com.google.tho.oe E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.tho.oe/com.google.tho.oe.MainActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class com.algolia.instantsearch.ui.views.Hits
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
                                                                       at android.app.ActivityThread.access0(ActivityThread.java:143)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                       at android.os.Looper.loop(Looper.java:137)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:4960)
                                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                                       at java.lang.reflect.Method.invoke(Method.java:511)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
                                                                       at dalvik.system.NativeStart.main(Native Method)
                                                                    Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class com.algolia.instantsearch.ui.views.Hits
                                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693)
                                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                       at com.google.tho.oe.MainActivity.onCreate(MainActivity.java:63)
                                                                       at android.app.Activity.performCreate(Activity.java:5203)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139) 
                                                                       at android.app.ActivityThread.access0(ActivityThread.java:143) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                       at android.os.Looper.loop(Looper.java:137) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:4960) 
                                                                       at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                       at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
                                                                       at dalvik.system.NativeStart.main(Native Method) 
                                                                    Caused by: java.lang.reflect.InvocationTargetException
                                                                       at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                       at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:593)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693) 
                                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                       at com.google.tho.oe.MainActivity.onCreate(MainActivity.java:63) 
                                                                       at android.app.Activity.performCreate(Activity.java:5203) 
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078) 
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139) 
                                                                       at android.app.ActivityThread.access0(ActivityThread.java:143) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                       at android.os.Looper.loop(Looper.java:137) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:4960) 
                                                                       at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                       at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
                                                                       at dalvik.system.NativeStart.main(Native Method) 
                                                                    Caused by: java.lang.NoClassDefFoundError: org.greenrobot.eventbus.EventBus
                                                                       at com.algolia.instantsearch.ui.views.Hits.<init>(Hits.java:162)
                                                                       at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                       at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
                                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:593) 
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693) 
                                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                       at com.google.tho.oe.MainActivity.onCreate(MainActivity.java:63) 
                                                                       at android.app.Activity.performCreate(Activity.java:5203) 
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078) 
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139) 
                                                                       at android.app.ActivityThread.access0(ActivityThread.java:143) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                       at android.os.Looper.loop(Looper.java:137) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:4960) 
                                                                       at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                       at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
                                                                       at dalvik.system.NativeStart.main(Native Method) 

style.xml

   <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="drawerArrowStyle">@style/DrawerHamburgerStyle</item>
        <item name="actionBarWidgetTheme">@style/MyActionBarWidgetTheme</item>
    </style>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#fff"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    tools:context="com.google.tho.oes.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:orientation="horizontal"
        android:background="@drawable/side_nav_bar_four">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/transparent"
        android:id="@+id/temp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:titleTextColor="#fff"
            />

            </android.support.design.widget.AppBarLayout>

    </LinearLayout>
    <com.algolia.instantsearch.ui.views.SearchBox
        android:id="@+id/search_barer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       android:background="@drawable/side_nav_bar_four"
        android:searchHintIcon="@drawable/common_google_signin_btn_icon_dark"/>
    <include layout="@layout/content_main"
        />

</LinearLayout>

contain_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:algolia="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.google.tho.oes.MainActivity"
    tools:showIn="@layout/activity_main">

    <View
        android:id="@+id/activity_main_cente"
        android:layout_width="1dp"
        android:layout_height="1dp"
        android:layout_alignParentBottom="true"
        />
    <!--android:layout_centerInParent="true"-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_above="@id/activity_main_cente"
        android:id="@+id/map_placeholher">

        <FrameLayout
            android:id="@+id/map_placehol"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#f2f3f4"></FrameLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:orientation="vertical"
        android:layout_below="@id/activity_main_cente">
        <com.algolia.instantsearch.ui.views.Hits
            android:id="@+id/hits"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            algolia:autoHideKeyboard="false"
            algolia:hitsPerPage="10"
            algolia:itemLayout="@layout/hits_item"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            />
    </LinearLayout>
    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sorry, Please wait..."
        android:textColor="#345678"
        android:layout_alignTop="@+id/admin"
        android:layout_toRightOf="@+id/activity_main_cente"
        android:layout_toEndOf="@+id/activity_main_cente"
        android:layout_marginLeft="15dp"
        android:layout_marginStart="15dp" />
    <ImageView
        android:id="@+id/admin"
        android:layout_width="40dp"
        android:background="@drawable/oneone"
        android:layout_height="40dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="20dp"
        android:layout_marginEnd="20dp"
        android:layout_marginTop="21dp" />
</RelativeLayout>

Gradle 我的应用文件 :

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'
    defaultConfig {
        applicationId "com.google.tho.oe"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

Gradle 模块文件:

android {
    dataBinding {
        enabled true
    }

    compileSdkVersion 25
    buildToolsVersion '25.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName project.ext.VERSION
        consumerProguardFiles "proguard-rules.pro"
    }

你的问题来自没有org.greenrobot.eventbus.EventBus

只需将 compile 'org.greenrobot:eventbus:3.0.0' 添加到您的 gradle 依赖项中。

dependencies {
  //... your other dependencies
  compile 'org.greenrobot:eventbus:3.0.0'
}

更新: 由于问题是棒棒糖之前的问题,因此可能是 Multidex 的问题。以下是您应该尝试的方法:

  • compile 'com.android.support:multidex:1.0.1' 添加到您的 依赖项。
  • 在默认配置中添加multiDexEnabled true
  • 添加 android:name="android.support.multidex.MultiDexApplication" 给你的 manifest.xml 在 <application .. 部分