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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:30:52+00:00 2026-05-27T17:30:52+00:00

I am working on a contact list application and i am getting an error

  • 0

I am working on a contact list application and i am getting an error when i try to get the path of my image in my edit text:

12-27 18:12:37.909: E/AndroidRuntime(2620): Caused by: java.lang.NullPointerException
12-27 18:12:37.909: E/AndroidRuntime(2620):     at org.example.dbcontactconsole.ContactDetails.onCreate(ContactDetails.java:54)
12-27 18:12:37.909: E/AndroidRuntime(2620):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-27 18:12:37.909: E/AndroidRuntime(2620):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)

ContactDetails.java source is:

package org.example.dbcontactconsole;

import android.app.Activity;
import android.app.AlertDialog;                                                                            
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class ContactDetails extends Activity{
    private Button cancelButton;
    private Button saveContactButton;
    private static EditText poza;
    private static final int SELECT_PICTURE = 1;
    private static EditText nameField; 
    private static EditText mobilePhoneField;
    private static EditText emailField;
    private static Uri currImageURI;

    private static String operationType;
    static final int RESULT_MODIFY_USER = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contactdetails);
         Button sButton = (Button) findViewById(R.id.button1);
         sButton.setOnClickListener(new OnClickListener() {

              public void onClick(View arg0) {
                  // in onCreate or any event where your want the user to
                  // select a file
                  Intent intent = new Intent();
                  intent.setType("image/*");
                  intent.setAction(Intent.ACTION_GET_CONTENT);
                  startActivityForResult(Intent.createChooser(intent,
                          "Select Picture"), SELECT_PICTURE);
              }
          });
        Bundle incomingActionType = getIntent().getExtras();
        operationType = incomingActionType.getString("mod_type");

        if (operationType.equals("addPerson")){

            nameField = (EditText) findViewById(R.id.contactName); 
            mobilePhoneField = (EditText) findViewById(R.id.contactmobile);
            emailField = (EditText) findViewById(R.id.contactemail);
            poza=(EditText) findViewById(R.id.editText1);
            poza.setText(currImageURI.toString());
        }

        else if (operationType.equals("modifyPerson")){

            String modifyFirstName = incomingActionType.getString("cFirstName");
            nameField = (EditText) findViewById(R.id.contactName);
            nameField.setText(modifyFirstName);


            String modifyPhoneNumber = incomingActionType.getString("cMobilePhone");
            mobilePhoneField = (EditText) findViewById(R.id.contactmobile);
            mobilePhoneField.setText(modifyPhoneNumber);

            String modifyEmail = incomingActionType.getString("cEmail");
            emailField = (EditText) findViewById(R.id.contactemail);
            emailField.setText(modifyEmail);    
        }


    cancelButton = (Button) findViewById(R.id.cancelcontactbutton);
    saveContactButton = (Button) findViewById(R.id.savecontactbutton);

    saveContactButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Intent resultIntent = new Intent();
            Bundle contactData = new Bundle();

                if (nameField.getText().toString().length() == 0){
                    new AlertDialog.Builder(ContactDetails.this).setTitle("Error").setMessage("First name field cannot be empty!").setNeutralButton("Close", null).show();
                } else if (mobilePhoneField.getText().toString().length() == 0){
                    new AlertDialog.Builder(ContactDetails.this).setTitle("Error").setMessage("Mobile Phone field cannot be empty!").setNeutralButton("Close", null).show();
                } else if (emailField.getText().toString().length() == 0){
                    new AlertDialog.Builder(ContactDetails.this).setTitle("Error").setMessage("Email field cannot be empty!").setNeutralButton("Close", null).show();
                } else{
                    contactData.putString("contactFirstName", nameField.getText().toString());
                    contactData.putString("contactMobilePhone", mobilePhoneField.getText().toString());
                    contactData.putString("contactEmail", emailField.getText().toString());

                    resultIntent.putExtra("contactData", contactData);

                    if (operationType.equals("addPerson")){
                        setResult(RESULT_FIRST_USER, resultIntent);
                    }else if (operationType.equals("modifyPerson")){
                        setResult(RESULT_MODIFY_USER, resultIntent);
                    }               
                    finish();
                }
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener(){


        public void onClick(View v) {
            Intent resultIntent = new Intent();
            setResult(RESULT_CANCELED, resultIntent);
            finish();


        }
    });

    }
    public void onActivityResult(int requestCode, int resultCode, Intent data) {  
           if (resultCode == RESULT_OK) {
               if (requestCode == 1) {
                   // currImageURI is the global variable I'm using to hold the content:// URI of the image
                    currImageURI = data.getData();
                   getRealPathFromURI(currImageURI);

               }
             }
           }


        public String getRealPathFromURI(Uri currImageURI) {
           // can post image
           String [] proj={MediaStore.Images.Media.DATA};
           Cursor cursor = managedQuery( currImageURI,
                   proj, // Which columns to return
                   null,       // WHERE clause; which rows to return (all rows)
                   null,       // WHERE clause selection arguments (none)
                   null); // Order-by clause (ascending by name)
           int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
           cursor.moveToFirst();


              poza=(EditText)findViewById(R.id.editText1);
               poza.setText(currImageURI.toString());
              return cursor.getString(column_index);

        }
  }

line 54 is:poza.setText(currImageURI.toString());
I think that the error appears because currimageURI has no value, but i made the onActivityResult method. Can you help me please?

  • 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-05-27T17:30:52+00:00Added an answer on May 27, 2026 at 5:30 pm

    Sure. You wrote the onActivityResult method, so what? That method is called (if called) after the onCreate so currImageURI is null when onCreate gets executed.

    Just do not do that in onCreate. Do it when currImageURI is not null, i.e. in the onActivityResult method.

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

Sidebar

Related Questions

I am working on a contact list application I need to create 2 tables
Hi im working on iphone application using monotouch im trying to get list of
Iam working on a contact list application i need to do 2 table because
On my contact list application i try to use autocompletetextview when making search of
I am working on a contact list project and the last thing i need
I'm working on a Sencha Touch application, and have a list of contacts. When
I am working at a contacl list database application and when i click on
I am working on a contact list project in android and i want to
I am working on a contact list project and so far i can add,modify
I have referred this code to display contact list. and it is working fine

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.