-3

I'm trying to fix my app and I can't figure out what's the problem. The problem is ONLY when I run the app on Android version < 4.0 so I guess the problem is about appcompat, but I have no idea how to fix it. The error when I run it is this:

07-30 09:40:44.726  14081-14081/my.app.pag E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{my.app.pag/my.app.pag.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class TextView
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:123)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
            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 #2: Error inflating class TextView
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
            at my.app.pag.utils.SlidingTabLayout.populateTabStrip(SlidingTabLayout.java:207)
            at my.app.pag.utils.SlidingTabLayout.setViewPager(SlidingTabLayout.java:166)
            at my.app.pag.fragment.MainFragment.onCreateView(MainFragment.java:96)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
            at it.seatpg.core.activity.CoreActivity.onStart(CoreActivity.java:119)
            at my.app.pag.MainActivity.onStart(MainActivity.java:469)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
            at android.app.Activity.performStart(Activity.java:3791)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:123)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x101030e a=-1}
            at android.content.res.Resources.loadDrawable(Resources.java:1681)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
            at android.view.View.<init>(View.java:1961)
            at android.widget.TextView.<init>(TextView.java:376)
            at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:44)
            at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:40)
            at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
            at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:802)
            at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:832)
            at android.support.v4.view.LayoutInflaterCompatBase$FactoryWrapper.onCreateView(LayoutInflaterCompatBase.java:36)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
            at my.app.pag.utils.SlidingTabLayout.populateTabStrip(SlidingTabLayout.java:207)
            at my.app.pag.utils.SlidingTabLayout.setViewPager(SlidingTabLayout.java:166)
            at my.app.pag.fragment.MainFragment.onCreateView(MainFragment.java:96)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
            at my.app.core.activity.CoreActivity.onStart(CoreActivity.java:119)
            at my.app.pag.MainActivity.onStart(MainActivity.java:469)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
            at android.app.Activity.performStart(Activity.java:3791)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:123)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)

The code in my fragment (in onCreateView) is this:

ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_main,
        container, false);

ViewPager pager = (ViewPager) root.findViewById(R.id.pager);
FragmentManager fm = getChildFragmentManager();

MainPagerAdapter adapter = new MainPagerAdapter(fm, getActivity(),
        recentWhere, recentWhat);
pager.setAdapter(adapter);
// pager.setOffscreenPageLimit(2);
// pager.setCurrentItem(page);

SlidingTabLayout slidingTabLayout = (SlidingTabLayout) root
        .findViewById(R.id.sliding_tabs);
slidingTabLayout.setCustomTabView(R.layout.custom_tab, 0);
slidingTabLayout.setBackgroundColor(getResources().getColor(R.color.pb_blue));
slidingTabLayout.setDistributeEvenly(true);
slidingTabLayout.setViewPager(pager);
slidingTabLayout
        .setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
            @Override
            public int getIndicatorColor(int position) {
                return getResources().getColor(R.color.pb_white);
            }
        });

My gradle build is this one:

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 22
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.google.android.gms:play-services-location:7.5.0'
    compile 'com.google.android.gms:play-services-analytics:7.5.0'
    compile 'io.gsonfire:gson-fire:1.0.1'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile files('libs/cardview-v7.jar')
    compile files('libs/core-2.13.42.jar')
    compile files('libs/recyclerview-v7.jar')
    compile files('libs/simple-xml-2.7.jar')
    compile files('libs/universal-image-loader-1.9.1.jar')
    compile files('libs/GoogleConversionTrackingSdk-2.2.2.jar')
    compile project(':adobeMobileLibrary-4.4.1')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/adagiosdk_2.6.1.jar')
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.android.support:design:22.2.0'
}

This is the xml of the fragment

<my.app.pag.slideup.SlidingUpPanelLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    app:shadowHeight="4dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <my.app.pag.utils.SlidingTabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" >
        </android.support.v4.view.ViewPager>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/grid_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="10dp" >

        <GridView
            android:id="@+id/grid_view_services"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:choiceMode="singleChoice"
            android:gravity="center"
            android:numColumns="3"
            android:stretchMode="columnWidth" />
    </LinearLayout>

</my.app.pag.slideup.SlidingUpPanelLayout>

I didn't find the problem in my xml as printed in the error log... Could you please find it?

What's a possible solution?

Thanks

michoprogrammer
  • 1,159
  • 2
  • 18
  • 45

3 Answers3

0

I think you maybe using the context on the inflater

final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.myInflatedLayout, null);

instead try it like this

final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.myInflatedLayout, null);

remove the "this" or "context" from the "getSystemService"

Rob85
  • 1,719
  • 1
  • 23
  • 46
  • But why it works perfectly on android >= 4.0? And where is the color or the background color that you said? Every time that I use a color I use getResources and getColor or getDrawable if I need a drawable.. I really can't explain this issue... And I'm getting a lot of "-" to the question.... – michoprogrammer Jul 30 '15 at 08:13
  • try setting the background colour to a hex colour like setBackgroundColor(0xFFFFFFFF) – Rob85 Jul 30 '15 at 08:26
  • Background color of which part? Because the error points to an xml in which there aren't colors! – michoprogrammer Jul 30 '15 at 08:51
  • Change this part in the main activity slidingTabLayout.setBackgroundColor(getResources().getColor(R.color.pb_blue)); to the above just to see if it works. this is still running xml in the background and i think that is what it is referring to – Rob85 Jul 30 '15 at 08:56
0

Try passing textview id as the second parameter for this function. slidingTabLayout.setCustomTabView(R.layout.custom_tab, 0).

Fabin Paul
  • 1,701
  • 1
  • 16
  • 18
0

I FOUND THE SOLUTION!

my custom_tab.xml was

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="12sp"
    android:textStyle="bold"
    android:background="?android:selectableItemBackground
    android:padding="16dp"
    android:gravity="center"
/>

and now is

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="12sp"
    android:textStyle="bold"
    android:background="@color/pb_blue"
    android:padding="16dp"
    android:gravity="center"
/>

Now I have to test a lot! Thanks for all your replies and gtfo to all who downvoted!

Bye bye and thanks ^^

michoprogrammer
  • 1,159
  • 2
  • 18
  • 45
  • no if you had uploaded your custom view to begin with this would have saved alot of time – Rob85 Jul 30 '15 at 10:01