因此我試圖在成功登錄後從主活動啓動WebView活動。主要的活動是這樣的:重定向到Android中的webview活動
try {
response = CustomHttpClient.executeHttpPost("http://192.168.1.101/adddrop/login.php", postParameters);
Log.v(LOG_TAG," PostParameters = " +postParameters.toString());
String res=response.toString();
res= res.replaceAll("\\s+","");
Log.v(LOG_TAG," response value = " +res);
if(res.equals("1")){
Intent myIntent = new Intent(v.getContext(), Registration.class);
startActivity(myIntent);
//error.setText("Correct Username or Password");
}
else
error.setText("Sorry!! Incorrect Username or Password");
} catch (Exception e) {
USER.setText(e.toString());
}
和其他活動的WebView(編輯:這就是所謂Registration.java當我啓動它作爲一個單獨的項目主要活動的正常工作)看起來是這樣的:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new HelloWebViewClient());
mWebView.loadUrl("http://192.168.1.101/adddrop/index2.php");
mWebView.setInitialScale(130);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
,這裏是在點擊登錄的logcat的地方我得到debigging成功的響應,但它應該帶我去的網頁,但其他的應用程序崩潰和關閉:
05-19 12:02:39.394: W/dalvikvm(433): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-18 11:24:22.524: E/AndroidRuntime(1094): FATAL EXCEPTION: main
05-18 11:24:22.524: E/AndroidRuntime(1094): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.login/com.example.login.Registration}: java.lang.NullPointerException
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.os.Looper.loop(Looper.java:123)
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-18 11:24:22.524: E/AndroidRuntime(1094): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 11:24:22.524: E/AndroidRuntime(1094): at java.lang.reflect.Method.invoke(Method.java:507)
05-18 11:24:22.524: E/AndroidRuntime(1094): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-18 11:24:22.524: E/AndroidRuntime(1094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-18 11:24:22.524: E/AndroidRuntime(1094): at dalvik.system.NativeStart.main(Native Method)
05-18 11:24:22.524: E/AndroidRuntime(1094): Caused by: java.lang.NullPointerException
05-18 11:24:22.524: E/AndroidRuntime(1094): at com.example.login.Registration.onCreate(Registration.java:19)
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-18 11:24:22.524: E/AndroidRuntime(1094): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-18 11:24:22.524: E/AndroidRuntime(1094): ... 11 more
註冊似乎是空 – keyser
Registration.java看行... 19 –
刪除我的回答,@SamirMangroliya在我完成打字之前在評論中提到了它。 – jjm