【问题标题】:ClassCastException when using simonvt number picker使用 simonvt 数字选择器时出现 ClassCastException
【发布时间】:2012-12-01 19:46:56
【问题描述】:

我正在尝试使用 simonvt 号码选择器。我已成功地将库添加到我的项目中,并且已成功运行带有库的示例项目。 但在我的项目中,我得到了这个例外:

12-01 21:39:48.543: E/AndroidRuntime(987): java.lang.RuntimeException: 无法启动 >activity ComponentInfo{com.tekna.digiguide/com.tekna.digiguide.KayitHourPickerActivity}: >java. lang.ClassCastException: 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);
    }

【问题讨论】:

  • 贴出你的相关代码并指出这个错误发生在哪里。
  • 编辑并添加了我的代码

标签: android xml classcastexception numberpicker


【解决方案1】:

看来您已导入:

import android.widget.NumberPicker;

但你想使用:

import net.simonvt.widget.NumberPicker;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    相关资源
    最近更新 更多