2012-07-31 56 views
0

我一直收到splashscreen.java中與Thread.stop()相關的錯誤。我在它很新,並瞭解棄用使用Thread.stop(的),但可有人請解釋我在做什麼錯在這裏,感謝..splashscreen.java上的java.lang.UnsupportedOperationException錯誤

java.lang.UnsupportedOperationException 
    at java.lang.Thread.stop(Thread.java:1076) 
    at java.lang.Thread.stop(Thread.java:1063) 
    at com.dapp.d.SplashScreen$4.run(SplashScreen.java:88) 

這是splashscreen.java

的全部源代碼
import android.app.Activity; 
    import android.content.Intent; 
    import android.net.Uri; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.view.View.OnClickListener; 
    import android.widget.Button; 
    import android.widget.RelativeLayout; 

    public class SplashScreen extends Activity { 

private boolean active = true; 
private int splashTime = 3000; 
private boolean clickFlag = true; 
private Thread splashTread = null; 
private Button btnHelp; 
private Button btnAboutUs; 

@Override 
public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 

    RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.splashRelativeLayout); 
    relativeLayout.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Uri uri = Uri.parse("http://www.exmaple.com"); 
      Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
      startActivity(intent); 
     } 
    }); 

    btnAboutUs = (Button)findViewById(R.id.btnAboutus); 
    btnHelp = (Button)findViewById(R.id.btnHelp); 

    try{ 

     btnAboutUs.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       clickFlag = false; 
       splashTread.stop(); <<<<<<<<<<<<<<<<<<< line 49 
       Intent intent = new Intent(); 
       intent.setClass(getApplicationContext(), AboutUs.class); 
       startActivity(intent); 
       SplashScreen.this.finish(); 
      } 
     }); 

     btnHelp.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       clickFlag = false; 
       splashTread.stop(); <<<<<<<<<<<<<<<<<<< line 63 
       Intent intent = new Intent(); 
       intent.setClass(getApplicationContext(), HelpActivity.class); 
       startActivity(intent); 
       SplashScreen.this.finish(); 
      } 
     }); 

     splashTread = new Thread() { 
      @Override 
      public void run() { 
       try{ 
        int waited = 0; 
        while(active && (waited < splashTime)) { 
         sleep(100); 
         waited += 100; 
        }      
       } catch(InterruptedException e) { 
        // do nothing 
       }finally { 
        if(clickFlag){ 
         Intent intent=new Intent(); 
         intent.setClass(getApplicationContext(), SearchWord.class); 
         startActivity(intent); 
         finish(); 
         stop(); <<<<<<<<<<<<<<< line 88 
        }else{ 
         finish(); 
         stop(); 
        } 
       } 
      } 
     }; 
     splashTread.start(); 

    }catch (Exception e) { 
     // TODO: handle exception 
    } 
} 

    } 
+0

在stop()後運行應用程序刪除() – 2012-07-31 14:13:02

+0

這導致它在所有版本上強制關閉,而在它沒有.. – dpark123 2012-08-01 04:44:23

回答

1

我不認爲你需要打電話在那裏停止。你的線程不會循環,所以它會正常執行和結束。嘗試刪除stop();

+0

之前,如果仍不能解決問題,請嘗試連接它們。實際上,在startActivity()下面評論一切。 – Shark 2012-07-31 14:11:23

+0

我刪除了停止(),但它仍然強制關閉應用程序。刪除第49和63行 - 相同的結果,更好的想法?謝謝。 – dpark123 2012-08-01 04:43:09

+0

我不熟悉Thread.finish()是你的方法嗎?當你捕捉到異常時,你至少應該記錄這個異常,因爲當前可能發生異常並且你不知道它。 – Zoop 2012-08-01 13:25:28

0

我有一個類似的問題,解決的辦法是將停止方法包裝在try/catch語句中,並在捕獲中使用Throwable t。 它會工作。

相關問題