所以我试图在成功登录后从主要活动启动 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,我在其中得到成功的调试响应,但它应该带我进入网页,但应用程序崩溃并关闭:
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