Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:37:41+00:00 2026-06-04T20:37:41+00:00

When clicking on an image button in my app I always get the message:

  • 0

When clicking on an image button in my app I always get the message: “unfortunately myapp has stopped”. What is the problem???

Here is my code. The showImageDialog method is called on a click on an image button:

public class ReminderEditActivity extends Activity {

//
// Private instance variables
//
private Button mDateButton;
private Calendar mCalendar;
private Button mTimeButton;
private EditText mTitleText;
private EditText mBodyText;
private Button mConfirmButton;

private RemindersDbAdapter mDbHelper;
private ImageAdapter mImageHelper;

private Long mRowId;
private Long mImageRowId;

private ImageButton mImageButton;

private Uri mImageCaptureUri;

public String imageFilePath;


//
// Private constants
//
private static final int DATE_PICKER_DIALOG = 0;
private static final int TIME_PICKER_DIALOG = 1;
private static final String DATE_FORMAT = "dd-MM-yyyy";
private static final String TIME_FORMAT = "kk:mm";

public static final String DATE_TIME_FORMAT = "dd-MM-yyyy kk:mm:ss";

private static final int PICK_FROM_CAMERA = 1;
private static final int PICK_FROM_FILE = 2;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Instantiate mDbHelper and mImageHelper
    mDbHelper = new RemindersDbAdapter(this);
    mImageHelper = new ImageAdapter(this);

    setContentView(R.layout.reminder_edit);

    //
    // Instantiate instance variables
    //
    mTimeButton = (Button)findViewById(R.id.reminder_time);
    mCalendar = Calendar.getInstance();
    mDateButton = (Button)findViewById(R.id.reminder_date);
    mConfirmButton = (Button)findViewById(R.id.confirm);
    mTitleText = (EditText)findViewById(R.id.title);
    mBodyText = (EditText)findViewById(R.id.body);

    mImageButton =(ImageButton)findViewById(R.id.image);

    //Checks whether mRowId contains any values.
    mRowId = savedInstanceState != null ? savedInstanceState.getLong(RemindersDbAdapter.KEY_ROWID) : null;
    mImageRowId = savedInstanceState != null ? savedInstanceState.getLong(ImageAdapter.KEY_ROWID) : null;

    registerButtonListenerandSetDefaultText();
}

//
// Sets the row id from the intent. If mRowId is null its content is null.
//
private void setRowIdFromIntent() {
    if(mRowId == null) {
        Bundle extras = getIntent().getExtras();
        mRowId = extras != null ? extras.getLong(RemindersDbAdapter.KEY_ROWID) : null;
    }
}

//
// Executed on pause.
//
@Override
protected void onPause() {
    super.onPause();
    mDbHelper.close();
    mImageHelper.close();
}

//
// Executed on resume
//
@Override
protected void onResume() {
    super.onResume();
    mDbHelper.open();
    mImageHelper.open();
    setRowIdFromIntent();
    populateFields();
    populateImageField();
}

//
// Register the Date, Time and Save Button and set the default text
//
private void registerButtonListenerandSetDefaultText() {

    mDateButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(DATE_PICKER_DIALOG); 
        }
    });

    mTimeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(TIME_PICKER_DIALOG);
        }
    });

    mConfirmButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            saveState();
            setResult(RESULT_OK);
            Toast.makeText(ReminderEditActivity.this, getString(R.string.task_saved_message), Toast.LENGTH_SHORT).show();
            finish();
        }
    }); 

    mImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showImageDialog();
        }
    });

    updateDateButtonText();
    updateTimeButtonText(); 
}


private void showImageDialog() {
    final String [] items = new String [] {"From Camera", "From SD Card"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.select_dialog_item,items);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Select Image");
    builder.setAdapter( adapter, new DialogInterface.OnClickListener() {
        public void onClick( DialogInterface dialog, int item ) {
            if (item == 0) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File file = new File(Environment.getExternalStorageDirectory(),
                                    "tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
                mImageCaptureUri = Uri.fromFile(file);

                try {
                    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
                    intent.putExtra("return-data", true);

                    startActivityForResult(intent, PICK_FROM_CAMERA);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                dialog.cancel();
            } else {
                Intent intent = new Intent();

                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);

                startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
            }
        }
    } );

    final AlertDialog dialog = builder.create();
    dialog.show();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       if(requestCode == PICK_FROM_FILE && data != null && data.getData() != null) {
           Uri uri = data.getData();
           if(uri != null) {
              Cursor cursor = getContentResolver().query(uri, new String[] {   
                                       android.provider.MediaStore.Images.ImageColumns.DATA}, 
                                       null, null, null);
                    cursor.moveToFirst();
                    String imageFilePath = cursor.getString(0);             
                    cursor.close();

                    if(imageFilePath != null) {
                            // Do whatever you want like decode it into a Bitmap
                            Bitmap bitmap = BitmapFactory.decodeFile(imageFilePath);
                            mImageButton.setImageBitmap(bitmap);
                            // Or.. store it somewhere in your local db  
                        }
           }
       }
    }


//
// If mRowId is not null (it contains value and we want to edit the task)
// this method is called.
//
private void populateFields() {
    if (mRowId != null) {
        Cursor reminder = mDbHelper.fetchReminder(mRowId);
        startManagingCursor(reminder);
        mTitleText.setText(reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_TITLE)));
        mBodyText.setText(reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_BODY)));


        SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
        Date date = null;
        try {
            String dateString = reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_DATE_TIME));
            date = dateTimeFormat.parse(dateString);
            mCalendar.setTime(date);
        } catch (ParseException e) {
            Log.e("ReminderEditActivity", e.getMessage(), e);
        }
    } 

    updateDateButtonText();
    updateTimeButtonText();
}

private void populateImageField() {
    if (mImageRowId != null) {
        Cursor reminderImage = mImageHelper.fetchReminder(mImageRowId);
        startManagingCursor(reminderImage);
        String imagePath = reminderImage.getString(reminderImage.getColumnIndexOrThrow(ImageAdapter.KEY_IMAGE));

        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        mImageButton.setImageBitmap(bitmap);

    }
}


//
// Saves the state so that it can be restored.
//
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putLong(RemindersDbAdapter.KEY_ROWID, mRowId);

}

//
// Saves the content by communicating with the RemindersDbAdapter.
//
private void saveState() {
    String title = mTitleText.getText().toString();
    String body = mBodyText.getText().toString();

    SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
    String reminderDateTime = dateTimeFormat.format(mCalendar.getTime());

    // Creates a new reminder if the value is null.
    if (mRowId == null) {
        long id = mDbHelper.createReminder(title, body, reminderDateTime);
        if (id > 0) {
            mRowId = id;

        } 
    // Updates the reminder if the content is not null.     
    } else {
        mDbHelper.updateReminder(mRowId, title, body, reminderDateTime);
    }
}

//
// Opens up an alert dialog box and asks the user if he wants to discard his task.
//
@Override
public void onBackPressed() {
    AlertDialog.Builder builder = new AlertDialog.Builder(ReminderEditActivity.this);
    builder.setMessage("Are you sure you want to discard your task?");
            builder.setTitle("Are you sure?");
            builder.setCancelable(false);
            builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    Intent j = new Intent(((Dialog)dialog).getContext(), ReminderListActivity.class);
                    startActivity(j);
                    return;

                }
            });

            builder.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();

                }
            });
            builder.create().show();        
}

//
// When creating a dialog box, it either shows up a date or time picker.
//
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case DATE_PICKER_DIALOG:
            return showDatePicker();
        case TIME_PICKER_DIALOG:
            return showTimePicker();
    }
    return super.onCreateDialog(id);
}

//
// Creates the date picker dialog box.
//
private DatePickerDialog showDatePicker() {
    DatePickerDialog datePicker = new DatePickerDialog(ReminderEditActivity.this, new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mCalendar.set(Calendar.YEAR, year);
            mCalendar.set(Calendar.MONTH, monthOfYear);
            mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            updateDateButtonText();
        }
    }, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
    return datePicker;
}

//
// Creates the time picker dialog box.
//
private TimePickerDialog showTimePicker() {
    TimePickerDialog timePicker = new TimePickerDialog(ReminderEditActivity.this, new TimePickerDialog.OnTimeSetListener() {

        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            mCalendar.set(Calendar.MINUTE, minute);
            updateTimeButtonText();
        }
    }, mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE), true);
    return timePicker;
}

//
// Updates the Date Button text.
//
private void updateDateButtonText() {
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    String dateForButton = dateFormat.format(mCalendar.getTime());
    mDateButton.setText(dateForButton);
}

//
// Updates the Time Button text.
//
private void updateTimeButtonText() {
    SimpleDateFormat timeFormat = new SimpleDateFormat(TIME_FORMAT);
    String timeForButton = timeFormat.format(mCalendar.getTime());
    mTimeButton.setText(timeForButton);
}

}

Here is the LogCat:

05-30 22:09:06.726: E/AndroidRuntime(628): FATAL EXCEPTION: main
05-30 22:09:06.726: E/AndroidRuntime(628): java.lang.RuntimeException: Unable to pause activity {com.ndroidstudios.android.taskreminder/com.ndroidstudios.android.taskreminder.ReminderEditActivity}: java.lang.NullPointerException
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2706)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2662)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2640)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.ActivityThread.access$800(ActivityThread.java:123)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1154)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.os.Looper.loop(Looper.java:137)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-30 22:09:06.726: E/AndroidRuntime(628):  at java.lang.reflect.Method.invokeNative(Native Method)
05-30 22:09:06.726: E/AndroidRuntime(628):  at java.lang.reflect.Method.invoke(Method.java:511)
05-30 22:09:06.726: E/AndroidRuntime(628):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-30 22:09:06.726: E/AndroidRuntime(628):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-30 22:09:06.726: E/AndroidRuntime(628):  at dalvik.system.NativeStart.main(Native Method)
05-30 22:09:06.726: E/AndroidRuntime(628): Caused by: java.lang.NullPointerException
05-30 22:09:06.726: E/AndroidRuntime(628):  at com.ndroidstudios.android.taskreminder.ReminderEditActivity.onSaveInstanceState(ReminderEditActivity.java:345)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.Activity.performSaveInstanceState(Activity.java:1113)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1185)
05-30 22:09:06.726: E/AndroidRuntime(628):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2688)
05-30 22:09:06.726: E/AndroidRuntime(628):  ... 12 more

And here is my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ndroidstudios.android.taskreminder"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".ReminderListActivity"
        android:label="@string/app_name"
        android:configChanges="orientation|keyboardHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".ReminderEditActivity"
        android:label="@string/app_name" />
    <activity 
        android:name=".ImageAdapter"
        android:label="@string/app_name" />    
</application>

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:37:42+00:00Added an answer on June 4, 2026 at 8:37 pm

    ReminderEditActivity at line 345 has a null object. Im not sure which line it is in your code cause theres no line numbers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i stop progress bar gif image when i stopped processing by clicking
So, I'm building a little app that has 118 buttons for clicking. It is
I need to swap the image while clicking the div tag Here is my
I have a webpage and a F-Share button. On clicking this button, an image
I have 3 activities. 1st activity has a 'go right' image button. (to move
The code below compiles but after clicking on first button it breaks with msg
Update progress not working.The code is given below,When i am clicking on any button
I made an app which plays the song on clicking on the image of
Clicking on the image should show div near it (.show() in jQuery). But how
I'm trying to call javascript by clicking on the image but it's not working.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.