Skip to content Skip to sidebar Skip to footer

How To Solve Error "Unable To Start Activity ComponentInfo"?

I have written a code for alarming phone for a particular time, and the alarm will stop after that period. I have tried running this code in emulator, and everything runs smoothly.

Solution 1:

The issue is due to a nullpointer exception at onCreate. Somtimes the Audio service is not returning the AudioManager.

Change the code :

AudioManager manager = (AudioManager)getSystemService(AUDIO_SERVICE);
manager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
int maxVolume = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
manager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, 0);

as below in onCreate :

AudioManager manager = (AudioManager)getSystemService(AUDIO_SERVICE);
if(manager!=null){
manager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
int maxVolume = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
manager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, 0);
}

Solution 2:

Try using this code,

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

    mp = MediaPlayer.create(RingerActivity.this, R.raw.alarm);
    // are you sure that res/raw/alarm is a valid media file?
    mp.start();

Solution 3:

You have a NullPointerException on line 35 in your activity. Fix it.


Solution 4:

MediaPlayer mp = MediaPlayer.create(context, R.raw.alarm);
mp.prepare(); <- Error, delete this line in your code

You no need to call the method "prepare();", the method "create(,);" does that for you. :)


Post a Comment for "How To Solve Error "Unable To Start Activity ComponentInfo"?"