我已经创建了一个应用程序,可以从我的web服务中加载一个问题,而且运行良好。但是,有时它会崩溃,我不明白发生这种情况的原因,特别是因为我也给了它所需的权限。它工作正常,但随机崩溃,并给我这个报告。
private void sendContinentQuestions(int id) {
// TODO Auto-generated method stub
//Get the data (see above)
JSONArray json = getJSONfromURL(id);
try{
for(int i=0; i < json.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject jObject = json.getJSONObject(i);
longitude":"72.5660200"
String category_id = jObject.getString("category_id");
String question_id = jObject.getString("question_id");
String question_name = jObject.getString("question_name");
String latitude = jObject.getString("latitude");
String longitude = jObject.getString("longitude");
String answer = jObject.getString("answer");
String ansLatLng = latitude+"|"+longitude ;
Log.v("## data:: ###",question_id+"--"+question_name+"-cat id-"+category_id+"--ansLatLng "+ansLatLng+" answer: "+answer);
all_question.add(new QuestionData(game_id,category_id,question_id,question_name,ansLatLng,answer));
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
}
public JSONArray getJSONfromURL(int id){
String response = "";
URL url;
try {
url = new URL(Consts.GET_URL+"index.php/Api/getQuestion?cat_id="+id);
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setRequestMethod("POST");
InputStream is = http.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
response = br.readLine();
Log.v("###Response :: ###",response);
http.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (ProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//try parse the string to a JSON object
JSONArray jArray = null;
try{
jArray = new JSONArray(response);
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
return jArray;
}
11-13 15:02:52.307: W/System.err(8012): java.net.UnknownHostException: Unable to resolve host "www.xyz.com": No address associated with hostname
11-13 15:02:52.317: W/System.err(8012): at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
11-13 15:02:52.317: W/System.err(8012): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
11-13 15:02:52.317: W/System.err(8012): at java.net.InetAddress.getAllByName(InetAddress.java:214)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282)
11-13 15:02:52.317: W/System.err(8012): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
11-13 15:02:52.327: W/System.err(8012): at com.abc.xyz.ContinentActivity.getJSONfromURL(ContinentActivity.java:400)
11-13 15:02:52.327: W/System.err(8012): at com.abc.xyz.ContinentActivity.sendContinentQuestions(ContinentActivity.java:327)
11-13 15:02:52.327: W/System.err(8012): at com.abc.xyz.ContinentActivity.access$2(ContinentActivity.java:323)
11-13 15:02:52.327: W/System.err(8012): at com.abc.xyz.ContinentActivity$LoadQuestions.doInBackground(ContinentActivity.java:254)
11-13 15:02:52.327: W/System.err(8012): at com.abc.xyz.ContinentActivity$LoadQuestions.doInBackground(ContinentActivity.java:1)
11-13 15:02:52.327: W/System.err(8012): at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-13 15:02:52.327: W/System.err(8012): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
11-13 15:02:52.327: W/System.err(8012): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-13 15:02:52.327: W/System.err(8012): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
11-13 15:02:52.337: W/System.err(8012): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
11-13 15:02:52.337: W/System.err(8012): at java.lang.Thread.run(Thread.java:841)
11-13 15:02:52.337: W/System.err(8012): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
11-13 15:02:52.337: W/System.err(8012): at libcore.io.Posix.getaddrinfo(Native Method)
11-13 15:02:52.337: W/System.err(8012): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
11-13 15:02:52.337: W/System.err(8012): at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
11-13 15:02:52.337: W/System.err(8012): ... 24 more
11-13 15:02:52.337: E/log_tag(8012): Error parsing data org.json.JSONException: End of input at character 0 of
11-13 15:02:52.337: W/dalvikvm(8012): threadid=194: thread exiting with uncaught exception (group=0x417c1700)
11-13 15:02:52.337: E/AndroidRuntime(8012): FATAL EXCEPTION: AsyncTask #5
11-13 15:02:52.337: E/AndroidRuntime(8012): java.lang.RuntimeException: An error occured while executing doInBackground()
11-13 15:02:52.337: E/AndroidRuntime(8012): at android.os.AsyncTask$3.done(AsyncTask.java:299)
11-13 15:02:52.337: E/AndroidRuntime(8012): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
11-13 15:02:52.337: E/AndroidRuntime(8012): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
11-13 15:02:52.337: E/AndroidRuntime(8012): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
11-13 15:02:52.337: E/AndroidRuntime(8012): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-13 15:02:52.337: E/AndroidRuntime(8012): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
11-13 15:02:52.337: E/AndroidRuntime(8012): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
11-13 15:02:52.337: E/AndroidRuntime(8012): at java.lang.Thread.run(Thread.java:841)
11-13 15:02:52.337: E/AndroidRuntime(8012): Caused by: java.lang.NullPointerException
11-13 15:02:52.337: E/AndroidRuntime(8012): at com.abc.xyz.ContinentActivity.sendContinentQuestions(ContinentActivity.java:328)
11-13 15:02:52.337: E/AndroidRuntime(8012): at com.abc.xyz.ContinentActivity.access$2(ContinentActivity.java:323)
11-13 15:02:52.337: E/AndroidRuntime(8012): at com.abc.xyz.ContinentActivity$LoadQuestions.doInBackground(ContinentActivity.java:254)
11-13 15:02:52.337: E/AndroidRuntime(8012): at com.abc.xyz.ContinentActivity$LoadQuestions.doInBackground(ContinentActivity.java:1)
11-13 15:02:52.337: E/AndroidRuntime(8012): at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-13 15:02:52.337: E/AndroidRuntime(8012): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
我在模拟器(OSX上的Android Studio)中也有同样的例外,但在iOS模拟器上连接到同一个URL效果很好。。。看起来这一切都源于这样一个事实:我在运行模拟器的同时连接到一个个人热点进行互联网连接,然后在连接到wifi时回来,模拟器出于某种原因不喜欢新的互联网连接,似乎它认为旧的热点是当前的连接,这已经不起作用了。。
关闭并重新启动模拟器成功了!
如果重新连接WiFi对您不起作用,请尝试重新启动设备。
这对我有用。希望有帮助。
问题内容: 我创建了一个应用程序,该应用程序从我的Web服务加载了一个问题,并且运行正常。但是,有时会崩溃,而我不知道为什么会发生这种情况,尤其是因为我还给了它所需的权限。它工作正常,但随机崩溃,并给了我这份报告。 问题答案: 我也遇到了这个问题,重新连接WiFi可以解决此问题。 对于我们来说,我们可以在启动应用程序时检查电话是否可以将主机解析为IP。如果无法解决,请告诉用户检查WiFi,然后退出
当来自后台服务和移动屏幕的API调用关闭时。出现以下错误。 java.net.无法解析主机:没有与主机名相关联的地址W/System.err:在java.net.InetAddress.lookupHostByName(InetAddress.java:424)在java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)在java.net
我正在开发一个用于测试asp的应用程序。android中的NetWebService。为此,我们使用了一个简单的Web服务来添加两个数字。其中数字作为参数传递。结果是进入对话。网络服务器在本地工作。当应用程序运行时,以下结果作为异常获取。我在清单中提供了互联网许可。 JAVA网UnknownHostException(无法解析主机)http://url.com/“:没有与主机名关联的地址) 我的代
如何处理这个崩溃?我没有任何文件Dns.kt在我的项目,得到随机用户崩溃。 无法解析主机"maps.googleapis.com":没有与主机名相关联的地址java.net.Inet6AddressImpl.lookupHostByName 由Android系统引起的。系统。GaiException android_getaddrinfo失败:EAI_NODATA(没有与主机名关联的地址)okht
问题内容: 在我的用于读取RSS链接的Android应用程序中,出现此错误: java.net.UnknownHostException:无法解析主机“ example.com”;没有与主机名关联的地址。 在模拟器中,我可以通过浏览器连接到Google。请帮助我解决此问题。 问题答案: 您可能没有权限。尝试将它添加到您的文件中: 注:以上不 必须 的前右侧的标签,但这是把它的好/正确的位置。 注意
当我尝试在android应用程序上按主机名获取ip时,我遇到了一个类似的奇怪错误。 类似的问题在IOs上返回的结果是whitout problems,但我的应用程序android没有返回任何东西。 我创建这些函数来测试我的应用程序: 但是类似的代码,在IOs上,如果我搜索我自己托管的服务器,会返回一个有效的结果,但是在android上搜索相同的页面或服务器时,结果会给我一个“无法解析主机”的警告。