SeekBar 正在崩溃空指针异常。

发布于 2025-01-03 05:49:24 字数 8969 浏览 3 评论 0原文

我有以下代码,并且我的搜索栏因空点异常而崩溃。 在我的最后一个问题为什么我的对话框搜索栏崩溃我可以找不到解决我的问题的信息。

这里的代码:

dialog_context_mark_edit:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/edit_mark_dialog"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name" />

    <EditText
        android:id="@+id/edit_mark_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/lololol"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"/>

    <SeekBar
        android:id="@+id/seek_edit_gewicht"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Note" />

    <EditText
        android:id="@+id/edit_mark_note"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Datum" />

    <DatePicker
        android:id="@+id/date_maturity_mark_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dip"
        android:orientation="horizontal" >

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

        <Button
            android:id="@+id/cmd_close_mark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/close" />
    </LinearLayout>

</LinearLayout>

class mark:

SeekBar seekBar_wertung, seek_edit_gewicht, seek_gewicht, seek_gewichtt;
TextView gewicht, gewicht_test;

OnSeekBarChangeListener yourSeekBarListener = new OnSeekBarChangeListener() {

public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
    // TODO Auto-generated method stub

    // change progress text label with current seekbar value
    gewicht_test.setText(progress+"%");
    // change action text label to changing
}

public void onStartTrackingTouch(SeekBar seekBar) {
}

public void onStopTrackingTouch(SeekBar seekBar) {
    seekBar.setSecondaryProgress(seekBar.getProgress());
}

};

Dialog:

@Override
protected Dialog onCreateDialog(int id) {
 Dialog dialog = null;;
    switch(id) {
    case ADD_MARK_DIALOG:
     dialog = new Dialog(mark.this);

     dialog.setContentView(R.layout.dialog_context_mark);
     dialog.setTitle("Note hinzufügen");

     insert_markname = (EditText)dialog.findViewById(R.id.insert_markname);
     insert_note    = (EditText)dialog.findViewById(R.id.insert_mark);
     cmd_add_mark = (Button)dialog.findViewById(R.id.cmd_add_mark);
     cmd_close_popup = (Button)dialog.findViewById(R.id.cmd_close_popup);
     date_pick = (DatePicker)dialog.findViewById(R.id.date_maturity_mark);
     seek_gewicht = (SeekBar)dialog.findViewById(R.id.seekBar_wertung);
     seek_gewicht.setOnSeekBarChangeListener(yourSeekBarListener);

     gewicht = (TextView)dialog.findViewById(R.id.txt_weight_change);
     cmd_add_mark.setOnClickListener(add_mark);
     cmd_close_popup.setOnClickListener(close_popup);


        break;
    case EDIT_MARK_DIALOG:       
        dialog = new Dialog(mark.this);

        dialog.setContentView(R.layout.dialog_context_hw_edit);
        dialog.setTitle("Note bearbeiten");

        edit_mark_name = (EditText)dialog.findViewById(R.id.edit_mark_name);
        edit_mark_mark = (EditText)dialog.findViewById(R.id.edit_mark_note);
        cmd_save_mark = (Button)dialog.findViewById(R.id.cmd_save_mark);
        cmd_close_mark = (Button)dialog.findViewById(R.id.cmd_close_mark);
        date_pick_edit = (DatePicker)dialog.findViewById(R.id.date_maturity_mark_edit);
        seek_gewichtt = (SeekBar)dialog.findViewById(R.id.seek_edit_gewicht);
        seek_gewichtt.setOnSeekBarChangeListener(yourSeekBarListener);


        edit_mark_name.setText(name);
        edit_mark_mark.setText(mark);
        seek_gewichtt.setProgress(gewicht_mark_int);

        gewicht_test = (TextView)dialog.findViewById(R.id.lololol);
        cmd_save_mark.setOnClickListener(save_mark);
        cmd_close_mark.setOnClickListener(close_popup_mark);

           break;
    }

    return dialog;
}

LogCat:第339行是seek_gewichtt.setOnSeekBarChangeListener(yourSeekBarListener);

02-07 14:52:15.718: D/dalvikvm(11876): GC_EXTERNAL_ALLOC freed 51K, 50% free 2695K/5379K, external 0K/0K, paused 33ms
02-07 14:52:15.761: D/dalvikvm(11876): GC_EXTERNAL_ALLOC freed 4K, 50% free 2698K/5379K, external 13K/523K, paused 32ms
02-07 14:52:20.097: D/dalvikvm(11876): GC_EXTERNAL_ALLOC freed 81K, 47% free 2891K/5447K, external 4220K/4230K, paused 19ms
02-07 14:52:20.113: D/AndroidRuntime(11876): Shutting down VM
02-07 14:52:20.117: W/dalvikvm(11876): threadid=1: thread exiting with uncaught exception (group=0x40235568)
02-07 14:52:20.121: E/AndroidRuntime(11876): FATAL EXCEPTION: main
02-07 14:52:20.121: E/AndroidRuntime(11876): java.lang.NullPointerException
02-07 14:52:20.121: E/AndroidRuntime(11876):    at test.marco.notenha.mark.onCreateDialog(mark.java:339)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.onCreateDialog(Activity.java:2506)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.createDialog(Activity.java:885)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.showDialog(Activity.java:2581)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.showDialog(Activity.java:2548)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at test.marco.notenha.mark.onContextItemSelected(mark.java:255)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.onMenuItemSelected(Activity.java:2233)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2888)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:857)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:138)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.app.AlertController$AlertParams$5.onItemClick(AlertController.java:928)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.widget.ListView.performItemClick(ListView.java:3535)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1827)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.os.Handler.handleCallback(Handler.java:587)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.os.Looper.loop(Looper.java:130)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.ActivityThread.main(ActivityThread.java:3703)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at java.lang.reflect.Method.invokeNative(Native Method)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at java.lang.reflect.Method.invoke(Method.java:507)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at dalvik.system.NativeStart.main(Native Method)
02-07 14:52:21.484: I/Process(11876): Sending signal. PID: 11876 SIG: 9

I have following Codes and my seekbar is crashing by a nullpoint exeption.
In my last question Why is my dialog seekbar crashing I coudn't find informations to solve my problem.

Here Codes:

dialog_context_mark_edit:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/edit_mark_dialog"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name" />

    <EditText
        android:id="@+id/edit_mark_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/lololol"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"/>

    <SeekBar
        android:id="@+id/seek_edit_gewicht"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Note" />

    <EditText
        android:id="@+id/edit_mark_note"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Datum" />

    <DatePicker
        android:id="@+id/date_maturity_mark_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dip"
        android:orientation="horizontal" >

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

        <Button
            android:id="@+id/cmd_close_mark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/close" />
    </LinearLayout>

</LinearLayout>

class mark:

SeekBar seekBar_wertung, seek_edit_gewicht, seek_gewicht, seek_gewichtt;
TextView gewicht, gewicht_test;

OnSeekBarChangeListener yourSeekBarListener = new OnSeekBarChangeListener() {

public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
    // TODO Auto-generated method stub

    // change progress text label with current seekbar value
    gewicht_test.setText(progress+"%");
    // change action text label to changing
}

public void onStartTrackingTouch(SeekBar seekBar) {
}

public void onStopTrackingTouch(SeekBar seekBar) {
    seekBar.setSecondaryProgress(seekBar.getProgress());
}

};

Dialog:

@Override
protected Dialog onCreateDialog(int id) {
 Dialog dialog = null;;
    switch(id) {
    case ADD_MARK_DIALOG:
     dialog = new Dialog(mark.this);

     dialog.setContentView(R.layout.dialog_context_mark);
     dialog.setTitle("Note hinzufügen");

     insert_markname = (EditText)dialog.findViewById(R.id.insert_markname);
     insert_note    = (EditText)dialog.findViewById(R.id.insert_mark);
     cmd_add_mark = (Button)dialog.findViewById(R.id.cmd_add_mark);
     cmd_close_popup = (Button)dialog.findViewById(R.id.cmd_close_popup);
     date_pick = (DatePicker)dialog.findViewById(R.id.date_maturity_mark);
     seek_gewicht = (SeekBar)dialog.findViewById(R.id.seekBar_wertung);
     seek_gewicht.setOnSeekBarChangeListener(yourSeekBarListener);

     gewicht = (TextView)dialog.findViewById(R.id.txt_weight_change);
     cmd_add_mark.setOnClickListener(add_mark);
     cmd_close_popup.setOnClickListener(close_popup);


        break;
    case EDIT_MARK_DIALOG:       
        dialog = new Dialog(mark.this);

        dialog.setContentView(R.layout.dialog_context_hw_edit);
        dialog.setTitle("Note bearbeiten");

        edit_mark_name = (EditText)dialog.findViewById(R.id.edit_mark_name);
        edit_mark_mark = (EditText)dialog.findViewById(R.id.edit_mark_note);
        cmd_save_mark = (Button)dialog.findViewById(R.id.cmd_save_mark);
        cmd_close_mark = (Button)dialog.findViewById(R.id.cmd_close_mark);
        date_pick_edit = (DatePicker)dialog.findViewById(R.id.date_maturity_mark_edit);
        seek_gewichtt = (SeekBar)dialog.findViewById(R.id.seek_edit_gewicht);
        seek_gewichtt.setOnSeekBarChangeListener(yourSeekBarListener);


        edit_mark_name.setText(name);
        edit_mark_mark.setText(mark);
        seek_gewichtt.setProgress(gewicht_mark_int);

        gewicht_test = (TextView)dialog.findViewById(R.id.lololol);
        cmd_save_mark.setOnClickListener(save_mark);
        cmd_close_mark.setOnClickListener(close_popup_mark);

           break;
    }

    return dialog;
}

LogCat: Line 339 is seek_gewichtt.setOnSeekBarChangeListener(yourSeekBarListener);

02-07 14:52:15.718: D/dalvikvm(11876): GC_EXTERNAL_ALLOC freed 51K, 50% free 2695K/5379K, external 0K/0K, paused 33ms
02-07 14:52:15.761: D/dalvikvm(11876): GC_EXTERNAL_ALLOC freed 4K, 50% free 2698K/5379K, external 13K/523K, paused 32ms
02-07 14:52:20.097: D/dalvikvm(11876): GC_EXTERNAL_ALLOC freed 81K, 47% free 2891K/5447K, external 4220K/4230K, paused 19ms
02-07 14:52:20.113: D/AndroidRuntime(11876): Shutting down VM
02-07 14:52:20.117: W/dalvikvm(11876): threadid=1: thread exiting with uncaught exception (group=0x40235568)
02-07 14:52:20.121: E/AndroidRuntime(11876): FATAL EXCEPTION: main
02-07 14:52:20.121: E/AndroidRuntime(11876): java.lang.NullPointerException
02-07 14:52:20.121: E/AndroidRuntime(11876):    at test.marco.notenha.mark.onCreateDialog(mark.java:339)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.onCreateDialog(Activity.java:2506)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.createDialog(Activity.java:885)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.showDialog(Activity.java:2581)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.showDialog(Activity.java:2548)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at test.marco.notenha.mark.onContextItemSelected(mark.java:255)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.Activity.onMenuItemSelected(Activity.java:2233)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2888)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:857)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:138)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.app.AlertController$AlertParams$5.onItemClick(AlertController.java:928)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.widget.ListView.performItemClick(ListView.java:3535)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1827)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.os.Handler.handleCallback(Handler.java:587)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.os.Looper.loop(Looper.java:130)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at android.app.ActivityThread.main(ActivityThread.java:3703)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at java.lang.reflect.Method.invokeNative(Native Method)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at java.lang.reflect.Method.invoke(Method.java:507)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-07 14:52:20.121: E/AndroidRuntime(11876):    at dalvik.system.NativeStart.main(Native Method)
02-07 14:52:21.484: I/Process(11876): Sending signal. PID: 11876 SIG: 9

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末蓝 2025-01-10 05:49:24

您的 SeekBar 使用了错误的 ID。在您的 XML 中,它被定义为 seek_edit_gewicht,但您正在寻找 R.id.seekBar_wertung。试试这个:

seek_gewicht = (SeekBar)dialog.findViewById(R.id.seek_edit_gewicht);

You're using the wrong ID for your SeekBar. In your XML it's defined as seek_edit_gewicht but you're looking for R.id.seekBar_wertung. Try this:

seek_gewicht = (SeekBar)dialog.findViewById(R.id.seek_edit_gewicht);
面如桃花 2025-01-10 05:49:24

我不明白什么。您将显示 dialog_context_mark_edit 文件中定义的布局。

但在您的对话框中,您使用 R.layout.dialog_context_mark 和 R.layout.dialog_context_hw_edit 。您能为我们提供dialog_context_mark 和dialog_context_hw_edit 文件吗?你能插入整个标记类代码吗?

I did not understand something. You show the layout that is defined in the dialog_context_mark_edit file.

But in your dialogs you use R.layout.dialog_context_mark and R.layout.dialog_context_hw_edit. Can you provide us with files dialog_context_mark and dialog_context_hw_edit? And can you insert whole mark class code?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文