我使用此代码从 Web 获取内容。我添加了 Internet 权限。
public void read() throws Exception
{
URL oracle = new URL("http://www.blabla.de");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
StringBuilder sb = new StringBuilder();
String inputLine="";
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine + "\n");
}
Log.w("tap",sb.toString());
}
我在 try catch 块中运行它,但它强制执行。我尝试了更多代码但相同。
这是日志
11-06 21:20:59.634: E/AndroidRuntime(4044): FATAL EXCEPTION: main
11-06 21:20:59.634: E/AndroidRuntime(4044): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.filsoft.jumpko/com.filsoft.jumpko.Rang}: java.lang.NullPointerException: println needs a message
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.os.Looper.loop(Looper.java:137)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.app.ActivityThread.main(ActivityThread.java:4424)
11-06 21:20:59.634: E/AndroidRuntime(4044): at java.lang.reflect.Method.invokeNative(Native Method)
11-06 21:20:59.634: E/AndroidRuntime(4044): at java.lang.reflect.Method.invoke(Method.java:511)
11-06 21:20:59.634: E/AndroidRuntime(4044): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-06 21:20:59.634: E/AndroidRuntime(4044): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-06 21:20:59.634: E/AndroidRuntime(4044): at dalvik.system.NativeStart.main(Native Method)
11-06 21:20:59.634: E/AndroidRuntime(4044): Caused by: java.lang.NullPointerException: println needs a message
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.util.Log.println_native(Native Method)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.util.Log.w(Log.java:180)
11-06 21:20:59.634: E/AndroidRuntime(4044): at com.filsoft.jumpko.Rang.onCreate(Rang.java:23)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.app.Activity.performCreate(Activity.java:4465)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-06 21:20:59.634: E/AndroidRuntime(4044): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
11-06 21:20:59.634: E/AndroidRuntime(4044): ... 11 more