0

I have a very frustrated error, that I cannot explain. I create an Android application. This is the XML of the problem.

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>

And here is main code of my activity :

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

The main problem here is : above code run smoothly on almost devices (ANDROID KITKAT or LOLLIPOP ). But when I run it on lower versions ICS come this error.

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

GRADLE

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

Please tell me how to fix error, thanks :)

exequielc
  • 681
  • 1
  • 11
  • 32
  • java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable ... have you included googlePlay services dependency in your gradle file. Please provide build.gradle file too – Ramesh Aug 25 '15 at 19:44
  • setContentView(R.layout.LinearMapa) change to setContentView(R.layout.widget_mapa); – Ravind Maurya Aug 25 '15 at 19:45
  • added gradle @Ramesh – exequielc Aug 25 '15 at 19:47
  • compile 'com.google.android.gms:play-services-maps:7.5.0' this along with metadata in androidmanifest is what we need to do for maps setup. !! – Ramesh Aug 25 '15 at 19:49
  • can you check if you have both requirements satisfied – Ramesh Aug 25 '15 at 19:49
  • after change play-service 7.5.0 have this error, java.lang.NoClassDefFoundError: android.support.v4.widget.SlidingPaneLayout$SlidingPanelLayoutImplJBMR1 at android.support.v4.widget.SlidingPaneLayout.(SlidingPaneLayout.java:200) 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) .... @Ramesh – exequielc Aug 25 '15 at 20:03
  • Can you please try to be on 4.0 google play services only and try the answer i gave below. Using supportMapFragment. – Ramesh Aug 25 '15 at 20:06
  • is your problem solved – Ramesh Aug 26 '15 at 05:26
  • If I change MapFragment to SupprtFragment then I have to modify a lot of coding. Is there another option to fix this error? The manifest is fine and the play-service now is in 4.0 and the project is working on Kitkat but not in ICS @Ramesh – exequielc Aug 26 '15 at 11:47
  • I dont think too much code. only imports needs to be changed because supportFragment almost has all the methods that mapFragment was using. just that this has support for previous verions as well.. and As far as I know No other options to make it work on lower devices without supportMapFragment – Ramesh Aug 26 '15 at 11:50
  • same error with FragmentActivity and SupportMapFragment – exequielc Aug 26 '15 at 12:29
  • 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.SupportMapFragment.onInflate(Unknown Source) @Ramesh – exequielc Aug 26 '15 at 12:32

2 Answers2

0

I think your error will go away if you use com.google.android.gms.maps.SupportMapFragment instead MapFragment.

MapFragment expects minimum version of android to be 11. Use supportMapFragment whenever you want to go below sdk version 11.

Ramesh
  • 1,287
  • 1
  • 9
  • 14
0

Fixed! The solution was change jdk1.8.0_40 too jdk1.7.0_75 go to project structure and change jdk 1.8 to jdk1.7 I Don't know why this could bring that error. If some one know please explain to me..

exequielc
  • 681
  • 1
  • 11
  • 32
  • 1
    good to know you fixed issue yourself :) from following posts it looks developing android does not support jdk1.8 it seems. http://stackoverflow.com/questions/27622370/android-sdk-for-eclipse-using-google-play-services-lib-error-target-runtime-jr – Ramesh Aug 26 '15 at 13:45
  • yes, but that is for eclipse. In my case my work is in Android Studio – exequielc Aug 26 '15 at 14:09