2013-05-17 228 views
0

我再次遇到此問題。 In this thread我有與按鈕單擊聲音相同的問題。沒有什麼幫助,所以我禁用了這個聲音。無其他解決方案。現在,我有了相同的崩潰報告,但現在在另一個帶有複選框聲音的活動中。我勒個去???我從來沒有這個崩潰,直到我禁用其他聲音。所以我想如果我禁用這個聲音,我會遇到其他一些聲音的問題。所以這不是解決方案。在這裏,崩潰報告:java.lang.NullPointerException ...崩潰報告

java.lang.NullPointerException 
at rs.androidaplikacije.zastaveigradovi.Izbor.onCheckedChanged(Izbor.java:126) 
at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172) 
at android.widget.RadioGroup.access$600(RadioGroup.java:52) 
at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342) 
at android.widget.CompoundButton.setChecked(CompoundButton.java:127) 
at android.widget.CompoundButton.toggle(CompoundButton.java:86) 
at android.widget.RadioButton.toggle(RadioButton.java:72) 
at android.widget.CompoundButton.performClick(CompoundButton.java:98) 
at android.view.View$PerformClick.run(View.java:9080) 
at android.os.Handler.handleCallback(Handler.java:587) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:130) 
at android.app.ActivityThread.main(ActivityThread.java:3821) 
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:875) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) 
at dalvik.system.NativeStart.main(Native Method) 

和活動代碼:

public void onCheckedChanged(RadioGroup group, int checkedId) { 
      if(music == true){ 
      buttonClicks.start(); 
      } 
      } 

錯誤是在這條線:

buttonClicks.start(); 

這裏是全班同學:

public class Izbor extends Activity implements OnClickListener, OnCheckedChangeListener{ 

    public boolean music; 
    MediaPlayer buttonClicks; 
    MediaPlayer buttonBack; 
    RadioButton rbDesetEasy,rbDvadesetEasy,rbDesetMedium,rbDvadesetMedium,rbDesetHard, rbDvadesetHard; 
    Button dNazad, dStart; 
    RadioGroup rGrupa; 
    TextView tv1; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); 
     music = getPrefs.getBoolean("checkbox", true); 

     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.izbor); 
     addListenerOnButton(); 

    } 

    private void addListenerOnButton() { 

     Typeface dugmad = Typeface.createFromAsset(getAssets(), "Bebas.ttf"); 
     Typeface pitanjeVrh = Typeface.createFromAsset(getAssets(), "Lobster.ttf"); 


     rbDesetEasy = (RadioButton) findViewById(R.id.radio1); 
     rbDvadesetEasy = (RadioButton) findViewById(R.id.radio2); 
     rbDesetMedium = (RadioButton) findViewById(R.id.radio3); 
     rbDvadesetMedium = (RadioButton) findViewById(R.id.radio4); 
     rbDesetHard = (RadioButton) findViewById(R.id.radio5); 
     rbDvadesetHard = (RadioButton) findViewById(R.id.radio6); 
     dNazad = (Button) findViewById(R.id.bNazad); 
     dStart = (Button) findViewById(R.id.bStart); 
     rGrupa = (RadioGroup) findViewById(R.id.radioGroup1); 
     buttonBack = MediaPlayer.create(Izbor.this, R.raw.button31); 
     tv1 = (TextView) findViewById(R.id.tv1); 
     buttonClicks = MediaPlayer.create(this, R.raw.click); 

     dNazad.setTypeface(dugmad); 
     dStart.setTypeface(dugmad); 
     rbDesetEasy.setTypeface(dugmad); 
     rbDvadesetEasy.setTypeface(dugmad); 
     rbDesetMedium.setTypeface(dugmad); 
     rbDvadesetMedium.setTypeface(dugmad); 
     rbDesetHard.setTypeface(dugmad); 
     rbDvadesetHard.setTypeface(dugmad); 
     tv1.setTypeface(pitanjeVrh); 


     rGrupa.setOnCheckedChangeListener(this); 
     rbDesetEasy.setOnClickListener(this); 
     rbDvadesetEasy.setOnClickListener(this); 
     rbDesetMedium.setOnClickListener(this); 
     rbDvadesetMedium.setOnClickListener(this); 
     rbDesetHard.setOnClickListener(this); 
     rbDvadesetHard.setOnClickListener(this); 
     dStart.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       if(rbDesetEasy.isChecked()){ 
        Intent intent = new Intent(Izbor.this, Kviz.class); 
        intent.putExtra("myMethod", "nextQuestion"); 
        startActivity(intent); 
       }else if(rbDvadesetEasy.isChecked()){ 
         Intent intent = new Intent(Izbor.this, Kviz20.class); 
         intent.putExtra("myMethod", "nextQuestion"); 
         startActivity(intent); 
        }else if(rbDesetMedium.isChecked()){ 
         Intent intent = new Intent(Izbor.this, Kviz10Medium.class); 
         intent.putExtra("myMethod", "nextQuestion"); 
         startActivity(intent); 
        }else if(rbDvadesetMedium.isChecked()){ 
         Intent intent = new Intent(Izbor.this, Kviz20Medium.class); 
         intent.putExtra("myMethod", "nextQuestion"); 
         startActivity(intent); 
        }else if(rbDesetHard.isChecked()){ 
         Intent intent = new Intent(Izbor.this, Kviz10Hard.class); 
         intent.putExtra("myMethod", "nextQuestion"); 
         startActivity(intent); 
        }else if(rbDvadesetHard.isChecked()){ 
         Intent intent = new Intent(Izbor.this, Kviz20Hard.class); 
         intent.putExtra("myMethod", "nextQuestion"); 
         startActivity(intent); 
       } 
      } 
     }); 


     dNazad.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       if(music == true){ 
       buttonBack.start(); 
       } 
       finish(); 
      } 
     }); 
    } 

    public void onCheckedChanged(RadioGroup group, int checkedId) { 
     if(music == true){ 
     buttonClicks.start(); 
     } 
     } 

    public void onClick(View v) { 
     // TODO Auto-generated method stub 

    } 
} 
+0

可能是您的'buttonClicks'爲'null'? –

+3

你確定'R.raw.click'存在並且拼寫正確嗎? – codeMagic

+0

'if(music == true){'不是很好的風格,'如果(音樂){'好得多...... – jlordo

回答

1

MediaPlayer似乎是即使你試圖在這裏

R.raw.click 

初始化它按照Docs

返回 一個MediaPlayer對象,或者爲null,如果創建失敗

所以這告訴我們,你的R.raw.clicks可能丟失,拼寫不正確或不可用。這導致MediaPlayer創建失敗,因此將您的buttonClicks作爲null

+0

它不會丟失,拼寫正確。它適用於我的電話和我女朋友的電話。我可以聽到它。而且我有大約10 000次下載這個應用程序,並且只有這些崩潰報告中的幾個,所以它在其他情況下工作正常。 – marjanbaz

+0

@marjanbaz你確定它與特定手機的型號無關嗎? – thegrinner

+0

嗯,我不知道。 Google不會與崩潰報告共享該信息。也許。 – marjanbaz