Android 应用程序在启动时崩溃,没有任何更改..?
Android App crashes on startup with nothing changed..?
[已解决] -> NullPointerException 不是在 Java 中引起的,而是由外部源 (WCF webservice) 错误实现引起的。
我在 Android Studio 中有一个 Android 应用程序项目,几天前我工作得很好。我今天开始工作,从字面上改变 nothing 并且当我现在启动它时,它只是在启动时崩溃。我真的不明白堆栈跟踪试图告诉我什么..
[ 08-21 16:59:35.445 8492:
8492 D/ ]
HostConnection::get() New Host
Connection established 0xa279c3c0, tid 8492
[ 08-21 16:59:35.499 8492:
8520 D/ ]
HostConnection::get() New Host
Connection established 0xa279c740, tid 8520
08-21 16:59:35.559 8492-8492/com.example.pmatthews.appointmentcreator
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pmatthews.appointmentcreator, PID: 8492
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String[] java.lang.String.split(java.lang.String)' on a null
object reference
at
com.example.pmatthews.appointmentcreator.
appointments$GetConNum.onPostExecute(ap
pointments.java:142)
at
com.example.pmatthews.appointmentcreator.
appointments$GetConNum.onPostExecute(appointments.java:71)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.
ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
08-21 16:59:36.728 2155-2243/com.google.android.googlequicksearchbox:search
E/AudioRecord: Could not get audio input for session 897, record source
1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
08-21 16:59:36.731 2155-2243/com.google.android.googlequicksearchbox:search
E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check
failed with status -22.
08-21 16:59:36.731 2155-2243/com.google.android.googlequicksearchbox:search
E/android.media.AudioRecord: Error code -20 when initializing native
AudioRecord object.
08-21 16:59:36.731 2155-2243/com.google.android.googlequicksearchbox:search
E/ActivityThread: Failed to find provider info for
com.google.android.apps.gsa.testing.ui.audio.recorded
启动activity- appointments.java:
class GetConNum extends AsyncTask<String, Void, String> {
StringBuilder sb = new StringBuilder();
String status = null;
Activity context;
ListView listView = (ListView) findViewById(R.id.list);
TextView txtV = (TextView) findViewById(R.id.txtConNum);
TextView txtV1 = (TextView) findViewById(R.id.txtConNum1);
TextView txtV2 = (TextView) findViewById(R.id.txtConNum2);
TextView txtV3 = (TextView) findViewById(R.id.txtConNum3);
TextView txtV4 = (TextView) findViewById(R.id.txtConNum4);
TextView txtV5 = (TextView) findViewById(R.id.txtConNum5);
TextView txtV6 = (TextView) findViewById(R.id.txtConNum6);
TextView txtV7 = (TextView) findViewById(R.id.txtConNum7);
TextView txtV8 = (TextView) findViewById(R.id.txtConNum8);
TextView txtV9 = (TextView) findViewById(R.id.txtConNum9);
TextView txtV10 = (TextView) findViewById(R.id.txtConNum10);
TextView txtV11 = (TextView) findViewById(R.id.txtConNum11);
TextView txtV12 = (TextView) findViewById(R.id.txtConNum12);
TextView txtV13 = (TextView) findViewById(R.id.txtConNum13);
TextView txtV14 = (TextView) findViewById(R.id.txtConNum14);
TextView txtV15 = (TextView) findViewById(R.id.txtConNum15);
TextView txtV16 = (TextView) findViewById(R.id.txtConNum16);
TextView txtV17 = (TextView) findViewById(R.id.txtConNum17);
TextView txtV18 = (TextView) findViewById(R.id.txtConNum18);
TextView txtV19 = (TextView) findViewById(R.id.txtConNum19);
public GetConNum(Activity context, ListView listView){
this.context = context;
this.listView = listView;
}
public void onPreExecute(){
}
public String doInBackground(String... connUrl){
HttpURLConnection conn = null;
BufferedReader reader;
try{
final URL url = new URL(connUrl[0]);
conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("Content-Type", "application/json;
charset=utf-8");
conn.setRequestMethod("GET");
int result = conn.getResponseCode();
if(result == 200){
InputStream in = new
BufferedInputStream(conn.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while ((line = reader.readLine()) != null){
status = line;
res = res + result;
}
}
}catch(Exception ex){
}
return status;
}
protected void onPostExecute(String result){
super.onPostExecute(result);
String[] resultArray = result.split(",");
if (resultArray.length == 0){
}else if (resultArray.length == 1) {
txtV.setText(resultArray[0].replaceAll("
[[{}]]","").replaceAll("\[", "").replaceAll("\]",
"").replaceAll("\"","").replaceAll(":", " :
").replaceAll("/","").replaceAll("00
: 00 AM", ""));
}else if (resultArray.length == 2){
检查你的AsyncTask
。
您正在尝试拆分 null String
.
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String[] java.lang.String.split(java.lang.String)' on a null
object reference
多亏了你们两个指出了我不知何故未能错过的事情,我才弄明白:字符串为空。在调试器中,我得到的 getresponsecode 为 400,因此我检查了 Google Chrome 中的 Web 服务,结果出乎意料,我没有获取数据,而是遇到了异常。我进入 Visual Studio 并摆脱了未实现异常并将其配置为 运行 方法。奇迹般有效。谢谢大家:)
[已解决] -> NullPointerException 不是在 Java 中引起的,而是由外部源 (WCF webservice) 错误实现引起的。
我在 Android Studio 中有一个 Android 应用程序项目,几天前我工作得很好。我今天开始工作,从字面上改变 nothing 并且当我现在启动它时,它只是在启动时崩溃。我真的不明白堆栈跟踪试图告诉我什么..
[ 08-21 16:59:35.445 8492:
8492 D/ ]
HostConnection::get() New Host
Connection established 0xa279c3c0, tid 8492
[ 08-21 16:59:35.499 8492:
8520 D/ ]
HostConnection::get() New Host
Connection established 0xa279c740, tid 8520
08-21 16:59:35.559 8492-8492/com.example.pmatthews.appointmentcreator
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pmatthews.appointmentcreator, PID: 8492
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String[] java.lang.String.split(java.lang.String)' on a null
object reference
at
com.example.pmatthews.appointmentcreator.
appointments$GetConNum.onPostExecute(ap
pointments.java:142)
at
com.example.pmatthews.appointmentcreator.
appointments$GetConNum.onPostExecute(appointments.java:71)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.
ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
08-21 16:59:36.728 2155-2243/com.google.android.googlequicksearchbox:search
E/AudioRecord: Could not get audio input for session 897, record source
1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
08-21 16:59:36.731 2155-2243/com.google.android.googlequicksearchbox:search
E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check
failed with status -22.
08-21 16:59:36.731 2155-2243/com.google.android.googlequicksearchbox:search
E/android.media.AudioRecord: Error code -20 when initializing native
AudioRecord object.
08-21 16:59:36.731 2155-2243/com.google.android.googlequicksearchbox:search
E/ActivityThread: Failed to find provider info for
com.google.android.apps.gsa.testing.ui.audio.recorded
启动activity- appointments.java:
class GetConNum extends AsyncTask<String, Void, String> {
StringBuilder sb = new StringBuilder();
String status = null;
Activity context;
ListView listView = (ListView) findViewById(R.id.list);
TextView txtV = (TextView) findViewById(R.id.txtConNum);
TextView txtV1 = (TextView) findViewById(R.id.txtConNum1);
TextView txtV2 = (TextView) findViewById(R.id.txtConNum2);
TextView txtV3 = (TextView) findViewById(R.id.txtConNum3);
TextView txtV4 = (TextView) findViewById(R.id.txtConNum4);
TextView txtV5 = (TextView) findViewById(R.id.txtConNum5);
TextView txtV6 = (TextView) findViewById(R.id.txtConNum6);
TextView txtV7 = (TextView) findViewById(R.id.txtConNum7);
TextView txtV8 = (TextView) findViewById(R.id.txtConNum8);
TextView txtV9 = (TextView) findViewById(R.id.txtConNum9);
TextView txtV10 = (TextView) findViewById(R.id.txtConNum10);
TextView txtV11 = (TextView) findViewById(R.id.txtConNum11);
TextView txtV12 = (TextView) findViewById(R.id.txtConNum12);
TextView txtV13 = (TextView) findViewById(R.id.txtConNum13);
TextView txtV14 = (TextView) findViewById(R.id.txtConNum14);
TextView txtV15 = (TextView) findViewById(R.id.txtConNum15);
TextView txtV16 = (TextView) findViewById(R.id.txtConNum16);
TextView txtV17 = (TextView) findViewById(R.id.txtConNum17);
TextView txtV18 = (TextView) findViewById(R.id.txtConNum18);
TextView txtV19 = (TextView) findViewById(R.id.txtConNum19);
public GetConNum(Activity context, ListView listView){
this.context = context;
this.listView = listView;
}
public void onPreExecute(){
}
public String doInBackground(String... connUrl){
HttpURLConnection conn = null;
BufferedReader reader;
try{
final URL url = new URL(connUrl[0]);
conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("Content-Type", "application/json;
charset=utf-8");
conn.setRequestMethod("GET");
int result = conn.getResponseCode();
if(result == 200){
InputStream in = new
BufferedInputStream(conn.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while ((line = reader.readLine()) != null){
status = line;
res = res + result;
}
}
}catch(Exception ex){
}
return status;
}
protected void onPostExecute(String result){
super.onPostExecute(result);
String[] resultArray = result.split(",");
if (resultArray.length == 0){
}else if (resultArray.length == 1) {
txtV.setText(resultArray[0].replaceAll("
[[{}]]","").replaceAll("\[", "").replaceAll("\]",
"").replaceAll("\"","").replaceAll(":", " :
").replaceAll("/","").replaceAll("00
: 00 AM", ""));
}else if (resultArray.length == 2){
检查你的AsyncTask
。
您正在尝试拆分 null String
.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference
多亏了你们两个指出了我不知何故未能错过的事情,我才弄明白:字符串为空。在调试器中,我得到的 getresponsecode 为 400,因此我检查了 Google Chrome 中的 Web 服务,结果出乎意料,我没有获取数据,而是遇到了异常。我进入 Visual Studio 并摆脱了未实现异常并将其配置为 运行 方法。奇迹般有效。谢谢大家:)