我正在为> = API 8开发Android应用程序。
出于兼容性原因,该应用程序使用Actionbar Sherlock。在API 11之前,NumberPicker是一个内部小部件,但我需要NumberPicker,所以我不得不想出另一个解决方案。
经过一番谷歌搜索,我偶然发现了迈克诺瓦克的NumberPicker。我实现了它,但不幸的是,当我点击应该使用numberpicker打开对话框的首选项时,应用程序崩溃了。
对布局的引用似乎有问题(logcat表示使用了com.example.widget.NumberPicker
)文件,但是源com.michaelnovakjr.numberpicker.R.layout.pref_number_picker
引用了here。
LogCat输出:
12-13 13:59:27.516: W/dalvikvm(11642): threadid=1: thread exiting with uncaught exception (group=0x40dbe930)
12-13 13:59:27.555: E/AndroidRuntime(11642): FATAL EXCEPTION: main
12-13 13:59:27.555: E/AndroidRuntime(11642): android.view.InflateException: Binary XML file line #24: Error inflating class com.michaelnovakjr.numberpicker.NumberPicker
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.preference.DialogPreference.onCreateDialogView(DialogPreference.java:343)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.preference.DialogPreference.showDialog(DialogPreference.java:287)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.preference.DialogPreference.onClick(DialogPreference.java:266)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.preference.Preference.performClick(Preference.java:949)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:215)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.widget.AbsListView$1.run(AbsListView.java:3423)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.os.Handler.handleCallback(Handler.java:725)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.os.Handler.dispatchMessage(Handler.java:92)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.os.Looper.loop(Looper.java:137)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-13 13:59:27.555: E/AndroidRuntime(11642): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 13:59:27.555: E/AndroidRuntime(11642): at java.lang.reflect.Method.invoke(Method.java:511)
12-13 13:59:27.555: E/AndroidRuntime(11642): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-13 13:59:27.555: E/AndroidRuntime(11642): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-13 13:59:27.555: E/AndroidRuntime(11642): at dalvik.system.NativeStart.main(Native Method)
12-13 13:59:27.555: E/AndroidRuntime(11642): Caused by: java.lang.reflect.InvocationTargetException
12-13 13:59:27.555: E/AndroidRuntime(11642): at java.lang.reflect.Constructor.constructNative(Native Method)
12-13 13:59:27.555: E/AndroidRuntime(11642): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
12-13 13:59:27.555: E/AndroidRuntime(11642): ... 23 more
12-13 13:59:27.555: E/AndroidRuntime(11642): Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.example.widget.NumberPickerButton
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.inflate(LayoutInflater.java:459)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-13 13:59:27.555: E/AndroidRuntime(11642): at com.michaelnovakjr.numberpicker.NumberPicker.<init>(NumberPicker.java:125)
12-13 13:59:27.555: E/AndroidRuntime(11642): at com.michaelnovakjr.numberpicker.NumberPicker.<init>(NumberPicker.java:117)
12-13 13:59:27.555: E/AndroidRuntime(11642): ... 26 more
12-13 13:59:27.555: E/AndroidRuntime(11642): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.widget.NumberPickerButton" on path: /data/app/nl.livecarb.android-1.apk
12-13 13:59:27.555: E/AndroidRuntime(11642): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
12-13 13:59:27.555: E/AndroidRuntime(11642): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-13 13:59:27.555: E/AndroidRuntime(11642): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
12-13 13:59:27.555: E/AndroidRuntime(11642): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
12-13 13:59:27.555: E/AndroidRuntime(11642): ... 31 more
RES / XML / main_preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:picker="http://schemas.android.com/apk/res/nl.livecarb.android" >
<PreferenceCategory android:title="@string/pref_cat_title_medical" >
<com.michaelnovakjr.numberpicker.NumberPickerPreference
android:key="@string/pref_key_ratio"
android:summary="Bla"
android:title="@string/pref_title_ratio"
picker:defaultValue="1"
picker:endRange="31"
picker:startRange="1" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_cat_title_other" >
<Preference
android:key="@string/pref_key_disclaimer"
android:title="@string/pref_title_disclaimer" />
</PreferenceCategory>
</PreferenceScreen>
SettingsActivity.java
public class SettingsActivity extends PreferenceActivity implements OnPreferenceClickListener {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(android.os.Build.VERSION.SDK_INT >= 11) {
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment(), "settings").commit();
} else {
addPreferencesFromResource(R.xml.main);
}
}
class SettingsFragment extends PreferenceFragment {
private Preference preferences = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.main);
preferences = findPreference(getResources().getString(R.string.pref_key_disclaimer));
preferences.setOnPreferenceClickListener(SettingsActivity.this);
}
}
}
错误
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.widget.NumberPickerButton" on path: /data/app/nl.livecarb.android-1.apk
对我没有任何意义,因为我从未使用com.example.widget.NumberPickerButton
。 NumberPicker lib都没有。
我试图解决这个问题的事情:
有什么想法吗?
答案 0 :(得分:1)
你是在离开项目的主分支吗?尝试搜索代码以获取对该示例包的引用。我只是看了一下图书馆,我没有看到它的任何参考。