我想用西蒙夫特号码选择器。我已经成功地将库添加到我的项目中,并且我已经成功地使用库运行了示例项目。
但在我的项目中我有一个例外:
12-01 21:39:48.543:e/androidruntime(987):java.lang.runtimeexception:无法启动>活动组件信息{com.tekna.digiguide/com.tekna.digiguide.kayithourpickeractivity}:>java.lang.classcasteexception:net.simonvt.widget.numberpicker
有人能帮忙吗?
我的XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

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

    <Button
        android:id="@+id/buttonPickerEkle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>

我的行为
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.pickerlayout);

        final NumberPicker np = (NumberPicker) findViewById(R.id.numberPicker);
        np.setMaxValue(24);
        np.setMinValue(1);
        np.setFocusable(true);

        np.setFocusableInTouchMode(true);
    }

最佳答案

似乎是您导入的:

import android.widget.NumberPicker;

但你想用的是:
import net.simonvt.widget.NumberPicker;

07-26 09:41