Note that there are some explanatory texts on larger screens.

plurals
  1. PONullpointer Exceptions
    text
    copied!<p>I have been following some android tutorials on the web. I tried copying his code to the best of my ability but whenever I run the application it crashes. I looked through the console and found it was a Nullpointer exception that caused it. The application is meant to play a sound and then close and then go to another layout. Here is my code, please tell me what I did wrong.</p> <pre><code> package com.greg.hello; import android.app.Activity; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundle; public class MainActivity extends Activity { MediaPlayer mpSplash; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.splash); MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.explosion); mpSplash.start(); Thread logoTimer = new Thread(){ public void run(){ try{ int logoTimer=0; while(logoTimer&lt;8000){ sleep(100); logoTimer=logoTimer+100; } startActivity(new Intent("com.greg.hello.CLEARSCREEN")); } catch (InterruptedException e) { // TODO Auto-generated catch block setContentView(R.layout.tutorial1); e.printStackTrace(); } finally{ finish(); } } }; logoTimer.start(); finish(); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); mpSplash.release(); startActivity(new Intent("com.greg.hello.TUTORIALONE")); setContentView(R.layout.activity_main); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); mpSplash.pause(); setContentView(R.layout.activity_main); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); mpSplash.start(); setContentView(R.layout.activity_main); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); setContentView(R.layout.activity_main); } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); setContentView(R.layout.activity_main); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload