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

  • Home
  • SEARCH
  • 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 9203975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:35:48+00:00 2026-06-17T23:35:48+00:00

I am trying to display the value of a string to a text View

  • 0

I am trying to display the value of a string to a text View in java class. But when i run my app it is showing that my application has stopped unexpectedly. It is not working properly please suggest me a best way to do this.

My code:

protected void onListItemClick(ListView l, View v, int position, long id){
    currentPosition = position;
    playSong(MEDIA_PATH + songs.get(position));

    //Toast.makeText(getApplicationContext(), songs.get(position).toString(), Toast.LENGTH_SHORT).show();

    Intent in = new Intent(this, current_song.class);
    startActivity(in);

    //Toast.makeText(getApplicationContext(), "End of Song List", Toast.LENGTH_SHORT).show();
    final String songName = songs.get(position).toString();
    final TextView textchange = (TextView)findViewById(R.id.current_song_name);
    textchange.setText(songName);

}

Layout xml:

    <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical" >

<Button 
    android:id="@+id/play_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Play"
    />

<TextView 
    android:id="@+id/current_song_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

    </LinearLayout>

Log:

01-26 22:29:16.599: I/Process(531): Sending signal. PID: 531 SIG: 9
01-26 22:29:28.679: D/AndroidRuntime(602): Shutting down VM
01-26 22:29:28.679: W/dalvikvm(602): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-26 22:29:28.750: E/AndroidRuntime(602): FATAL EXCEPTION: main
01-26 22:29:28.750: E/AndroidRuntime(602): java.lang.NullPointerException
01-26 22:29:28.750: E/AndroidRuntime(602):  at    com.example.musicplayer.MainActivity.onListItemClick(MainActivity.java:71)
01-26 22:29:28.750: E/AndroidRuntime(602):  at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
01-26 22:29:28.750: E/AndroidRuntime(602):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-26 22:29:28.750: E/AndroidRuntime(602):  at android.widget.ListView.performItemClick(ListView.java:3513)
01-26 22:29:28.750: E/AndroidRuntime(602):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
01-26 22:29:28.750: E/AndroidRuntime(602):  at android.os.Handler.handleCallback(Handler.java:587)
01-26 22:29:28.750: E/AndroidRuntime(602):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-26 22:29:28.750: E/AndroidRuntime(602):  at android.os.Looper.loop(Looper.java:123)
01-26 22:29:28.750: E/AndroidRuntime(602):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-26 22:29:28.750: E/AndroidRuntime(602):  at java.lang.reflect.Method.invokeNative(Native Method)
01-26 22:29:28.750: E/AndroidRuntime(602):  at java.lang.reflect.Method.invoke(Method.java:507)
01-26 22:29:28.750: E/AndroidRuntime(602):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-26 22:29:28.750: E/AndroidRuntime(602):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-26 22:29:28.750: E/AndroidRuntime(602):  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-17T23:35:49+00:00Added an answer on June 17, 2026 at 11:35 pm

    You are trying to do this from your list activity,

    final TextView textchange = (TextView)findViewById(R.id.current_song_name);
    textchange.setText(songName);
    

    But this view is declared in the xml which you are using in current_song.java Activity.

    You can’t use view objects of one activity to other.

    Pass the value of songName with bundle extras to current_song activity with intent and then set that songName in your current_song activity.

    From your List activity :

    protected void onListItemClick(ListView l, View v, int position, long id){
        currentPosition = position;
        final String songName = songs.get(position).toString();
        playSong(MEDIA_PATH + songs.get(position));
        Intent in = new Intent(this, current_song.class);
        in.putExtra("song_name",songName );
        startActivity(in);
    }
    

    In your current_song activity :

    Bundle extras = getIntent().getExtras();
    
    if (extras != null) {
        String songName = extras.getString("song_name");
        TextView textchange = (TextView)findViewById(R.id.current_song_name);
        textchange.setText(songName);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the $url value to display from the MySQL database but
I'm having an issue using a new WPF app that is trying to display
I am trying to display the float value degrees as a string in a
I am trying to display a default value (or even NO value) when selected
I'm trying to change the value of a dojo tree to display the correct
i am trying to get the value from my methods and display it in
I am trying to display latitude and longitude values in a TextView , but
I'm trying to display string on the textview. I'm succesfully able to print it
I'm making an application that parses text and images from the Internet and displays
I'm trying to diagnose a problem in UKSyntaxColoredTextDocument 0.4 http://www.zathras.de/angelweb/blog-uksctd-oh-four.htm where text that actually

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.