try {
URL url = new URL("http://javalovers.net16.net/showdata.php");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.connect();
switch (connection.getResponseCode()) {
case HttpURLConnection.HTTP_OK:
InputStream stream = connection.getInputStream(); //here getting response
br = new BufferedReader(new InputStreamReader(stream));
String line = "";
while ((line = br.readLine()) != null) {
// buffer.append(line);
str = str + line;
}
break; // fine, go on
case HttpURLConnection.HTTP_GATEWAY_TIMEOUT:
break; // retry
case HttpURLConnection.HTTP_UNAVAILABLE:
break; // retry, server is unstable
default:
break; // abort
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
connection.disconnect();
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
-致命html" target="_blank">异常:AsyncTask#3进程:kuldeep.mourya.com.smartCollege,pid:10617 java.lang.RuntimeException:在Android.os.AsyncTask$3执行doInBackground()时出错。done(AsyncTask.java:309)在java.util.concurrent.FutureTask.FinishCompletion(futureTask.java:354)在java.util.concurrent.FutureTask.SetException(futureTask.java:354)在rofessor.CollegeNWSFragment$JsonTask.DoinBackground(collegeNWSFragment.java:148)位于android.os.asyncTask$2.call(asynctask.java:295)
有人知道为什么我会出现这个错误吗?
哇!!!我在分离异常时得到了答案,尝试捕获块!
//URL url=new URL("http://javalovers.net16.net/showdata.php");
URL url = null;// this api link
try {
url = new URL("http://vcetsmart.netne.net/showdata.php");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
connection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
connection.setRequestMethod("POST");
} catch (ProtocolException e) {
e.printStackTrace();
}
try {
connection.connect();
} catch (IOException e) {
e.printStackTrace();
}
try{
if(connection.getResponseCode()==200)
{
//Toast.makeText(getBaseContext(),"Everything is right",Toast.LENGTH_SHORT).show();
InputStream stream=connection.getInputStream(); //here getting response
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String line = "";
while ((line = br.readLine()) != null) {
// buffer.append(line);
str=str+line;
}
}
else {
Toast toast= Toast.makeText(getActivity(),"Something goes wrong", Toast.LENGTH_LONG);
toast.show();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str;
br = new BufferedReader(new InputStreamReader(stream));
在上面的代码行中,您在哪里声明并初始化了BufferedReader?
当连接可用时,很有可能您肯定会将数据获取到您的流中。但当您未连接到internet时,流为NULL。
我给您的建议是在您的代码中做一个小改动:
URL url = new URL("http://javalovers.net16.net/showdata.php");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.connect();
BufferredReader br = new BufferedReader(new InputStreamReader(stream));
我做了一个应用程序登录,一切都是正常的昨天,但今天android工作室给了我这个错误 {08-03 14:29:07.894 137 03-14015/Complete.Lyne.MyApplication E/AndroidRuntime:致命异常:AsyncTask#1进程:Complete.Lyne.MyApplication,PID:13703 java.lang.RuntimeExcep
我在android设备上构建代码时出错了。这是错误报告 05-17 09:47:16.035 17982-18134/com . example . ckw . mapku E/Android runtime:致命异常:async task # 1 05-17 09:47:16.035 17982-18134/com . example . mapku E/Android runtime:Proc
执行 时出错。 这是错误日志: 11-05 05:03:20.171:E/Android runtime(3171):致命异常:async task # 1 < br > 11-05 05:03:20.171:E/Android runtime(3171):Process:com . example . MySQL test,PID:3171 < br > 11-05 05:03:20.171:E
我在android设备上构建代码时出错。这是错误报告 致命异常:AsyncTask#1进程:com。实例冈图,PID:1248爪哇。lang.RuntimeException:在android上执行doInBackground()时出错。操作系统。异步任务3美元。在java上完成(AsyncTask.java:304)。util。同时发生的未来任务。在java完成(FutureTask.java:
java.lang.RuntimeException:执行doInBackground()E/Android runtime(695)时出错:at Android . OS . async task $ 3 . done(async task . Java:200)E/Android runtime(695):at Java . util . concurrent . future task $
活动: 类 updateTwitterStatus extends AsyncTask { 这就是 LogCat 06-05 18:00:26.696: E/AndroidRuntime(1516): 致命异常: AsyncTask #2 06-05 18:00:26.696: E/AndroidRuntime(1516): java.lang.RuntimeException: 执行 doInB