android.view.InflateException:一个特定设备中的二进制XML

时间:2015-08-25 19:39:46

标签: java android inflate-exception

我有一个非常沮丧的错误,我无法解释。我创建了一个Android应用程序。 这是问题的XML。

widget_mapa.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/quilmes_gray_fafafa"
android:orientation="vertical">

<!-- compact view -->
<LinearLayout
    android:id="@+id/compactViewContainer"
    android:layout_width="match_parent"
    android:layout_height="@dimen/base_item_size"
    android:paddingLeft="30dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/base_item_size"
        android:layout_weight="0.4"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_titulo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:paddingRight="10dp"
            android:text="Ubicación"
            android:textColor="@color/quilmes_blue"
            android:textStyle="bold" />


        <TextView
            android:id="@+id/tv_detalle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="5dp"
            android:text="geolocalizada"
            android:textColor="@color/gray"
            android:textSize="11.5sp"
            android:textStyle="normal" />


    </LinearLayout>

    <ImageView
        android:layout_width="@dimen/base_item_size"
        android:layout_height="@dimen/base_item_size"
        android:layout_gravity="center"
        android:layout_marginRight="4dp"
        android:adjustViewBounds="true"
        android:scaleType="centerInside"
        android:src="@drawable/ic_arrow_dark_abajo" />
</LinearLayout>


<!-- full view -->
<LinearLayout
    android:id="@+id/fullViewContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="gone">

    <include layout="@layout/double_line_separator" />

    <!-- frecuency -->

    <LinearLayout
        android:id="@+id/fullFrequencyContainer"
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:layout_gravity="center_vertical"
        android:layout_marginBottom="10dp"
        android:orientation="horizontal"
        android:weightSum="1.0">

        <fragment
            android:id="@+id/mapView"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>
    </LinearLayout>
</LinearLayout>

这是我活动的主要代码:

LinearMapa.java

public class LinearMapa extends LinearLayout {
private Activity activity;
private Context ctx;
private Cliente pdv;

public LinearMapa(Context context, AttributeSet attrs) {
    super(context, attrs);
    try {
        this.ctx = context;
        this.loadViewComponents();
        this.loadListeners();
    }catch (Exception e){
        e.printStackTrace();
    }
}

public LinearMapa(Context context, Activity activity,Cliente pdv) {
    super(context);
    this.ctx = context;
    this.activity = activity;
    this.loadViewComponents();
    this.loadListeners();
    this.pdv = pdv;

}




/**
 * LAYOUT_ID
 */
public static final int LAYOUT_ID = R.layout.widget_mapa;

/**
 * compactViewContainer
 */
private LinearLayout compactViewContainer;
private TextView tvTitulo;
private TextView tv_detalle;
private LinearLayout fullViewContainer;

/**
 * compactComerceName
 */
private TextView compactComerceName;

/**
 * compactAddress
 */
private TextView compactAddress;


/**
 * compactCodPdv
 */
private TextView compactCodPdv;


private void loadViewComponents() {
    try {
    // generate view
    (LayoutInflater.from(this.getContext())).inflate(LAYOUT_ID, this);

    // load UI
    this.compactViewContainer = (LinearLayout) this.findViewById(R.id.compactViewContainer);
    this.fullViewContainer = (LinearLayout) this.findViewById(R.id.fullViewContainer);
    this.tvTitulo = (TextView) this.findViewById(R.id.tv_titulo);
    this.tv_detalle = (TextView) this.findViewById(R.id.tv_detalle);

    }
    catch (Exception e){
        e.printStackTrace();
    }
}

这里的主要问题是:上面的代码几乎可以在几乎所有设备上运行(ANDROID KITKAT或LOLLIPOP)。但是当我在较低版本上运行ICS时出现此错误。

.InflateException: Binary XML file line #15: Error inflating class chess.samandroid.view.general.widget.LinearMapa
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
            at android.app.ActivityThread.access$600(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5392)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class chess.samandroid.view.general.widget.LinearMapa
            at android.view.LayoutInflater.createView(LayoutInflater.java:613)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
            at android.app.Activity.setContentView(Activity.java:1881)
            at chess.samandroid.view.cliente.activities.Cliente.onCreate(Cliente.java:149)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1084)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
            at android.app.ActivityThread.access$600(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5392)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            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:587)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
            at android.app.Activity.setContentView(Activity.java:1881)
            at chess.samandroid.view.cliente.activities.Cliente.onCreate(Cliente.java:149)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1084)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
            at android.app.ActivityThread.access$600(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5392)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
            at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
            at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
            at android.app.Activity.onCreateView(Activity.java:4734)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at chess.samandroid.view.general.widget.LinearMapa.loadViewComponents(LinearMapa.java:92)
            at chess.samandroid.view.general.widget.LinearMapa.<init>(LinearMapa.java:39)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
            at android.app.Activity.setContentView(Activity.java:1881)
            at chess.samandroid.view.cliente.activities.Cliente.onCreate(Cliente.java:149)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1084)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
            at android.app.ActivityThread.access$600(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5392)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)

摇篮

allprojects {
    repositories {
        mavenCentral()
        //maven { url 'http://dt-imac-ba-032:8082/nexus/content/repositories/legacy/' }
        // flatDir { dirs 'libs' }

        maven { url 'http://clinker.47deg.com/nexus/content/groups/public' }
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
}

apply plugin: 'com.android.application'

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.+'
    compile 'com.google.android.gms:play-services:4.0.+'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':qRCodeReaderViewlib')
    compile('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT@aar') {
        transitive = true
    }
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.github.nirhart:parallaxscroll:1.0'
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'commons-lang:commons-lang:2.6'
    compile 'com.github.amlcurran.showcaseview:library:5.0.0'
    //compile 'com.android.support:appcompat-v7:22.2.0'
    //compile 'com.rengwuxian.materialedittext:library:2.1.4'
}

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    compileOptions {
        encoding "UTF-8"
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    lintOptions {
        abortOnError false
    }
    dexOptions {
        javaMaxHeapSize "8g"
    }

    signingConfigs {
        // debug {
        //    storeFile file("../keystore/sam.keystore")
        //}
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/INDEX.LIST'
        exclude 'META-INF/ASL2.0'
    }
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "2.0.0"
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true

        // Enabling multidex support.
        multiDexEnabled true
    }
    productFlavors {
    }
}

请告诉我如何修复错误,谢谢:)

2 个答案:

答案 0 :(得分:0)

如果您使用com.google.android.gms.maps.SupportMapFragment而不是MapFragment,我认为您的错误将会消失。

MapFragment希望android的最低版本为11.只要你想要低于sdk版本11,就可以使用supportMapFragment。

答案 1 :(得分:0)

固定!解决方案是更改jdk1.8.0_40 jdk1.7.0_75 转到项目结构并将jdk 1.8更改为jdk1.7 我不知道为什么会带来这个错误。如果有人知道请向我解释..