From 7a868370fe5c1601ec2aeed0149d957ca88ac9b2 Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Sat, 29 Apr 2017 10:33:50 +0800 Subject: [PATCH] Fixed error when answer is null --- .../itxtech/daedalus/fragment/DnsTestFragment.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java index 52fe3fa..9c06a2b 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java @@ -106,12 +106,16 @@ public class DnsTestFragment extends Fragment { long endTime = System.currentTimeMillis(); Set answers = responseMessage.getAnswersFor(question); - for (A a : answers) { - InetAddress inetAddress = a.getInetAddress(); - testText.append("\n").append(getResources().getString(R.string.test_result_resolved)).append(" ").append(inetAddress.getHostAddress()); + if (answers != null && answers.size() > 0) { + for (A a : answers) { + InetAddress inetAddress = a.getInetAddress(); + testText.append("\n").append(getResources().getString(R.string.test_result_resolved)).append(" ").append(inetAddress.getHostAddress()); + } + testText.append("\n").append(getResources().getString(R.string.test_time_used)).append(" "). + append(String.valueOf(endTime - startTime)).append(" ms\n\n"); + } else { + testText.append("\n").append(getResources().getString(R.string.test_failed)).append("\n\n"); } - testText.append("\n").append(getResources().getString(R.string.test_time_used)).append(" ").append(String.valueOf(endTime - startTime)).append(" ms\n\n"); - } catch (Exception e) { testText.append("\n").append(getResources().getString(R.string.test_failed)).append("\n\n");