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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:11:51+00:00 2026-06-16T20:11:51+00:00

I am making a music player application for my Computing project. I got it

  • 0

I am making a music player application for my Computing project. I got it working but found that using objects would get more more marks. As a result, I changed some of my code to incorporate the use of objects, but it doesn’t work when I execute my application. Btw I am quite new to Java so it’s possible I made a silly mistake.

When I used this code the function I tried to implement worked:

private void SongTitleEndTime(){
    try {
        TextViewSongTitle = (TextView)findViewById(R.id.songTitle); 
        if (id != 0 ){ 
            String where = MediaStore.Audio.Media._ID + " = " + "'" + id + "'"; 
              final Cursor mCursor = managedQuery( 
              MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
              new String[] {MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media._ID.toString(), MediaStore.Audio.Media.ALBUM_ID.toString()}, where , null,
              null); 
              mCursor.moveToFirst(); 
              String title = mCursor.getString(0); 
              String artist = mCursor.getString(1); 
              String name = title + " - " + artist; 
              TextViewSongTitle.setText(name); 
              String fulltime; 
              albumfullid = Long.parseLong(mCursor.getString(3));
              TextView EndTime = (TextView) findViewById(R.id.endtime); 
              long Minutes = TimeUnit.MILLISECONDS.toMinutes(mMediaPlayer.getDuration()); 
              long Seconds = TimeUnit.MILLISECONDS.toSeconds(mMediaPlayer.getDuration()) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(mMediaPlayer.getDuration()));
                if (Seconds < 10) { 
                    String second = "0" + String.valueOf(Seconds);
                    fulltime = Minutes + ":" + second;
                } else {
                        //else display as normal
                    fulltime = Minutes + ":" + Seconds;
                }

             EndTime.setText(fulltime); 
             //display the duration of song
        }
      } catch (IllegalArgumentException e) { 
        e.printStackTrace();
      } catch (IllegalStateException e) {
        e.printStackTrace();
      } //catch for errors
}

But when I tried this, I got an error:

Main Class:

private void SongTitleEndTime() {
    try {
        final TextView TextViewSongTitle = (TextView) findViewById(R.id.songTitle);
        if (CurrentSongID != 0) {
            final Song CurrentSong = new Song(CurrentSongID);
            SongName = CurrentSong.SongName;
            TextViewSongTitle.setText(SongName);
            AlbumID = CurrentSong.AlbumID;
            final TextView EndTime = (TextView) findViewById(R.id.endtime);
            final String TotalSongDuration = CurrentSong.TotalDuration;
            EndTime.setText(TotalSongDuration);
        }
    } catch (final IllegalArgumentException e) {
        e.printStackTrace();
    } catch (final IllegalStateException e) {
        e.printStackTrace();
    }
}

Object Class:

package com.example.music.test;

import java.util.concurrent.TimeUnit;
import android.app.Activity;
import android.database.Cursor;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio.AudioColumns;
import android.provider.MediaStore.MediaColumns;

public class Song extends Activity {

private final String where;
public String SongName;
public long AlbumID;
public String TotalDuration;

public Song(final long SongID) {
    where = MediaStore.Audio.Media._ID + " = " + "'" + SongID + "'";
    final Cursor mCursor = managedQuery(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST,
                    MediaStore.Audio.Media._ID.toString(),
                    MediaStore.Audio.Media.ALBUM_ID.toString() }, where, null, null);
            mCursor.moveToFirst();
    final String SongTitle = getSongTitle(mCursor);
    final String SongArtist = getSongArtist(mCursor);
    SongName = SongTitle + " - " + SongArtist;
    AlbumID = getAlbumID(mCursor);
    TotalDuration = getTotalDuration();
}

public String getSongTitle(final Cursor mCursor) {
    final String songtitle = mCursor.getString(0);
    return songtitle;
}

public String getSongArtist(final Cursor mCursor) {
    final String songartist = mCursor.getString(1);
    return songartist;
}

public long getAlbumID(final Cursor mCursor) {
    final long AlbumID = Long.parseLong(mCursor.getString(3));
    return AlbumID;
}

public String getTotalDuration() {
    String TotalTime;
    final long Minutes = TimeUnit.MILLISECONDS
            .toMinutes(Player.mMediaPlayer.getDuration());
    final long Seconds = TimeUnit.MILLISECONDS
            .toSeconds(Player.mMediaPlayer.getDuration())
            - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
                    .toMinutes(Player.mMediaPlayer.getDuration()));
    if (Seconds < 10) {
        final String second = "0" + String.valueOf(Seconds);
        TotalTime = Minutes + ":" + second;
    } else {
        TotalTime = Minutes + ":" + Seconds;
    }
    return TotalTime;
}

}

The error I get is:

01-02 21:55:41.941: E/AndroidRuntime(717): FATAL EXCEPTION: main
01-02 21:55:41.941: E/AndroidRuntime(717): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.music.test/com.example.music.test.Player}: java.lang.NullPointerException
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.os.Looper.loop(Looper.java:137)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.ActivityThread.main(ActivityThread.java:4745)
01-02 21:55:41.941: E/AndroidRuntime(717):  at java.lang.reflect.Method.invokeNative(Native Method)
01-02 21:55:41.941: E/AndroidRuntime(717):  at java.lang.reflect.Method.invoke(Method.java:511)
01-02 21:55:41.941: E/AndroidRuntime(717):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-02 21:55:41.941: E/AndroidRuntime(717):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-02 21:55:41.941: E/AndroidRuntime(717):  at dalvik.system.NativeStart.main(Native Method)
01-02 21:55:41.941: E/AndroidRuntime(717): Caused by: java.lang.NullPointerException
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:91)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.Activity.managedQuery(Activity.java:1737)
01-02 21:55:41.941: E/AndroidRuntime(717):  at com.example.music.test.Song.<init>(Song.java:21)
01-02 21:55:41.941: E/AndroidRuntime(717):  at com.example.music.test.Player.SongTitleEndTime(Player.java:90)
01-02 21:55:41.941: E/AndroidRuntime(717):  at com.example.music.test.Player.AllActivities(Player.java:80)
01-02 21:55:41.941: E/AndroidRuntime(717):  at com.example.music.test.Player.onCreate(Player.java:66)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.Activity.performCreate(Activity.java:5008)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-02 21:55:41.941: E/AndroidRuntime(717):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
01-02 21:55:41.941: E/AndroidRuntime(717):  ... 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-16T20:11:53+00:00Added an answer on June 16, 2026 at 8:11 pm

    Song is an Activity. Thus you can’t call manageQuery before onCreate has been called. That’s your error.

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

Sidebar

Related Questions

I'm making an android application that plays music. When I run it, I get
I'm making a music player for android and I would like to get the
I am making a music player in PyQt4, and I am using Phonon to
I've created a music service for my application (a music player), and after making
I am making Shadowing application . I have in trouble that play music by
I am making an android application where i got a seekbar for some music.
So i want to get a game that i'm making to start playing music
I'm making an audio player app. In apple's Music app, if music album or
I'm making a game. Now if my player goes to another level the music
I'm making a mock-media player program that allows the user to input,edit,delete and view

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.