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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:28:33+00:00 2026-06-17T11:28:33+00:00

I am trying to submit details from a form to the local database on

  • 0

I am trying to submit details from a form to the local database on the device. I am getting a null pointer which seems to be occuring in this section of code. I have a feeling it might be to do with the way I am trying to get the image from the ImageView.

Any ideas?

    addContactBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(v.getContext(), "Add Contact", Toast.LENGTH_SHORT).show();
            i = new Intent(v.getContext(), ViewActivity.class);
            //Add contact to database
            dbAdapter.addContact(nameBox.getText().toString(), numberBox.getText().toString(), emailBox.getText().toString(), imgHolder.getDrawingCache());
            startActivity(i);
        }
    });
}

This is the addContact() method:

public void addContact(String name, String number, String email, Bitmap img){
    ContentValues values = new ContentValues();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    img.compress(Bitmap.CompressFormat.PNG, 100, out);

    values.put(COLUMN_NAME, name);
    values.put(COLUMN_NUMBER, number);
    values.put(COLUMN_EMAIL, email);
    values.put(COLUMN_IMG, out.toByteArray());

    db.insert(TABLE_NAME, null, values);
    Toast.makeText(context, "Contact Added Successfully!", Toast.LENGTH_SHORT).show();
}

This is the log output:

01-17 23:57:16.939: E/AndroidRuntime(4582): FATAL EXCEPTION: main
01-17 23:57:16.939: E/AndroidRuntime(4582): java.lang.NullPointerException
01-17 23:57:16.939: E/AndroidRuntime(4582):     at com.example.contactappca2.AddActivity$2.onClick(AddActivity.java:73)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at android.view.View.performClick(View.java:3549)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at android.view.View$PerformClick.run(View.java:14400)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at android.os.Handler.handleCallback(Handler.java:605)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at android.os.Looper.loop(Looper.java:154)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at android.app.ActivityThread.main(ActivityThread.java:4944)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at java.lang.reflect.Method.invokeNative(Native Method)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at java.lang.reflect.Method.invoke(Method.java:511)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-17 23:57:16.939: E/AndroidRuntime(4582):     at dalvik.system.NativeStart.main(Native Method)
  • 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-17T11:28:34+00:00Added an answer on June 17, 2026 at 11:28 am

    Its better if you directly pass the Bitmap rather than imgHolder.getDrawableCache(), it should work,

    BitmapDrawable drawable = (BitmapDrawable) imgHolder.getDrawable();
    Bitmap bitmap = drawable.getBitmap();
    
    i = new Intent(v.getContext(), ViewActivity.class);
    //Add contact to database
    dbAdapter.addContact(nameBox.getText().toString(), numberBox.getText().toString(), emailBox.getText().toString(), bitmap);
    startActivity(i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to submit a EDIT form which edits Users Academics Details, These
I'm trying to submit an app with these details: Base SDK: iPhone Device 3.2
Im trying to submit a specific form programatically, but I allways get the initial
I'm trying to submit a form (it's a dynamic form with fields added via
I'm trying to submit a form entry with an uploaded file, but I can't
I'm trying to submit a form when a select changes using jQuery Mobile. I
i'm trying to submit my Ajax form using jQuery. However calling the submit() function
I am trying to submit a form with method GET and action index.php?id=3. The
I'm trying to submit a form on an .asp page but Mechanize does not
I am trying to retrieve the details of the course selected from the Course

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.