Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPagerIndicator ClassNotFoundException?

I'm trying to use Jake Wharton's ViewPagerIndicator library in my project, and I followed the simple tutorial laid out here:

http://viewpagerindicator.com/

But I keep getting a ClassNotFoundException when I try and run my project.

Here is the XML I have in my layout:

<android.support.v4.view.ViewPager
    android:id="@+id/day_pager"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" />

<com.viewpagerindicator.TitlePageIndicator
    android:id="@+id/titles"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" />

and here is the corresponding code I have (dayPage is a ViewPager type).

    ArrayList<Integer> testData = new ArrayList<Integer>();
    testData.add(12);
    testData.add(13);
    testData.add(22);

    dayPage = (ViewPager) this.getActivity().findViewById(R.id.day_pager);
    dayPage.setAdapter(new DayAdapter(testData));

    //Bind the title indicator to the adapter
    TitlePageIndicator titleIndicator = (TitlePageIndicator)this.getActivity().findViewById(R.id.titles);
    titleIndicator.setViewPager(dayPage);

The values in testData are garbage for now.

The full stack trace is:

08-25 22:32:23.420: E/AndroidRuntime(1710): FATAL EXCEPTION: main
08-25 22:32:23.420: E/AndroidRuntime(1710): android.view.InflateException: Binary XML file line #12: Error inflating class com.viewpagerindicator.TitlePageIndicator
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at vt.finder.sherlock.ScheduleFragment.onCreateView(ScheduleFragment.java:50)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at vt.finder.sherlock.ScheduleFragment.onCreate(ScheduleFragment.java:30)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:835)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:431)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.view.ViewPager.populate(ViewPager.java:895)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.view.ViewPager.populate(ViewPager.java:772)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1234)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.View.measure(View.java:8313)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.View.measure(View.java:8313)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.View.measure(View.java:8313)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.View.measure(View.java:8313)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.View.measure(View.java:8313)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.os.Looper.loop(Looper.java:130)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at java.lang.reflect.Method.invokeNative(Native Method)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at java.lang.reflect.Method.invoke(Method.java:507)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at dalvik.system.NativeStart.main(Native Method)
08-25 22:32:23.420: E/AndroidRuntime(1710): Caused by: java.lang.ClassNotFoundException: com.viewpagerindicator.TitlePageIndicator in loader dalvik.system.PathClassLoader[/data/app/vt.finder.sherlock-1.apk]
08-25 22:32:23.420: E/AndroidRuntime(1710):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.LayoutInflater.createView(LayoutInflater.java:471)
08-25 22:32:23.420: E/AndroidRuntime(1710):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
08-25 22:32:23.420: E/AndroidRuntime(1710):     ... 37 more

I imported the ViewPagerIndicator project as a library to my project, and I double checked that the package name was intact, and it was. I did a clean on my project, but still I get the class not found exception. Am I missing something?

like image 923
Ethan Avatar asked Aug 25 '12 22:08

Ethan


2 Answers

A lot of people add this to the lib's folder or import it (which is not correct)

Instead you need to add the whole project (source and all resources) under the properties/android dialog in the libraries section (shown below)

If your are not sure what you did then try removing all references to the library so that it is not in the library or referenced library folder and doesn't show up under the properties/java build path - libraries tab

Then add the whole project back into via the properties/android dialog, do a clean build (sometimes twice, thanks eclipse) and it should work correctly.

added it to Eclipse?

like image 198
Idistic Avatar answered Oct 04 '22 04:10

Idistic


The suggested steps above did not work for me, but this did the trick:

  • right click on project, properties
  • java build path, source tab
  • add folder, add the problematic folder
like image 26
keybee Avatar answered Oct 04 '22 04:10

keybee