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

  • SEARCH
  • Home
  • 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 8011577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:03:28+00:00 2026-06-04T19:03:28+00:00

I have stored an image path in the string selectedImagePath. Now I want to

  • 0

I have stored an image path in the string selectedImagePath. Now I want to store this string in a SQL Database. Therefore I have created another class, the ImageAdapter.

Can you please look at the code and tell me why the code always crashes when I try to save the string?

This is my onActivityResult method were I were I retrieve the image path and store it in the string selectedImagePath:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == PICK_FROM_FILE) {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);

            Log.v("IMAGE PATH====>>>> ",selectedImagePath);

            // Save the image path to the database
            long id = mImageHelper.createImage(selectedImagePath);
            if (id > 0) {
                id = mImageRowId;
            }
        }
    }
}

And here is my Database helper, the ImageAdapter:

public class ImageAdapter {

//
// Database Related Constants
//
private static final String DATABASE_NAME = "dataImage";
private static final String DATABASE_TABLE = "remindersImage";
private static final int DATABASE_VERSION = 4;

public static final String KEY_IMAGE = "image";
public static final String KEY_ROWID = "_id";


private static final String TAG = "ImageAdapter";
private DatabaseHelper mImageHelper;
private SQLiteDatabase mImageDb;

/**
 * Database creation SQL statement
 */
private static final String DATABASE_CREATE =
    "create table " + DATABASE_TABLE + " ("
            + KEY_ROWID + " integer primary key autoincrement, "
            + KEY_IMAGE + " text not null)"; 



private final Context mImageCtx;

private static class DatabaseHelper extends SQLiteOpenHelper {

    DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(DATABASE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
        onCreate(db);
    }
}

/**
 * Constructor - takes the context to allow the database to be
 * opened/created
 * 
 * @param ctx the Context within which to work
 */
public ImageAdapter(Context ctx) {
    this.mImageCtx = ctx;
}

/**
 * Open the database. If it cannot be opened, try to create a new
 * instance of the database. If it cannot be created, throw an exception to
 * signal the failure
 * 
 * @return this (self reference, allowing this to be chained in an
 *         initialization call)
 * @throws SQLException if the database could be neither opened or created
 */
public ImageAdapter open() throws SQLException {
    mImageHelper = new DatabaseHelper(mImageCtx);
    mImageDb = mImageHelper.getWritableDatabase();
    return this;
}

public void close() {
    mImageHelper.close();
}



public long createImage(String selectedImagePath) {
    ContentValues cv = new ContentValues();
    cv.put(KEY_IMAGE, selectedImagePath);

    return mImageDb.insert(DATABASE_TABLE, null, cv);
}


public boolean deleteImage(long rowId) {

    return mImageDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
}


public Cursor fetchAllImages() {

    return mImageDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_IMAGE}, null, null, null, null, null);
}


public Cursor fetchImage(long rowId) throws SQLException {

    Cursor mCursor =

            mImageDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                    KEY_IMAGE}, KEY_ROWID + "=" + rowId, null,
                    null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;

}


public boolean updateImage(long rowId, String image) {
    ContentValues args = new ContentValues();
    args.put(KEY_IMAGE, image);

    return mImageDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
}
}

UPDATE: Here is my LogCat:

05-31 21:10:14.947: E/AndroidRuntime(533): FATAL EXCEPTION: main
05-31 21:10:14.947: E/AndroidRuntime(533): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://media/external/images/media/22 }} to activity {com.xyz.android.taskreminder/com.xyz.android.taskreminder.ReminderEditActivity}: java.lang.NullPointerException
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2980)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.app.ActivityThread.access$1100(ActivityThread.java:123)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.os.Looper.loop(Looper.java:137)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-31 21:10:14.947: E/AndroidRuntime(533):  at java.lang.reflect.Method.invokeNative(Native Method)
05-31 21:10:14.947: E/AndroidRuntime(533):  at java.lang.reflect.Method.invoke(Method.java:511)
05-31 21:10:14.947: E/AndroidRuntime(533):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-31 21:10:14.947: E/AndroidRuntime(533):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-31 21:10:14.947: E/AndroidRuntime(533):  at dalvik.system.NativeStart.main(Native Method)
05-31 21:10:14.947: E/AndroidRuntime(533): Caused by: java.lang.NullPointerException
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:290)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:115)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1591)
05-31 21:10:14.947: E/AndroidRuntime(533):  at com.xyz.android.taskreminder.ImageAdapter.createImage(ImageAdapter.java:114)
05-31 21:10:14.947: E/AndroidRuntime(533):  at com.xyz.android.taskreminder.ReminderEditActivity.onActivityResult(ReminderEditActivity.java:233)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.app.Activity.dispatchActivityResult(Activity.java:4649)
05-31 21:10:14.947: E/AndroidRuntime(533):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
05-31 21:10:14.947: E/AndroidRuntime(533):  ... 11 more
  • 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-04T19:03:30+00:00Added an answer on June 4, 2026 at 7:03 pm

    First, lets clean up some code 🙂

    Change this

    private static final String DATABASE_CREATE =
    "create table " + DATABASE_TABLE + " ("
            + KEY_ROWID + " integer primary key autoincrement, "
            + KEY_IMAGE + " text not null)"; 
    

    to

    private static final String DATABASE_CREATE =
    "create table if not exists " + DATABASE_TABLE + " ("
            + KEY_ROWID + " integer primary key autoincrement, "
            + KEY_IMAGE + " text not null)"; 
    

    Now, uninstall the app or clear data, so that any previously created databases gets deleted. Try your app, and post results. Please also post the result from this line:

    Log.v("IMAGE PATH====>>>> ", selectedImagePath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some image path stored in database and I have to show the
I have got a an image path stored in a string: if(uri != null)
I have an image that is uploaded and stored on server. I now want
I have stored images from the net like this Documents/imagecache/domain1/original/path/inURI/foo.png Documents/imagecache/domain2/original/path/inURI/bar.png Documents/imagecache/... Documents/imagecache/... Now
I have currently got imagepaths stored within the database and image files stored in
For example, I want to zip a file stored in /Users/me/Desktop/image.jpg I made this
I have this function to store the bmp image in a desired location as
I have a image stored in SD card of my phone. I want to
I currently have a varchar(255) column that stores the path to a small image
<input src=LOGO.JPG type=image name=imagem> I have an xml element that contains the image path

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.