Im新的android和java編程。我試圖得到啓動時加載啓動畫面,然後在後臺加載位於不同活動的webview,一旦webview頁面準備就緒,我想切換活動到webview的活動預加載web視圖,然後切換到其活動
package com.example.troyalert;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new DownloadWebpageTask().execute();
}
private class DownloadWebpageTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... arg0) {
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://enigmamaster.com/raul/locator3/");
myWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url){
setContentView(R.layout.activity_main);
}
});
return null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
該應用程序在doInBackground()上崩潰,我很確定它是因爲它沒有看到啓動畫面上的webview視圖。我如何使這項工作,以便一旦webview中的頁面加載它切換到activity_main佈局。 原因想這是我不想帶有一個白色的屏幕的人在等待頁面加載在它
05-13 14:34:37.174: E/Trace(1070): error opening trace file: No such file or directory (2)
05-13 14:34:37.814: W/dalvikvm(1070): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
05-13 14:34:37.894: D/gralloc_goldfish(1070): Emulator without GPU emulation detected.
05-13 14:34:38.474: E/AndroidRuntime(1070): FATAL EXCEPTION: AsyncTask #1
05-13 14:34:38.474: E/AndroidRuntime(1070): java.lang.RuntimeException: An error occured while executing doInBackground()
05-13 14:34:38.474: E/AndroidRuntime(1070): at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-13 14:34:38.474: E/AndroidRuntime(1070): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-13 14:34:38.474: E/AndroidRuntime(1070): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-13 14:34:38.474: E/AndroidRuntime(1070): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-13 14:34:38.474: E/AndroidRuntime(1070): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-13 14:34:38.474: E/AndroidRuntime(1070): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-13 14:34:38.474: E/AndroidRuntime(1070): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-13 14:34:38.474: E/AndroidRuntime(1070): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-13 14:34:38.474: E/AndroidRuntime(1070): at java.lang.Thread.run(Thread.java:856)
05-13 14:34:38.474: E/AndroidRuntime(1070): Caused by: java.lang.NullPointerException
05-13 14:34:38.474: E/AndroidRuntime(1070): at com.example.troyalert.MainActivity$DownloadWebpageTask.doInBackground(MainActivity.java:24)
05-13 14:34:38.474: E/AndroidRuntime(1070): at com.example.troyalert.MainActivity$DownloadWebpageTask.doInBackground(MainActivity.java:1)
05-13 14:34:38.474: E/AndroidRuntime(1070): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-13 14:34:38.474: E/AndroidRuntime(1070): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-13 14:34:38.474: E/AndroidRuntime(1070): ... 5 more
05-13 14:39:38.700: I/Process(1070): Sending signal. PID: 1070 SIG: 9
郵政logcat的請 – 2013-05-13 19:44:10
添加logcat的。 – EnigmaMaster 2013-05-13 20:02:35