這裏的報告:顯示java.lang.NullPointerException ....崩潰報告
java.lang.RuntimeException: Unable to start activity ComponentInfo{rs.androidaplikacije.zastaveigradovi/rs.androidaplikacije.zastaveigradovi.PogresanOdgovor}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at rs.androidaplikacije.zastaveigradovi.PogresanOdgovor.onCreate(PogresanOdgovor.java:56)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
這基本上是一個彈出式的活動,說:「錯誤的答案」用一些聲音。下面是類:
public class PogresanOdgovor extends Activity{
MediaPlayer zvuk;
TextView pogresno;
String tacanOdgovor;
String tacno;
public final int delayTime = 2500;
private Handler myHandler = new Handler();
public void onUserInteraction(){
myHandler.removeCallbacks(zatvoriPopup);
myHandler.postDelayed(zatvoriPopup, delayTime);
}
private Runnable zatvoriPopup = new Runnable(){
public void run(){
finish();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.pogresno);
Bundle extras = getIntent().getExtras();
if(extras !=null) {
tacno = extras.getString("tacanOdgovor");
}
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean zvuci = getPrefs.getBoolean("checkbox", true);
myHandler.postDelayed(zatvoriPopup, delayTime);
inicijalizujVarijable();
if(zvuci == true){
zvuk.start();
}
}
private void inicijalizujVarijable() {
Typeface pogresanFont = Typeface.createFromAsset(getAssets(), "Bebas.ttf");
zvuk = MediaPlayer.create(this, R.raw.aah);
pogresno = (TextView) findViewById(R.id.tvPogresno);
pogresno.setTypeface(pogresanFont);
pogresno.setText("Pogrešan odgovor!\nTačan odgovor je:\n\n" + tacno);
}
}
錯誤的ON LINE:
zvuk.start();
這正是我打電話給我的sound.I不明白這一點。如果有時有效,爲什麼不總是?
zvuk.start(); ... – marjanbaz 2013-05-13 16:55:23