spinning wheel for webview
I want to set 开发者_JS百科spinning wheel for the webview till when the page is loaded , i am using the following approach but its floating with following logcat errors . Please guide
public class Webview extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
// Makes Progress bar Visible
getWindow().requestFeature(Window.FEATURE_PROGRESS);
WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
mWebView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle("My title");
}
});
mWebView.loadUrl("..........................");
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
}
xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
logcat
07-10 17:49:18.785: DEBUG/AndroidRuntime(23772): Shutting down VM
07-10 17:49:18.785: WARN/dalvikvm(23772): threadid=3: thread exiting with uncaught exception (group=0x4001e390)
07-10 17:49:18.785: ERROR/AndroidRuntime(23772): Uncaught handler: thread main exiting due to uncaught exception
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.droidnova.android.howto.optionmenu/com.droidnova.android.howto.optionmenu.Webview}: java.lang.NullPointerException
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.os.Looper.loop(Looper.java:123)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.app.ActivityThread.main(ActivityThread.java:4595)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at java.lang.reflect.Method.invoke(Method.java:521)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at dalvik.system.NativeStart.main(Native Method)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): Caused by: java.lang.NullPointerException
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at com.droidnova.android.howto.optionmenu.Webview.onCreate(Webview.java:36)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
07-10 17:49:18.795: ERROR/AndroidRuntime(23772): ... 11 more
I don't see it in your code - you should call setContentView before you can call findViewById
, otherwise it will return null.
So if your xml is called main.xml, you should first call setContentView(R.layout.main);
精彩评论