Android HttpURLConnection致命错误

时间:2013-07-17 18:46:40

标签: java android

我正在为android编写一个下载管理器,当我尝试打开httpurlconnection时会出错

07-17 20:30:13.928: E/AndroidRuntime(25485): FATAL EXCEPTION: main
07-17 20:30:13.928: E/AndroidRuntime(25485): java.lang.IllegalStateException: Could not execute method of the activity
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.view.View$1.onClick(View.java:3699)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.view.View.performClick(View.java:4223)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.view.View$PerformClick.run(View.java:17275)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.os.Handler.handleCallback(Handler.java:615)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.os.Looper.loop(Looper.java:137)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.app.ActivityThread.main(ActivityThread.java:4921)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at java.lang.reflect.Method.invokeNative(Native Method)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at java.lang.reflect.Method.invoke(Method.java:511)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at dalvik.system.NativeStart.main(Native Method)
07-17 20:30:13.928: E/AndroidRuntime(25485): Caused by: java.lang.reflect.InvocationTargetException
07-17 20:30:13.928: E/AndroidRuntime(25485):    at java.lang.reflect.Method.invokeNative(Native Method)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at java.lang.reflect.Method.invoke(Method.java:511)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.view.View$1.onClick(View.java:3694)
07-17 20:30:13.928: E/AndroidRuntime(25485):    ... 11 more
07-17 20:30:13.928: E/AndroidRuntime(25485): Caused by: java.lang.NullPointerException: println needs a message
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.util.Log.println_native(Native Method)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at android.util.Log.d(Log.java:155)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at com.example.flinkdownloadmanager.DownloadService.DownloadFile(DownloadService.java:87)
07-17 20:30:13.928: E/AndroidRuntime(25485):    at com.example.flinkdownloadmanager.MainActivity.DownloadItem(MainActivity.java:115)
07-17 20:30:13.928: E/AndroidRuntime(25485):    ... 14 more

这是我的下载程序代码

public void DownloadFile(String uri)
    {
        //Toast.makeText(this, uri, Toast.LENGTH_SHORT).show();
        int count;
        try {
            URL url = new URL(uri);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setInstanceFollowRedirects(false);
            connection.connect();

        } catch (Exception e) {
            Log.e("Error: ", e.getMessage());
        }
}

0 个答案:

没有答案