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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:16:39+00:00 2026-06-13T04:16:39+00:00

My issue is within my onItemClickListener method. When it gets the line where it

  • 0

My issue is within my onItemClickListener method. When it gets the line where it assigns ‘selectedEmail’. The logcat claims that there is no column named Email so I am not sure where the actual problem is.

Code for ContactsMenu class

package com.emailandcontactmanager;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class ContactsMenu extends Activity {


    ListView listView;
    public static final String fields[] = { DatabaseSetup.colName};
    Cursor cursor;

    public static String name;
    public static String email;
    public static String phone1;
    public static String phone2;
    public static String address;
    public static String notes;


    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.managecontacts);
        listView = (ListView) findViewById(R.id.lstContacts); 
        DatabaseSetup.init(this); 

        Button btnAddItem = (Button) findViewById(R.id.btnAddContact);
        btnAddItem.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent addItem = new Intent(v.getContext(), AddContact.class);
            startActivity(addItem);
        }
        });

        listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> listView, View view, 
                int position, long id) {
        // Get the cursor, positioned to the corresponding row in the result set
            //cursor = DatabaseSetup.getContactData();
        Cursor cursor = (Cursor) listView.getItemAtPosition(position);
                //change cursor
                String selectedName = cursor.getString(cursor.getColumnIndexOrThrow("Name"));
                String selectedEmail = cursor.getString(cursor.getColumnIndexOrThrow("Email"));
                String selectedPhone1 = cursor.getString(cursor.getColumnIndexOrThrow("Phone1"));
                String selectedPhone2 = cursor.getString(cursor.getColumnIndexOrThrow("Phone2"));
                String selectedAddress = cursor.getString(cursor.getColumnIndexOrThrow("Address"));
                String selectedNotes = cursor.getString(cursor.getColumnIndexOrThrow("Notes"));

                setName(selectedName);
                setName(selectedEmail);
                setName(selectedPhone1);
                setName(selectedPhone2);
                setName(selectedAddress);
                setName(selectedNotes);


                Intent viewItem = new Intent(view.getContext(), ViewContact.class);
                startActivity(viewItem);

        }
        }); 

    }
        @Override
        protected void onPause() {
            listView.setAdapter(null);
            cursor.close();
            DatabaseSetup.deactivate();
            super.onPause();
        }

        @Override
        protected void onResume() {
            super.onResume();
            DatabaseSetup.init(this);
            //Updated
            cursor = DatabaseSetup.getContactData(); 
            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, fields, new int[] {R.id.item_text});
            listView.setAdapter(adapter); 
        }


        public void setName(String selectedName) {
            name = selectedName;
        }

        public void setEmail(String selectedEmail) {
            email = selectedEmail;
        }

        public void setPhone1(String selectedPhone1) {
            phone1 = selectedPhone1;
        }

        public void setPhone2(String selectedPhone2) {
            phone2 = selectedPhone2;
        }

        public void setAddress(String selectedAddress) {
            address = selectedAddress;
        }

        public void setNotes(String selectedNotes) {
            notes = selectedNotes;
        }


        public static String getName() {
            String itemName = name;
            return itemName;        
        }

        public static String getEmail() {
            String itemEmail = email;
            return itemEmail;       
        }

        public static String getPhone1() {
            String itemPhone1 = phone1;
            return itemPhone1;      
        }

        public static String getPhone2() {
            String itemPhone2 = phone2;
            return itemPhone2;      
        }

        public static String getAddress() {
            String itemAddress = address;
            return itemAddress;     
        }

        public static String getNotes() {
            String itemNotes = notes;
            return itemNotes;       
        }

////////////////MENU////////////////////////////////////////////////////////////////////////////////
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
            switch (which){ 
            case DialogInterface.BUTTON_POSITIVE: 
                finish();
                break; 

            case DialogInterface.BUTTON_NEGATIVE: 
                //Nothing happens on No button click, and the menu closes
                break; 
            } 
        } 
    }; 

    @Override
    public boolean onCreateOptionsMenu(Menu mainmenu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.mainmenu, mainmenu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        final CharSequence[] items = {"Contacts list", "Add Contact"};

        switch (item.getItemId()) {
            case R.id.help:     AlertDialog.Builder builder = new AlertDialog.Builder(this);
                                builder.setTitle("Select a function to revice information about it.");
                                builder.setItems(items, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int selected) {
                                        switch(selected){
                                        case 0:
                                            Toast.makeText(getApplicationContext(),
                                                    "Allows you to view the selected item and make editations to it or delete it.",
                                                    Toast.LENGTH_LONG).show();
                                            break;
                                        case 1:
                                            Toast.makeText(getApplicationContext(),
                                                    "Allows you to add a new contact by bringing up a screen where the nececary information can be entered.",
                                                    Toast.LENGTH_LONG).show();
                                        }
                                    }
                                });
                                builder.show();
                                break;

                                case R.id.back:     AlertDialog.Builder builderBack = new AlertDialog.Builder(this); 
                                                    builderBack.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) 
                                                    .setNegativeButton("No", dialogClickListener).show(); 
                                break;
        }
        return true;

    }
}

Code for DatabaseSetup class

    package com.emailandcontactmanager;

import android.content.ContentValues; 
import android.content.Context; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 

/* 
 * usage:  
 * DatabaseSetup.init(egActivityOrContext); 
 * DatabaseSetup.createEntry() or DatabaseSetup.getContactNames() or DatabaseSetup.getDb() 
 * DatabaseSetup.deactivate() then job done 
 */ 

class DatabaseSetup extends SQLiteOpenHelper { 
static DatabaseSetup instance = null; 
static SQLiteDatabase db = null; 

public static void init(Context context) { 
    if (null == instance) { 
        instance = new DatabaseSetup(context); 
        } 
    } 

public static SQLiteDatabase getDb() { 
    if (null == db) { 
        db = instance.getWritableDatabase(); 
        } 
    return db; 
    } 

public static void deactivate() { 
    if (null != db && db.isOpen()) { 
        db.close(); 
        } 
    db = null; 
    instance = null; 
    } 

public static long createEntry(String name, String mail, String phone1, 
        String phone2, String address, String notes) { 
    ContentValues cv = new ContentValues(); 
    cv.put(colName, name); 
    cv.put(colMail, mail); 
    cv.put(colPhone1, phone1); 
    cv.put(colPhone2, phone2); 
    cv.put(colAddress, address); 
    cv.put(colNotes, notes); 
    return getDb().insert(contactsTable, null, cv); 

    } 
/*  Old 
public static Cursor getContactNames() { 
    // TODO Auto-generated method stub 
    String[] columns = new String[] {"_id", colName }; 
    return getDb().query(contactsTable, columns, null, null, null, null, 
            null); 
    } 
*/
public static Cursor getContactData(){
    String[] columns = new String[] {"_id", colName, colMail, colPhone1, colPhone2, colAddress, colNotes }; 
    return getDb().query(contactsTable, columns, null, null, null, null, 
            null); 
    }

DatabaseSetup(Context context) { 
    super(context, dbName, null, dbVersion); 
    } 

@Override 
public void onCreate(SQLiteDatabase db) { 
    // TODO Auto-generated method stub 
    db.execSQL("CREATE TABLE IF NOT EXISTS " + contactsTable 
            + " (_id integer primary key autoincrement, " + colName 
            + " TEXT NOT NULL, " + colMail + " TEXT NOT NULL, " + colPhone1 
            + " TEXT NOT NULL, " + colPhone2 + " TEXT NOT NULL, " 
            + colAddress + " TEXT NOT NULL, " + colNotes 
            + " TEXT NOT NULL)"); 

    db.execSQL("CREATE TABLE IF NOT EXISTS " + templatesTable 
            + " (_id integer primary key autoincrement, " + colSubject 
            + " TEXT NOT NULL, " + colBody + " TEXT NOT NULL)"); 

    db.execSQL("CREATE TABLE IF NOT EXISTS " + tagsTable 
            + " (_id integer primary key autoincrement, " + colTagName 
            + " TEXT NOT NULL, " + colContact + " TEXT NOT NULL)"); 

    } 

@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    db.execSQL("DROP TABLE IF EXISTS " + contactsTable); 
    db.execSQL("DROP TABLE IF EXISTS " + templatesTable); 
    db.execSQL("DROP TABLE IF EXISTS " + tagsTable); 
    onCreate(db); 
    } 

static final String dbName = "DB"; 
static final int dbVersion = 1; 
static final String contactsTable = "Contacts"; 
static final String colName = "Name"; 
static final String colMail = "Email"; 
static final String colPhone1 = "Phone1"; 
static final String colPhone2 = "Phone2"; 
static final String colAddress = "Address"; 
static final String colNotes = "Notes"; 

static final String templatesTable = "Templates"; 
static final String colSubject = "Subject"; 
static final String colBody = "Body"; 

static final String tagsTable = "Tags"; 
static final String colTagName = "Name"; 
static final String colContact = "Contact"; 

} 

Code for ViewContact class

    package com.emailandcontactmanager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ViewContact extends Activity {

    EditText nameField, mailield, phoneField1, phoneField2, addressField, notesField;

    String name, mail, phone1, phone2, address, notes;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewcontact);

        nameField = (EditText) findViewById(R.id.txtName);
        mailield = (EditText) findViewById(R.id.txtMail);
        phoneField1 = (EditText) findViewById(R.id.txtPhone1);
        phoneField2 = (EditText) findViewById(R.id.txtPhone2);
        addressField = (EditText) findViewById(R.id.txtAddress);
        notesField = (EditText) findViewById(R.id.txtNotes);

        name = ContactsMenu.getName();
        mail = ContactsMenu.getEmail();
        phone1 =ContactsMenu.getPhone1();
        phone2 =ContactsMenu.getPhone2();
        address =ContactsMenu.getAddress();
        notes =ContactsMenu.getNotes();

        nameField.setText(name);
        mailield.setText(mail);
        phoneField1.setText(phone1);
        phoneField2.setText(phone2);
        addressField.setText(address);
        notesField.setText(notes);

        Button btnEditContact = (Button) findViewById(R.id.btnEditContact);
        btnEditContact.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            editContact();
        }
        });

        Button btnDeleteContact = (Button) findViewById(R.id.btnEditContact);
        btnDeleteContact.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            deleteContact();
        }
        });

        Button btnEditTags = (Button) findViewById(R.id.btnEditContact);
        btnEditTags.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent editTags = new Intent(v.getContext(), EditContactTags.class);
            startActivity(editTags);
        }
        });

    }

    public void editContact(){

    }

    public void deleteContact(){

    }

    public void setValues(){

    }

}

Logcat output

10-16 13:37:12.824: D/gralloc_goldfish(869): Emulator without GPU emulation detected.
10-16 13:37:20.553: D/AndroidRuntime(869): Shutting down VM
10-16 13:37:20.553: W/dalvikvm(869): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
10-16 13:37:20.603: E/AndroidRuntime(869): FATAL EXCEPTION: main
10-16 13:37:20.603: E/AndroidRuntime(869): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.emailandcontactmanager/com.emailandcontactmanager.ViewContact}: java.lang.NullPointerException
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.os.Looper.loop(Looper.java:137)
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.app.ActivityThread.main(ActivityThread.java:4340)
10-16 13:37:20.603: E/AndroidRuntime(869):  at java.lang.reflect.Method.invokeNative(Native Method)
10-16 13:37:20.603: E/AndroidRuntime(869):  at java.lang.reflect.Method.invoke(Method.java:511)
10-16 13:37:20.603: E/AndroidRuntime(869):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-16 13:37:20.603: E/AndroidRuntime(869):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-16 13:37:20.603: E/AndroidRuntime(869):  at dalvik.system.NativeStart.main(Native Method)
10-16 13:37:20.603: E/AndroidRuntime(869): Caused by: java.lang.NullPointerException
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.app.Activity.findViewById(Activity.java:1794)
10-16 13:37:20.603: E/AndroidRuntime(869):  at com.emailandcontactmanager.ViewContact.<init>(ViewContact.java:12)
10-16 13:37:20.603: E/AndroidRuntime(869):  at java.lang.Class.newInstanceImpl(Native Method)
10-16 13:37:20.603: E/AndroidRuntime(869):  at java.lang.Class.newInstance(Class.java:1319)
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
10-16 13:37:20.603: E/AndroidRuntime(869):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
10-16 13:37:20.603: E/AndroidRuntime(869):  ... 11 more

Please tell me if I need to clarify the question.

  • 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-13T04:16:40+00:00Added an answer on June 13, 2026 at 4:16 am

    You cursor contains only _id and colName, (Name). It does not contain Email. You have to add it to the projection in order to be able to retreive it.

    You’ll also need Phone1, Phone2, Address and Notes.

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

Sidebar

Related Questions

I'm having an issue calling a method from a separate project within the same
I'm having an issue with an expanding div tag that is nested within another
I am having an issue whereby a column within a table of mine has
****UPDATE**** # The issue was within the wanpipemon script and the way that it
I'm having an issue with text overflowing within a column when an inline image
How can I use validation controls within server controls? The issue that I have
My issue is that I cannot add SourceSafe Database for source control within Visual
Update: This issue was not properly explored. The real issue lies within render :json
I am implementing instrumentation within an application and have encountered an issue where the
I've an issue at the moment where we are running a CMS within a

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.