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

The Archive Base Latest Questions

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

I have a listview of names(imported from database).When a name on the list is

  • 0

I have a listview of names(imported from database).When a name on the list is clicked,I want to get the details of the name from the database so I have to pass the name to the next class where I am retrieving the details.I am trying to pass a name from one class to another class. I don’t know if I am passing the string wrong or getting the name of the string in a wrong way.

contact.java:

public class Contacts extends Activity implements OnClickListener {
    int NewContact_Request_Code = 1;
    Button newcontact;
    ListView listview;
    public static final String LOG_TAG = "Contacts";
    int mInt = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contactview);// Set the content to contactview.xml

        // newcontact = NEW CONTACT button
        // listview = MyList List View
        newcontact = (Button) findViewById(R.id.baddcontact);
        listview = (ListView) findViewById(R.id.mylist);

        // Make a New Database
        DBContact info = new DBContact(this);
        // Open , get Information from database and close it
        info.open();
        String[] data = info.queryAll();
        info.close();
        // listview = getListView();
        listview.setTextFilterEnabled(true);
        // Display the names
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(Contacts.this,
                android.R.layout.simple_list_item_1, data);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?>listview, View view,
                    int position, long id) {

                String nameclicked = ((TextView)view).getText().toString();
                Intent viewintent = new Intent(Contacts.this, ViewContact.class);
                viewintent.putExtra("name_clicked", nameclicked);
                startActivity(viewintent);

            }
        });
        newcontact.setOnClickListener(this);

    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent newintent = new Intent(Contacts.this, AddNewContact.class);
        // start activity for result - to get the name of the new contact
        startActivityForResult(newintent, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        // pass the value of the string via cursor and update the list
    }

}

viewcontact.java:

public class ViewContact extends Activity implements OnClickListener {
    Button ViewPPhone, ViewHPhone, ViewOPhone, EditContact;
    TextView ViewName;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewcontact);
        savedInstanceState = getIntent().getExtras();
        String name = savedInstanceState.getString("name_clicked");
        Long l = Long.parseLong(name);
        DBContact getdetails = new DBContact(this);
        getdetails.open();
        String returnedname = getdetails.getName(l);
        String returnedpphone = getdetails.getPphone(l);
        String returnedhphone = getdetails.getHphone(l);
        String returnedophone = getdetails.getOphone(l);
        getdetails.close();
        ViewName.setText(returnedname);
        ViewPPhone.setText(returnedpphone);
        ViewHPhone.setText(returnedhphone);
        ViewOPhone.setText(returnedophone);

        EditContact = (Button) findViewById(R.id.bEditContact);
        EditContact.setOnClickListener(this);
        ViewPPhone = (Button) findViewById(R.id.ViewPersonalPhoneNumber);
        ViewPPhone.setOnClickListener(this);
        ViewHPhone = (Button) findViewById(R.id.ViewHomePhoneNumber);
        ViewHPhone.setOnClickListener(this);
        ViewOPhone = (Button) findViewById(R.id.ViewOfficePhoneNumber);
        ViewOPhone.setOnClickListener(this);

    }

    public void onClick(View view) {
        // TODO Auto-generated method stub
        switch (view.getId()) {
        case R.id.ViewPersonalPhoneNumber:
        /*  Intent dialpersonalphone = new
            Intent(android.content.Intent.ACTION_DIAL,
            Uri.parse("returnedpphone"));
            startActivity(dialpersonalphone );*/
            break;

        case R.id.ViewHomePhoneNumber:
            /*Intent dialhome = new
            Intent(android.content.Intent.ACTION_DIAL,
            Uri.parse("returnedhphone"));
            startActivity(dialhome);*/
            break;

        case R.id.ViewOfficePhoneNumber:
            /*Intent dialoffice = new
            Intent(android.content.Intent.ACTION_DIAL,
            Uri.parse("returnedophone"));
            startActivity(dialoffice);*/
            break;

        case R.id.bEditContact:
            startActivity(new Intent("com.example.contactlist.EDITCONTACT"));
            break;
        }
    }

}

LOGCAT

10-02 10:30:23.064: E/AndroidRuntime(1045): FATAL EXCEPTION: main
10-02 10:30:23.064: E/AndroidRuntime(1045): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.contactlist/com.example.contactlist.ViewContact}: java.lang.NumberFormatException: Invalid long: "nishanth"
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.os.Looper.loop(Looper.java:137)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at java.lang.reflect.Method.invokeNative(Native Method)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at java.lang.reflect.Method.invoke(Method.java:511)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at dalvik.system.NativeStart.main(Native Method)
10-02 10:30:23.064: E/AndroidRuntime(1045): Caused by: java.lang.NumberFormatException: Invalid long: "nishanth"
10-02 10:30:23.064: E/AndroidRuntime(1045):     at java.lang.Long.invalidLong(Long.java:125)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at java.lang.Long.parse(Long.java:362)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at java.lang.Long.parseLong(Long.java:353)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at java.lang.Long.parseLong(Long.java:319)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at com.example.contactlist.ViewContact.onCreate(ViewContact.java:23)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.app.Activity.performCreate(Activity.java:5008)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-02 10:30:23.064: E/AndroidRuntime(1045):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-02 10:30:23.064: E/AndroidRuntime(1045):     ... 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-12T04:54:14+00:00Added an answer on June 12, 2026 at 4:54 am

    when I am passing information with bundles I find that I need to instantiate an os.Bundle object which I then go on to populate with my bundle information before adding this bundle to the intent.

    Modify your contact.java code to read;

        Intent viewintent = new Intent(Contacts.this, ViewContact.class);
        final Bundle bundle = new Bundle();
        bundle.putString("name_clicked", nameclicked);
        viewintent.putExtras(bundle);
        startActivity(viewintent);
    

    and re-run to see if that works.

    EDIT

    The problem is that String nameclicked = ((TextView)view).getText().toString(); doesn’t return a long- it returns the contact name, “nishanth”! This is clear in the logcat log which states;

    10-02 10:30:23.064: E/AndroidRuntime(1045): Caused by:
    java.lang.NumberFormatException: Invalid long: “nishanth”

    The view returned by ((TextView)view) is not the phone number- rather it is the name of the contact as alluded to by your key “name_clicked”. Change this view to target the phone number. Note that a phone number can contain “+” and “-” symbols so this implementation of retrieving the selected phone number is not fool-proof.

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

Sidebar

Related Questions

I have a listview that displays player names from a datastore class and i
I have to put a list of names queried from database into a list
It seems that android has enforced that a listview must have the name android:id=@android:id/list,
I have a ListView that shows a list of names. When you select a
I have a list that contains names. I would like to create a listview
i have to make a listview that haves a list of names, and also,
I have listview which has 5000 items. I want to get item of listview
I have a listview with the names of the email lists (on import it
I have created a list view that displays the names and dates of items
I have chat list view in which sender name should be left aligned 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.