Search code examples
androidcrashnullpointerexceptionseekbar

I have again a NullPointerException from seekbar in android


Why do I have a NullPointerException here? I checked my code for 5 times... When I install my app on my Galaxy S it works. But when I rebuild it without changing the code it crashes. Could you explain me why? Thanks in advance!

Codesnippets:

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" >


    <TextView
        android:id="@+id/txt_Pruefung"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Prüfungsname" />

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

    <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" />

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

    <EditText
        android:id="@+id/insert_mark"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal" >
        <requestFocus />
    </EditText>

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

    <DatePicker
        android:id="@+id/date_maturity_mark"
        android:layout_width="wrap_content"
        android:layout_height="75dp" />

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

        <Button
            android:id="@+id/cmd_add_mark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Note hinzufügen" />

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

dialog_context_mark_edit.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" >


    <TextView
        android:id="@+id/txt_Pruefung"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Prüfungsname" />

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

    <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" />

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

    <EditText
        android:id="@+id/insert_mark"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal" >
        <requestFocus />
    </EditText>

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

    <DatePicker
        android:id="@+id/date_maturity_mark"
        android:layout_width="wrap_content"
        android:layout_height="75dp" />

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

        <Button
            android:id="@+id/cmd_add_mark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Note hinzufügen" />

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

Some snippets from mark.java

static final int ADD_MARK_DIALOG = 0;
static final int EDIT_MARK_DIALOG = 1;
final int CONTEXT_MENU_DELETE_ITEM =1;
final int CONTEXT_MENU_EDIT_ITEM =2;
SeekBar seekBar_wertung, seek_edit_gewicht, seek_gewicht, seek_gewichtt;

TextView gewicht, txt_durchschnitt;

String mark, gewicht_mark, name, id_edit, teststring, txt_edit_mark_name, txt_edit_mark_mark, txt_edit_weigh_trim;
EditText insert_markname, edit_mark_name, insert_note, edit_mark_mark;
Button cmd_add_mark, cmd_close_popup, cmd_save_mark, cmd_close_mark;
int progress, gewicht_mark_int;

OnSeekBarChangeListener yourSeekBarListener = new OnSeekBarChangeListener() {

public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
    gewicht.setText(progress+"%");
}

public void onStartTrackingTouch(SeekBar seekBar) {
}

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

};

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_mark_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 = (TextView)dialog.findViewById(R.id.gewicht);
        gewicht.setText(""+gewicht_mark);
        cmd_save_mark.setOnClickListener(save_mark);
        cmd_close_mark.setOnClickListener(close_popup_mark);

           break;
    }

    return dialog;
}

LogCat:

Line 83: gewicht.setText(progress+"%");

Line 90: seekBar.setSecondaryProgress(seekBar.getProgress());

Line 359: seek_gewichtt.setProgress(gewicht_mark_int);

02-08 09:44:00.582: D/dalvikvm(7476): GC_EXTERNAL_ALLOC freed 87K, 48% free 2903K/5511K, external 4228K/4230K, paused 21ms
02-08 09:44:00.617: D/AndroidRuntime(7476): Shutting down VM
02-08 09:44:00.617: W/dalvikvm(7476): threadid=1: thread exiting with uncaught exception (group=0x4022f568)
02-08 09:44:00.625: E/AndroidRuntime(7476): FATAL EXCEPTION: main
02-08 09:44:00.625: E/AndroidRuntime(7476): java.lang.NullPointerException
02-08 09:44:00.625: E/AndroidRuntime(7476):     at test.marco.notenha.mark$1.onProgressChanged(mark.java:83)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.SeekBar.onProgressRefresh(SeekBar.java:90)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:544)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:523)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.ProgressBar.refreshProgress(ProgressBar.java:558)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.ProgressBar.setProgress(ProgressBar.java:607)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.ProgressBar.setProgress(ProgressBar.java:588)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at test.marco.notenha.mark.onCreateDialog(mark.java:359)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.app.Activity.onCreateDialog(Activity.java:2506)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.app.Activity.createDialog(Activity.java:885)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.app.Activity.showDialog(Activity.java:2581)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.app.Activity.showDialog(Activity.java:2548)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at test.marco.notenha.mark.onContextItemSelected(mark.java:257)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.app.Activity.onMenuItemSelected(Activity.java:2233)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2888)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:857)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:138)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at com.android.internal.app.AlertController$AlertParams$5.onItemClick(AlertController.java:928)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.ListView.performItemClick(ListView.java:3535)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1827)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.os.Handler.handleCallback(Handler.java:587)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.os.Looper.loop(Looper.java:130)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at android.app.ActivityThread.main(ActivityThread.java:3703)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at java.lang.reflect.Method.invokeNative(Native Method)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at java.lang.reflect.Method.invoke(Method.java:507)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-08 09:44:00.625: E/AndroidRuntime(7476):     at dalvik.system.NativeStart.main(Native Method)

FULL mark.java

public class mark extends ListActivity{
    /** Called when the activity is first created. */

    SQLiteDatabase db;
    private dbHelper mDbHelper;
    static final int ADD_MARK_DIALOG = 0;
    static final int EDIT_MARK_DIALOG = 1;
    final int CONTEXT_MENU_DELETE_ITEM =2;
    final int CONTEXT_MENU_EDIT_ITEM =3;
    SeekBar seekBar_wertung, seek_edit_gewicht, seek_gewicht, seek_gewichtt;
    TextView gewicht, gewicht_test, txt_durchschnitt;

    float zahl1, zahl2, result;
    String mark, gewicht_mark, name, id_edit, teststring, txt_edit_mark_name, txt_edit_mark_mark, txt_edit_weigh_trim;
    EditText insert_markname, edit_mark_name, insert_note, edit_mark_mark;
    Button cmd_add_mark, cmd_close_popup, cmd_save_mark, cmd_close_mark;
    DatePicker date_pick, date_pick_edit;
    int progress, gewicht_mark_int;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mark);

        //Create Database if necessary
        db = openOrCreateDatabase("test_database.db", 
                SQLiteDatabase.CREATE_IF_NECESSARY, null);

        db.setVersion(1);
        db.setLocale(Locale.getDefault());
        db.setLockingEnabled(true);

        //Create table tbl_homework if not exists
        final String CREATE_TABLE_HW =
                "CREATE TABLE IF NOT EXISTS tbl_marks ("
                + "_id INTEGER PRIMARY KEY AUTOINCREMENT,"
                + "name TEXT NOT NULL,"
                + "subid INTEGER NOT NULL,"
                + "mark FLOAT NOT NULL,"
                + "gewicht INTEGER NOT NULL,"
                + "datum TEXT NOT NULL);";

                db.execSQL(CREATE_TABLE_HW);
                mDbHelper = new dbHelper(this);
                mDbHelper.db = db;
                press_cmd_back();            
                fillData();
                registerForContextMenu(getListView());

    }

    OnSeekBarChangeListener yourSeekBarListener = new OnSeekBarChangeListener() {

    public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
        gewicht.setText(progress+"%");
    }

    public void onStartTrackingTouch(SeekBar seekBar) {
    }

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

    };

    private void press_cmd_back(){
        Button cmd_back = (Button)findViewById(R.id.cmd_back);
        cmd_back.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent Intent_main = new Intent(mark.this, subjects.class);
                startActivity(Intent_main);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_mark, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.add_mark:    
                showDialog(ADD_MARK_DIALOG);
                break;
        }
        return true;
    }

    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");

            int seek_gewicht_progress = seek_gewicht.getProgress();

            if(txt_insert_markname.equals("")){doMessage("Bitte einen Namen eintragen!");}
            if(txt_note_mark.equals("")){doMessage("Bitte eine Note eintragen!");}

            float test = Float.parseFloat(txt_note_mark);
            if(test < 1){
                doMessage("Ungültige Note");
            }

            if(test > 6){
                doMessage("Ungültige Note");
            }

                final String INSERT_MARK = "INSERT INTO tbl_marks ('name', 'subid', 'gewicht', 'mark', 'datum') VALUES ('"+txt_insert_markname+"', '"+txt_sub_id+"', '"+seek_gewicht_progress+"', '"+txt_note_mark+"', '"+date_picker_message+"')";
                db.execSQL(INSERT_MARK);
                insert_note.setText("");
                dismissDialog(ADD_MARK_DIALOG);
                fillData();


            }

    };

    public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo) {

        menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM, Menu.NONE, "Löschen");
        menu.add(Menu.NONE, CONTEXT_MENU_EDIT_ITEM, Menu.NONE, "Bearbeiten");
       } 

    private Button.OnClickListener close_popup = new Button.OnClickListener(){
        public void onClick(View arg0) {
            dismissDialog(ADD_MARK_DIALOG);
        }
    };


    private void doMessage(String message) {
        AlertDialog alertDialog = new AlertDialog.Builder(mark.this).create();
        alertDialog.setTitle("Fehler:");
        alertDialog.setMessage(message);

        alertDialog.setButton("Erneut versuchen", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        } });
        alertDialog.show();
    }

    private void fillData() {

        Bundle extras = getIntent().getExtras();
        String txt_sub_id = extras.getString("IDFach");
        int test = Integer.parseInt(txt_sub_id);

        Cursor mCursor = db.rawQuery("SELECT _id, subid, name, mark, gewicht, datum FROM tbl_marks WHERE subid = '"+test+"';", null);
        startManagingCursor(mCursor);
        if (mCursor != null && mCursor.moveToFirst()) {
             int intMark = mCursor.getColumnIndex("mark");
             int intWeight = mCursor.getColumnIndex("gewicht");
              do {

                  String[] from = new String[] { dbHelper.KEY_NAME_MARKS, dbHelper.KEY_MARK_MARKS, dbHelper.KEY_GEWICHT_MARKS, dbHelper.KEY_DATUM_MARKS};
                  int[] to = new int[] {R.id.txt_marks_row, R.id.txt_note, R.id.txt_gewicht, R.id.txt_datum};

                  float weight = mCursor.getFloat(intWeight);

                  float mark = mCursor.getFloat(intMark);

                  zahl1 = zahl1 + (weight * mark);
                  zahl2 = zahl2 + weight;
                  SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.show_marks, mCursor, from, to);
                  setListAdapter(notes);
              } while (mCursor.moveToNext());

              txt_durchschnitt = (TextView)findViewById(R.id.txt_durchschnitt);
              result = zahl1 / zahl2;
              float result_neu = (float) (Math.round(result * 100) / 100.0);

              txt_durchschnitt.setText(""+result_neu);
        }
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {

         AdapterView.AdapterContextMenuInfo info= (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
         long id = getListAdapter().getItemId(info.position); /*what item was selected is ListView*/


         switch (item.getItemId()) {
                 case CONTEXT_MENU_DELETE_ITEM:
                     mDbHelper.open_database_rw();
                     String id_delete = Long.toString(id);
                     try{
                         delItem(id_delete);
                         Toast.makeText(this, "Gelöscht!", Toast.LENGTH_SHORT).show();
                         fillData();
                     }
                     catch(SQLiteException e){
                         Toast.makeText(this, "Nicht gelöscht!", Toast.LENGTH_SHORT).show();
                     }
                     return(true);

                 case CONTEXT_MENU_EDIT_ITEM:
                     try{
                         mDbHelper.open_database_rw();
                         id_edit = Long.toString(id);

                         Cursor cursor = db.query("tbl_marks", new String[] {"name", "mark", "gewicht"}, 
                                    "_id="+id_edit, null, null, null, null);
                         startManagingCursor(cursor);

                         cursor.moveToFirst();

                         int name_mark = cursor.getColumnIndex("name");
                         name = cursor.getString(name_mark);
                         int mark_mark = cursor.getColumnIndex("mark");
                         mark = cursor.getString(mark_mark);
                         int mark_gewicht_int = cursor.getColumnIndex("gewicht");
                         gewicht_mark = cursor.getString(mark_gewicht_int);
                         gewicht_mark_int = Integer.parseInt(gewicht_mark);
                         removeDialog(EDIT_MARK_DIALOG);
                         showDialog(EDIT_MARK_DIALOG);

                         registerForContextMenu(getListView());
                         fillData();
                     }
                     catch(SQLiteException e){
                         Toast.makeText(this, "Nicht gelöscht!", Toast.LENGTH_SHORT).show();
                     }
                     return(true);
         }
     return(super.onOptionsItemSelected(item));
   } 

    public void delItem(String item){
        db.delete("tbl_marks", "_id="+item, null);
    }





    private Button.OnClickListener save_mark = new Button.OnClickListener(){
        public void onClick(View arg0) {

            String txt_edit_name = edit_mark_name.getText().toString(); 
            String date_picker_message_edit = date_pick_edit.getDayOfMonth() + "/" + (date_pick_edit.getMonth()+1) + "/" + date_pick_edit.getYear();
            String txt_edit_mark = edit_mark_mark.getText().toString(); 
            int txt_edit_weight_int = seek_gewichtt.getProgress();
            String txt_edit_weight = ""+txt_edit_weight_int;

            txt_edit_mark_mark = txt_edit_mark.trim();
            txt_edit_mark_name = txt_edit_name.trim();
            txt_edit_weigh_trim = txt_edit_weight.trim();

            ContentValues args = new ContentValues();
            args.put("name", txt_edit_mark_name);

            ContentValues args_date = new ContentValues();
            args_date.put("datum", date_picker_message_edit);

            ContentValues args_mark = new ContentValues();
            args_mark.put("mark", txt_edit_mark_mark);

            ContentValues args_weight = new ContentValues();
            args_weight.put("gewicht", txt_edit_weigh_trim);

            db.update("tbl_marks", args, "_id="+id_edit, null);
            db.update("tbl_marks", args_date, "_id="+id_edit, null);
            db.update("tbl_marks", args_mark, "_id="+id_edit, null);
            db.update("tbl_marks", args_weight, "_id="+id_edit, null);
            dismissDialog(EDIT_MARK_DIALOG);
            fillData();
        }
    };

    private Button.OnClickListener close_popup_mark = new Button.OnClickListener(){
        public void onClick(View arg0) {
            dismissDialog(EDIT_MARK_DIALOG);
        }
    };


    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_mark_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 = (TextView)dialog.findViewById(R.id.gewicht);
            gewicht.setText(""+gewicht_mark);
            cmd_save_mark.setOnClickListener(save_mark);
            cmd_close_mark.setOnClickListener(close_popup_mark);

               break;
        }

        return dialog;
    }

}

Solution

  • Typical non-initialization stuff... gewicht is null, probably not initialized.

    EDIT: You call

    onProgressChanged() (triggered when seek_gewichtt.setProgress(gewicht_mark_int);)

    before

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