¿Por qué está chocando mi Dialog Seekbar? Excepción de puntero nulo

Tengo un buscador en un diálogo y se está estrellando. Dice que hay una nullpointerexeption. ¡Pero no puedo encontrarlo! ¿Dónde está mi error? He comentado dónde está la excepción nullpointer.

dialog_context_mark.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/add_hw_dialog" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp" > <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/txt_gewicht" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Gewicht: " /> <TextView android:id="@+id/txt_weight_change" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true"/> </RelativeLayout> <SeekBar android:id="@+id/seekBar_wertung" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> 

mark.java

En Public Class mark lo definí así:

 SeekBar seek_gewicht; SeekBar seekBar_wertung; TextView gewicht; 

OnSeekBarChangeListener:

  OnSeekBarChangeListener yourSeekBarListener = new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) { // TODO Auto-generated method stub gewicht.setText(progress+"%"); } public void onStartTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) { seekBar.setSecondaryProgress(seekBar.getProgress()); } }; 

Mi Diálogo:

 @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"); seek_gewicht = (SeekBar)findViewById(R.id.seekBar_wertung); /***NULLPOINTEREXEPTION seek_gewicht.setOnSeekBarChangeListener(yourSeekBarListener); ***/ } return dialog; } private Button.OnClickListener add_mark = new Button.OnClickListener(){ public void onClick(View arg0) { mDbHelper.open_database_rw(); String txt_insert_markname = insert_markname.getText().toString(); String txt_note_mark = insert_note.getText().toString(); String date_picker_message = date_pick.getDayOfMonth() + "/" + (date_pick.getMonth()+1) + "/" + date_pick.getYear(); Bundle extras = getIntent().getExtras(); String txt_sub_id = extras.getString("IDFach"); if(txt_insert_markname.equals("")){doMessage("Bitte einen Namen eintragen!");} if(txt_note_mark.equals("")){doMessage("Bitte eine Note eintragen!");} final String INSERT_MARK = "INSERT INTO tbl_marks ('name', 'subid', 'gewicht', 'mark', 'datum') VALUES ('"+txt_insert_markname+"', '"+txt_sub_id+"', '5', '"+txt_note_mark+"', '"+date_picker_message+"')"; db.execSQL(INSERT_MARK); insert_note.setText(""); fillData(); } }; 

LogCat: (La línea 207 es seek_gewicht.setOnSeekBarChangeListener (yourSeekBarListener);)

 02-07 10:13:58.382: D/dalvikvm(9189): GC_EXTERNAL_ALLOC freed 87K, 48% free 2916K/5511K, external 4223K/4230K, paused 21ms 02-07 10:13:58.414: D/AndroidRuntime(9189): Shutting down VM 02-07 10:13:58.414: W/dalvikvm(9189): threadid=1: thread exiting with uncaught exception (group=0x40235568) 02-07 10:13:58.418: E/AndroidRuntime(9189): FATAL EXCEPTION: main 02-07 10:13:58.418: E/AndroidRuntime(9189): java.lang.NullPointerException 02-07 10:13:58.418: E/AndroidRuntime(9189): at test.marco.notenha.mark.onCreateDialog(mark.java:207) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.app.Activity.onCreateDialog(Activity.java:2506) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.app.Activity.createDialog(Activity.java:885) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.app.Activity.showDialog(Activity.java:2581) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.app.Activity.showDialog(Activity.java:2548) 02-07 10:13:58.418: E/AndroidRuntime(9189): at test.marco.notenha.mark.onOptionsItemSelected(mark.java:113) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.app.Activity.onMenuItemSelected(Activity.java:2229) 02-07 10:13:58.418: E/AndroidRuntime(9189): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:755) 02-07 10:13:58.418: E/AndroidRuntime(9189): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143) 02-07 10:13:58.418: E/AndroidRuntime(9189): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:857) 02-07 10:13:58.418: E/AndroidRuntime(9189): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532) 02-07 10:13:58.418: E/AndroidRuntime(9189): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:123) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.view.View$PerformClick.run(View.java:9130) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.os.Handler.handleCallback(Handler.java:587) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.os.Handler.dispatchMessage(Handler.java:92) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.os.Looper.loop(Looper.java:130) 02-07 10:13:58.418: E/AndroidRuntime(9189): at android.app.ActivityThread.main(ActivityThread.java:3703) 02-07 10:13:58.418: E/AndroidRuntime(9189): at java.lang.reflect.Method.invokeNative(Native Method) 02-07 10:13:58.418: E/AndroidRuntime(9189): at java.lang.reflect.Method.invoke(Method.java:507) 02-07 10:13:58.418: E/AndroidRuntime(9189): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 02-07 10:13:58.418: E/AndroidRuntime(9189): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 02-07 10:13:58.418: E/AndroidRuntime(9189): at dalvik.system.NativeStart.main(Native Method) 

LogCat al deslizar la barra: 78 es gewicht.setText (progreso + "%");

 02-07 10:18:50.312: I/Process(9235): Sending signal. PID: 9235 SIG: 9 02-07 10:18:53.625: D/dalvikvm(9247): GC_EXTERNAL_ALLOC freed 92K, 48% free 2918K/5511K, external 4223K/4230K, paused 26ms 02-07 10:18:54.668: D/AndroidRuntime(9247): Shutting down VM 02-07 10:18:54.668: W/dalvikvm(9247): threadid=1: thread exiting with uncaught exception (group=0x40235568) 02-07 10:18:54.730: E/AndroidRuntime(9247): FATAL EXCEPTION: main 02-07 10:18:54.730: E/AndroidRuntime(9247): java.lang.NullPointerException 02-07 10:18:54.730: E/AndroidRuntime(9247): at test.marco.notenha.mark$1.onProgressChanged(mark.java:78) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.widget.SeekBar.onProgressRefresh(SeekBar.java:90) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:544) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:523) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.widget.ProgressBar.refreshProgress(ProgressBar.java:558) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.widget.ProgressBar.setProgress(ProgressBar.java:607) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.widget.AbsSeekBar.trackTouchEvent(AbsSeekBar.java:368) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:313) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.view.View.dispatchTouchEvent(View.java:3886) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:875) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:875) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:875) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:875) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:875) 02-07 10:18:54.730: E/AndroidRuntime(9247): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1794) 02-07 10:18:54.730: E/AndroidRuntime(9247): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1132) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.app.Dialog.dispatchTouchEvent(Dialog.java:642) 02-07 10:18:54.730: E/AndroidRuntime(9247): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1778) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2208) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.view.ViewRoot.handleMessage(ViewRoot.java:1892) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.os.Handler.dispatchMessage(Handler.java:99) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.os.Looper.loop(Looper.java:130) 02-07 10:18:54.730: E/AndroidRuntime(9247): at android.app.ActivityThread.main(ActivityThread.java:3703) 02-07 10:18:54.730: E/AndroidRuntime(9247): at java.lang.reflect.Method.invokeNative(Native Method) 02-07 10:18:54.730: E/AndroidRuntime(9247): at java.lang.reflect.Method.invoke(Method.java:507) 02-07 10:18:54.730: E/AndroidRuntime(9247): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 02-07 10:18:54.730: E/AndroidRuntime(9247): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 02-07 10:18:54.730: E/AndroidRuntime(9247): at dalvik.system.NativeStart.main(Native Method) 

De acuerdo. Pruebe este código .. seek_gewicht = (SeekBar) dialog.findViewById(R.id.seekBar_wertung);

en lugar de

seek_gewicht = (SeekBar) findViewById(R.id.seekBar_wertung);

Para la segunda excepción . Inicialice su TextView . Igual que SeekBar .

gewicht = (TextView) dialog.findViewById(R.id.txt_gewicht);

Tienes que inicializar otros componentes también.

Prueba esto

 seek_gewicht = (SeekBar)findViewById(R.id.seekBar_wertung); 

debiera ser

 seek_gewicht = (SeekBar)dialog.findViewById(R.id.seekBar_wertung); 
  • ActionBar lanza NullPointerException
  • Intentar invocar método virtual
  • ¿Por qué se bloquea mi actividad al pulsar el botón de inicio?
  • Android proguard obfuscated código está causando NullPointerException cuando realmente no debe ser
  • Android: Pasar datos (extras) a un fragmento
  • Android - NullPointerException en SearchView en la barra de acciones
  • NullPointerException en startAnimation (anim)
  • Excepción de puntero nulo en la intención de la cámara cuando elijo una cámara de terceros
  • NullPointerExceptions sólo en algunos dispositivos Samsung Galaxy?
  • NullPointerException - Intenta obtener la longitud de la matriz null (readDirectory ())
  • NullPointerException Causado por getActionBar ()
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.