Search code examples
androidwidgetcustomizationnumberpicker

How to solve android.view.InflateException when using com.android.internal.widget.NumberPicker?


I'm using this blog to create a custom Number Picker. I've added this source project to my Eclipse but when I run this project in emulator I get this error in LogCat.

10-14 15:31:46.074: E/AndroidRuntime(878): java.lang.RuntimeException: Unable to start
activity ComponentInfo{maximyudin.NumberPickerDemo/maximyudin.NumberPickerDemo.NumberPickerDemo}: 
android.view.InflateException: Binary XML file line #5: Error inflating class com.android.internal.widget.NumberPicker

Here is my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="maximyudin.NumberPickerDemo"
  android:versionCode="1"
  android:versionName="1.0">
  <uses-sdk android:targetSdkVersion="15" android:minSdkVersion="8"></uses-sdk>
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".NumberPickerDemo"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>


Solution

  • I found the problem. com.android.internal.widget.NumberPicker does not support in Android 2.2 and later. I tried to run this example in Android 2.2 and caused the error that I mentioned on my question. This is the main.xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.android.internal.widget.NumberPicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/numTestNumberPicker"
        android:layout_centerInParent="true">
    </com.android.internal.widget.NumberPicker>