ogaclejapan / SmartTabLayout

A custom ViewPager title strip which gives continuous feedback to the user when scrolling
Apache License 2.0
7.09k stars 1.34k forks source link

java.lang.ClassNotFoundException: Didn't find class "com.ogaclejapan.smarttablayout.demo.TintableImageView" #186

Open andersonbadari opened 8 years ago

andersonbadari commented 8 years ago

Just implemented custom tab icons and I am getting the following error:

FATAL EXCEPTION: main Process: com.mypackage, PID: 23770 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage/com.mypackage.views.activities.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class com.ogaclejapan.smarttablayout.demo.TintableImageView

Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.ogaclejapan.smarttablayout.demo.TintableImageView

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.ogaclejapan.smarttablayout.demo.TintableImageView" on path: DexPathList[[zip file "/data/app/com.mypackage-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

My code:

SetupTab.class:

public SmartTabLayout customizeTab(SmartTabLayout smartTab, Context context){

         final LayoutInflater inflater = LayoutInflater.from(smartTab.getContext());
         final Resources res = smartTab.getContext().getResources();

         smartTab.setCustomTabView(new SmartTabLayout.TabProvider() {

            @Override
            public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {

                ImageView icon = (ImageView) inflater.inflate(R.layout.tab_custom_icons, container,false);

                switch (position) {
                    case 0:
                        icon.setImageDrawable(res.getDrawable(R.drawable.ic_menu_camera));
                        break;
                    case 1:
                        icon.setImageDrawable(res.getDrawable(R.drawable.ic_menu_gallery));
                        break;
                    case 2:
                        icon.setImageDrawable(res.getDrawable(R.drawable.ic_menu_manage));
                        break;
                    default:
                        throw new IllegalStateException("Invalid position: " + position);
                }
                return null;
            }
        });
        return smartTab;

    }
<?xml version="1.0" encoding="utf-8"?>
<com.ogaclejapan.smarttablayout.demo.TintableImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/lib/com.mypackage"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:background="?attr/selectableItemBackground"
    android:padding="6dp"
    android:scaleType="center"
    app:tint="@color/custom_tab_icon"
    />

I had to chage the xmlns to "http://schemas.android.com/apk/lib/com.mypackage" because "http://schemas.android.com/apk/res-auto" was giving me "Error:(2) No resource identifier found for attribute 'tint' in package 'com.mypackage'" on apk compilling....

MainActivity.class:

SmartTabLayout smartTab = (SmartTabLayout) findViewById(R.id.view_pager_tabs_menu);
SetupTab setup= new SetupTab();
smartTab = setup.customizeTab(smartTab, MainActivity.this);
smartTab .setViewPager(viewPager); // exception in this line
andersonbadari commented 8 years ago

nevermind. Solved.

andersonbadari commented 8 years ago

To anyone who s getting this same error:

change this line to the package that you created the TintableImageView class...

<com.ogaclejapan.smarttablayout.demo.TintableImageView

to, for example

<com.myproject.mypackage.TintableImageView

from

<?xml version="1.0" encoding="utf-8"?>
  <com.ogaclejapan.smarttablayout.demo.TintableImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/lib/com.mypackage"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:background="?attr/selectableItemBackground"
    android:padding="6dp"
    android:scaleType="center"
    app:tint="@color/custom_tab_icon"
    />