2015-03-25 51 views
0

我在我的應用程序中使用定製定時器選擇器對話框。它工作得很好API版本11或更高,但在API版本9或10中得到例外。在android中定時器選擇器對話框中獲取異常9在android中我

任何人都可以幫助我嗎?

我的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_gravity="center_horizontal" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 

<LinearLayout android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layoutDirection="ltr"> 

    <!-- hour --> 
    <NumberPicker 
     android:id="@+id/hour" 
     android:layout_width="70dip" 
     android:layout_height="wrap_content" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     /> 

    <!-- minute --> 
    <NumberPicker 
     android:id="@+id/minute" 
     android:layout_width="70dip" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="5dip" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     /> 

    <!-- seconds --> 
    <NumberPicker 
     android:id="@+id/seconds" 
     android:layout_width="70dip" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="5dip" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     /> 

</LinearLayout> 

<!-- AM/PM --> 
<Button 
    android:id="@+id/amPm" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="43dip" 
    android:layout_marginStart="5dip" 
    android:paddingStart="20dip" 
    android:paddingEnd="20dip" 
    style="?android:attr/textAppearanceLargeInverse" 
    android:textColor="@android:color/primary_text_light_nodisable" 
    /> 

例外:

FATAL EXCEPTION: main 
 
java.lang.IllegalStateException: Could not execute method of the activity 
 
at android.view.View$1.onClick(View.java:2179) 
 
at android.view.View.performClick(View.java:2535) 
 
at android.view.View$PerformClick.run(View.java:9129) 
 
at android.os.Handler.handleCallback(Handler.java:618) 
 
at android.os.Handler.dispatchMessage(Handler.java:123) 
 
at android.os.Looper.loop(SourceFile:351) 
 
at android.app.ActivityThread.main(ActivityThread.java:3826) 
 
at java.lang.reflect.Method.invokeNative(Native Method) 
 
at java.lang.reflect.Method.invoke(Method.java:538) 
 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969) 
 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727) 
 
at dalvik.system.NativeStart.main(Native Method) 
 
Caused by: java.lang.reflect.InvocationTargetException 
 
at java.lang.reflect.Method.invokeNative(Native Method) 
 
at java.lang.reflect.Method.invoke(Method.java:538) 
 
at android.view.View$1.onClick(View.java:2174) 
 
... 11 more 
 
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class com.example.customtimepicker.TimePicker 
 
at android.view.LayoutInflater.createView(LayoutInflater.java:549) 
 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:601) 
 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:654) 
 
at android.view.LayoutInflater.inflate(LayoutInflater.java:439) 
 
at android.view.LayoutInflater.inflate(LayoutInflater.java:351) 
 
at android.view.LayoutInflater.inflate(LayoutInflater.java:307) 
 
at com.example.customtimepicker.MyTimePickerDialog.<init>(MyTimePickerDialog.java:100) 
 
at com.example.customtimepicker.MyTimePickerDialog.<init>(MyTimePickerDialog.java:67) 
 
at com.example.customtimepicker.MainActivity.timePicker(MainActivity.java:24) 
 
... 14 more 
 
Caused by: java.lang.reflect.InvocationTargetException 
 
at java.lang.reflect.Constructor.constructNative(Native Method) 
 
at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 
 
at android.view.LayoutInflater.createView(LayoutInflater.java:536) 
 
... 22 more 
 
Caused by: java.lang.NoClassDefFoundError: com.example.customtimepicker.TimePicker$3 
 
at com.example.customtimepicker.TimePicker.<init>(TimePicker.java:96) 
 
at com.example.customtimepicker.TimePicker.<init>(TimePicker.java:82) 
 
... 25 more

回答

0

號產品圖ker API在API級別11中添加,因此您不能直接在xml文件中使用它。

您必須創建自定義數字選擇器才能支持API級別9.請查找以下鏈接,瞭解自定義數字選擇器。

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

+0

我已經實現了相同的代碼時間選擇器,但我發現錯誤時拋出。 – Krishan 2015-03-25 13:14:18

相關問題