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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:23:47+00:00 2026-06-09T23:23:47+00:00

I am trying to implement an onItemClicklister() in which when an item is clicked,

  • 0

I am trying to implement an onItemClicklister() in which when an item is clicked, the text values are carried over from one activity to another. Below is the code snippet.

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

                String name = ((TextView) view.findViewById(R.id.title)).getText().toString();
                String cost = ((TextView) view.findViewById(R.id.artist)).getText().toString();
                String description = ((TextView) view.findViewById(R.id.duration)).getText().toString();

                // Starting new intent
                Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                in.putExtra(KEY_TITLE, name);
                in.putExtra(KEY_ARTIST, cost);
                in.putExtra(KEY_DURATION, description);
                startActivity(in);

            }
        });

Next Activity

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.single_list_item);

        // getting intent data
        Intent in = getIntent();

        // Get JSON values from previous intent
        String name = in.getStringExtra(KEY_TITLE);
        String cost = in.getStringExtra(KEY_ARTIST);
        String description = in.getStringExtra(KEY_DURATION);

//         Displaying all values on the screen
        TextView lblName = (TextView) findViewById(R.id.name_label);
        TextView lblCost = (TextView) findViewById(R.id.email_label);
        TextView lblDesc = (TextView) findViewById(R.id.mobile_label);

        lblName.setText(name);
        lblCost.setText(cost);
        lblDesc.setText(description);
    }

But it throws a

E/AndroidRuntime(  626): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eve_haps/com.example.eve_haps.SingleMenuItemActivity}: java.lang.NullPointerException
E/AndroidRuntime(  626):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime(  626):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime(  626):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime(  626):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime(  626):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  626):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(  626):    at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(  626):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  626):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(  626):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(  626):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(  626):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  626): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  626):    at com.example.eve_haps.SingleMenuItemActivity.onCreate(SingleMenuItemActivity.java:32)
E/AndroidRuntime(  626):    at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(  626):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(  626):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)

I dont seem know what the problem is.Thanks for your help in advance.

  • 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-09T23:23:49+00:00Added an answer on June 9, 2026 at 11:23 pm

    Un Comment following code line from SingleMenuItemActivity’s onCreate().

    setContentView(R.layout.single_list_item);
    

    I think your TextViews are null.

    And NullPointerException comes from these lines,

    lblName.setText(name);
    lblCost.setText(cost);
    lblDesc.setText(description);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement ListView with Delete functionality to delete item from the
I'm trying implement A* Start path finding in my games(which are written with JavaScript,
Trying to implement the decorator pattern in C# from the code in the Head
I am trying to create a ListActivity which its rows contain a text and
I am trying implement Unblock me Puzzle. i want to change image position from
trying to implement a multiplayer. Using the sample from Game Center - Sending and
Am trying to implement a generic way for reading sections from a config file.
Trying to implement a MSMQ-backed WCF PubSub. I understand that net.msmq is one-way; however
Ok so I've been trying to get an OnItemClickListener to retrieve values from list
I am trying implement a most recent widget into my tumblr post. So far,

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.