2013-08-31 31 views
0

由於某種原因,當我在我的代碼中聲明onResume()時,它在開始時無故崩潰我的程序,甚至沒有打開。onResume()讓我的應用程序崩潰,沒有理由

這是我的onResume()代碼:

public void onResume() 
    { 
     if(play==true) 
     { 
      if(playing==false) 
      { 
       if(numbl>0) 
       { 
       letter=thefull.substring(cur, cur+1); 
       if(letter.equals("m")) 
       { 
        oursong = MediaPlayer.create(MainActivity.this, R.raw.m); 
        oursong.start(); 
        playing=true; 
       } 
       else if(letter.equals("a")) 
       { 
        oursong = MediaPlayer.create(MainActivity.this, R.raw.a); 
        oursong.start(); 
        playing=true; 
       } 
       else if(letter.equals("r")) 
       { 
        oursong = MediaPlayer.create(MainActivity.this, R.raw.r); 
        oursong.start(); 
        playing=true; 
       } 
       } 
      } 


     } 

    } 

只要我刪除的onResume()程序運行得很好。 我做錯了什麼?

這裏是我完整的代碼一看:http://pastebin.com/faVfFK6q

+0

@ user2734723玩什麼玩?他們布爾變量?也發佈你的logcat ...如果可能的話,添加行號錯誤發生的地方..! – TheFlash

+0

請發佈LogCat –

+0

播放和播放都是布爾值。 出於某種原因,我的代碼不工作壽,因爲它不會播放像我想要的彼此之後的聲音。 – John

回答

6

必須完成的Android活動的生命週期。

如果你是覆蓋onResume()或生命週期的任何方法,你應該調用super.onResume();

public void onResume(){ 
super.onResume(); 

/// Your Code 
} 

UPDATE

條件你檢查是的onResume()方法不正確。

if(play) // UPDATE HERE 
     { 
      if(!playing)// UPDATE HERE 
      { 
       if(numbl>0) 
       { 
       letter=thefull.substring(cur, cur+1); 
       if(letter.equals("m")) 
       { 
        oursong = MediaPlayer.create(MainActivity.this, R.raw.m); 
        oursong.start(); 
        playing=true; 
       } 
       else if(letter.equals("a")) 
       { 
        oursong = MediaPlayer.create(MainActivity.this, R.raw.a); 
        oursong.start(); 
        playing=true; 
       } 
       else if(letter.equals("r")) 
       { 
        oursong = MediaPlayer.create(MainActivity.this, R.raw.r); 
        oursong.start(); 
        playing=true; 
       } 
       } 
      } 


     } 
+0

它現在有效。 還有一個問題,我注意到,即使是我所有的變量都是正確的,它不會播放任何聲音...你知道爲什麼嗎? – John

+0

我改變玩玩==真(玩)和玩==假((假) 但它仍然沒有工作 – John

+0

寫if(!playing)而不是if(!false) –

相關問題