-1

这是报告:

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);

    }
    }

错误在线:

zvuk.start();

这就是我所说的声音。我不明白。如果有时有效,为什么不总是?

4

1 回答 1

0

之后你发布了你的 MediaPlayer 吗?

于 2013-05-13T17:00:56.527 回答