我正在运行以下代码....
package com.dc;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class DC extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
try
{
// this is the code that I am surrounding in the try/catch block
super.onCreate(savedInstanceState);
//init webview
WebView DCWebView = (WebView) findViewById(R.id.webview);
//when a link is clicked, use the WebView instead of opening a new browser
DCWebView.setWebViewClient(new MyWebViewClient() {
public void launchExternalBrowser(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
//enable javascript
WebSettings webViewSettings = DCWebView.getSettings();
webViewSettings.setJavaScriptEnabled(true);
}
catch (Exception e)
{
// this is the line of code that sends a real error message to the log
Log.e("ERROR", "ERROR IN CODE: " + e.toString());
// this is the line that prints out the location in
// the code where the error occurred.
e.printStackTrace();
}
}
}
这个堆栈跟踪并不是非常有用。我刚刚学习java / android(我有PHP背景)
11-20 21:22:43.892: ERROR/ERROR(1032): ERROR IN CODE: java.lang.NullPointerException
11-20 21:22:43.892: WARN/System.err(1032): java.lang.NullPointerException
11-20 21:22:43.902: WARN/System.err(1032): at com.dealclippings.DealClippings.onCreate(DealClippings.java:24)
11-20 21:22:43.902: WARN/System.err(1032): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-20 21:22:43.912: WARN/System.err(1032): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
11-20 21:22:43.912: WARN/System.err(1032): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
11-20 21:22:43.922: WARN/System.err(1032): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-20 21:22:43.922: WARN/System.err(1032): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
11-20 21:22:43.932: WARN/System.err(1032): at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 21:22:43.932: WARN/System.err(1032): at android.os.Looper.loop(Looper.java:123)
11-20 21:22:43.942: WARN/System.err(1032): at android.app.ActivityThread.main(ActivityThread.java:3647)
11-20 21:22:43.942: WARN/System.err(1032): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 21:22:43.952: WARN/System.err(1032): at java.lang.reflect.Method.invoke(Method.java:507)
11-20 21:22:43.952: WARN/System.err(1032): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-20 21:22:43.962: WARN/System.err(1032): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-20 21:22:43.962: WARN/System.err(1032): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
您在文件DealClippings第24行
中有NullPointerExceptionjava.lang.NullPointerException at
com.dealclippings.DealClippings.onCreate(DealClippings.java:24)