0

Im my app I want to use this NumberPicker:

https://github.com/SimonVT/android-numberpicker

I've copied the .jar file from this project, build the path in Eclipse, and imported it at my MainActivity class.

My xml file has the following code:

<net.simonvt.widget.NumberPicker
    android:id="@+id/numberPicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

But I am getting this error at LogCat:

11-21 15:12:41.486: E/AndroidRuntime(6315): java.lang.RuntimeException: Unable to start activity ComponentInfo{xxxxxxxx.MainActivity}: android.view.InflateException: Binary XML file line #138: Error inflating class net.simonvt.widget.NumberPicker
11-21 15:12:41.486: E/AndroidRuntime(6315): Caused by: android.view.InflateException: Binary XML file line #138: Error inflating class net.simonvt.widget.NumberPicker
11-21 15:12:41.486: E/AndroidRuntime(6315):     at net.simonvt.widget.NumberPicker.<init>(NumberPicker.java:532)

What is happening?

Thank you!

androidevil
  • 9,011
  • 14
  • 41
  • 79

1 Answers1

1

You have to add your lib form java build path. just right click the properties and then find java build path to add your jar.

   <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:custom="http://schemas.android.com/apk/res/net.simonvt.widget.NumberPicker"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical" >
 <net.simonvt.widget.NumberPicker
  android:id="@+id/numberPicker"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />
 </LinearLayout

Try this.

kamil
  • 579
  • 4
  • 15
  • 1
    I think you are having error while inflating your view, Please add more code. – kamil Nov 21 '12 at 17:25
  • @user1771682 please specify in what package your creating your custom view. – kamil Nov 21 '12 at 17:27
  • I think, the problem is this: Android 4.0 NumberPicker backported to 2.1 Requires JakeWhartons NineOldAndroids library. It is included as a jar, but also available at: https://github.com/JakeWharton/NineOldAndroids Probably has to be built against API level 15 To use this library, it's required that 4 attributes are added to your theme. Check the sample app on how this is done. – androidevil Nov 21 '12 at 17:34
  • No I am trying fix the themes. – androidevil Nov 21 '12 at 17:34
  • have you added xmlns:custom to your parent layout? – kamil Nov 21 '12 at 17:41
  • No. How can I do this? Eclipse shows this warning: Unused namespace custom. – androidevil Nov 21 '12 at 17:44
  • My xml is already this way. And Eclipse show the warning: Unused namespace custom. And the app does not works. – androidevil Nov 21 '12 at 17:56
  • can you please specify in code where you are getting this warnings? – kamil Nov 21 '12 at 17:59
  • I've already fixed my project. I just added a libray which should be used in the project. Thank you – androidevil Nov 21 '12 at 18:41