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 8025937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:19:39+00:00 2026-06-04T23:19:39+00:00

Possible Duplicate: nullpointer exception raises when i click on the button case R.id.Button01check: startActivity(new

  • 0

Possible Duplicate:
nullpointer exception raises when i click on the button

case R.id.Button01check:
            startActivity(new Intent (SaveData.this,CheckData.class));
            break;  

this is my CheckData.java

 public class CheckData extends ListActivity  {     
TextView selection;
DataManipulator dm;
private DataManipulator DataManipulator;

    protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.check);
    dm = new DataManipulator(this);

    LinearLayout layout = new LinearLayout(this);
    ImageView image = new ImageView(this);
    DataManipulator = new DataManipulator(this);

    Certificates testCertificates = new Certificates(BitmapFactory.decodeFile(Context.STORAGE_SERVICE));

    DataManipulator.open();
    DataManipulator.createCertificatesEntry( (Certificates) testCertificates);
    DataManipulator.close(); 

    testCertificates = null;

    DataManipulator.open();
    testCertificates = DataManipulator.getFirstCertificatesFromDB();
    DataManipulator.close();

    image.setImageBitmap(((Certificates) testCertificates).getBitmap());

    setContentView(layout);
}

}
this is line 29 DataManipulator.createCertificatesEntry( (Certificates) testCertificates);

this is my DataManipulator.java

    public class DataManipulator {
public static final String KEY_IMG = "image";

 private DatabaseHelper mDbHelper;
    private SQLiteDatabase mDb;

    private static final String DATABASE_NAME = "DBtest";
    private static final int DATABASE_VERSION = 1;

    private static final String CERTIFICATES_TABLE = "certificates";

    private static final String CREATE_CERTIFICATES_TABLE = "create table "+CERTIFICATES_TABLE+" (" +KEY_IMG+" blob not null) ";

    private final Context mCtx;
    private static class DatabaseHelper extends SQLiteOpenHelper {
        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        public void onCreate(SQLiteDatabase db) {
            db.execSQL(CREATE_CERTIFICATES_TABLE);
        }

        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS "+CERTIFICATES_TABLE);
            onCreate(db);
        }
    }
    public void Reset() { mDbHelper.onUpgrade(this.mDb, 1, 1); }

    public DataManipulator(Context ctx) {
        mCtx = ctx;
        mDbHelper = new DatabaseHelper(mCtx);
    }

    public DataManipulator open() throws SQLException {
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }

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

    public void createCertificatesEntry(Certificates certificates) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        certificates.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, out);
        ContentValues cv = new ContentValues();
        cv.put(KEY_IMG, out.toByteArray());
        mDb.insert(CERTIFICATES_TABLE,  null, cv);
    }
    public Certificates getFirstCertificatesFromDB() throws SQLException {
        Cursor cur = mDb.query(true, CERTIFICATES_TABLE,  new String[] {KEY_IMG}, null, null, null, null, null, null);
        if(cur.moveToFirst()) {
            byte[] blob = cur.getBlob(cur.getColumnIndex(KEY_IMG));
            ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            cur.close();
            return new Certificates(bitmap);
        }
        cur.close();
        return null;
    }    
}

this is line 60 certificates.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, out);

this is my logcat output

06-04 11:09:41.824: E/AndroidRuntime(693): FATAL EXCEPTION: main
06-04 11:09:41.824: E/AndroidRuntime(693): java.lang.RuntimeException: Unable to start activity ComponentInfo{list.certificates/list.certificates.CheckData}: java.lang.NullPointerException
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.os.Looper.loop(Looper.java:137)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.app.ActivityThread.main(ActivityThread.java:4340)
06-04 11:09:41.824: E/AndroidRuntime(693):  at java.lang.reflect.Method.invokeNative(Native Method)
06-04 11:09:41.824: E/AndroidRuntime(693):  at java.lang.reflect.Method.invoke(Method.java:511)
06-04 11:09:41.824: E/AndroidRuntime(693):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-04 11:09:41.824: E/AndroidRuntime(693):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-04 11:09:41.824: E/AndroidRuntime(693):  at dalvik.system.NativeStart.main(Native Method)
06-04 11:09:41.824: E/AndroidRuntime(693): Caused by: java.lang.NullPointerException
06-04 11:09:41.824: E/AndroidRuntime(693):  at list.certificates.DataManipulator.createCertificatesEntry(DataManipulator.java:60)
06-04 11:09:41.824: E/AndroidRuntime(693):  at list.certificates.CheckData.onCreate(CheckData.java:29)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.app.Activity.performCreate(Activity.java:4465)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-04 11:09:41.824: E/AndroidRuntime(693):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
06-04 11:09:41.824: E/AndroidRuntime(693):  ... 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-04T23:19:41+00:00Added an answer on June 4, 2026 at 11:19 pm

    In your case…all I can say either your certificates variable or certificates.getBitmap() api is returning null.

    Certificates testCertificates = new Certificates(BitmapFactory.decodeFile(Context.STORAGE_SERVICE));
    

    In above code decodeFile needs the complete path to the image. What you passing is not a complete path to the file. So from the above two cases certificates.getBitmap() is most probable cause of the exception. Context.STORAGE_SERVICE is not the full path to image.

    Once you have the Uri for the image. Use the below code to get the image:

    Bitmap bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
    
    Certificates testCertificates = new Certificates(bmp);
    
    DataManipulator.open();
    DataManipulator.createCertificatesEntry( (Certificates) testCertificates);
    DataManipulator.close(); 
    

    Ref:

    Images MediaStore

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

Sidebar

Related Questions

Possible Duplicate: oracle PL/SQL: sort rows I run this query: Select a.product, sum( case
Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
Possible Duplicate: When do you use the “this” keyword? Hello, I understand that the
Possible Duplicate: Why do I get a null pointer exception from TabWidget? I have
Possible Duplicate: Direct casting vs 'as' operator? as doesn't throw an exception, but wouldn't
Possible Duplicate: how to use foursquare API in android application? This is a question
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: How to distinguish between left and right mouse click with jQuery? On
Possible Duplicate: Java resource as file I am kind of new to Java and

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.