我正在使用最新版本的android studio。 6.0沒有apache庫,但我已經將它們添加到gradle中。我的應用程序可以工作,但不能獲取數據。我已經添加下面的日誌貓,包括我的mainactivity:Android Studio JSon HTTP應用程序崩潰
public class MainActivity extends AppCompatActivity {
private TextView responseTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.responseTextView = (TextView) this.findViewById(R.id.responseTextView);
new GetAllLecturesTask().execute(new ApiConnector());
}
public void setTextToTextView(JSONArray jsonArray)
{
String s = "";
for (int i=0; i<jsonArray.length();i++){
JSONObject json = null;
try{
json = jsonArray.getJSONObject(i);
s = s +
"Name : "+json.getString("Name")+
"EmailAddress : "+json.getString("EmailAddress")+"\n"+
"PhoneNo : "+json.getString("PhoneNo")+"\n\n";
}catch (JSONException e){
e.printStackTrace();
}
}
}
private class GetAllLecturesTask extends AsyncTask<ApiConnector,Long,JSONArray>
{
@Override
protected JSONArray doInBackground(ApiConnector... params){
return params[0].GetAllLectures();
}
@Override
protected void onPostExecute(JSONArray jsonArray){
setTextToTextView(jsonArray);
}
}
}
的logcat:
02-16 20:55:57.690 2304-2304/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
02-16 20:55:57.690 2304-2304/? D/AndroidRuntime: CheckJNI is ON
02-16 20:55:57.710 2304-2304/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
02-16 20:55:57.740 2304-2304/? E/memtrack: Couldn't load memtrack module (No such file or directory)
02-16 20:55:57.740 2304-2304/? E/android.os.Debug: failed to load memtrack module: -2
02-16 20:55:57.740 2304-2304/? I/Radio-JNI: register_android_hardware_Radio DONE
02-16 20:55:57.750 2304-2304/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
02-16 20:55:57.760 1357-1368/? I/ActivityManager: Force stopping com.example.jahanara.externaldatabase appid=10066 user=0: from pid 2304
02-16 20:55:57.760 1357-1368/? I/ActivityManager: Killing 2275:com.example.jahanara.externaldatabase/u0a66 (adj 0): stop com.example.jahanara.externaldatabase
02-16 20:55:57.770 1357-1393/? W/InputDispatcher: channel '3605d7 com.example.jahanara.externaldatabase/com.example.jahanara.externaldatabase.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
02-16 20:55:57.770 1357-1393/? E/InputDispatcher: channel '3605d7 com.example.jahanara.externaldatabase/com.example.jahanara.externaldatabase.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
02-16 20:55:57.770 1357-1369/? D/GraphicsStats: Buffer count: 2
02-16 20:55:57.770 1357-1369/? I/WindowState: WIN DEATH: Window{3605d7 u0 com.example.jahanara.externaldatabase/com.example.jahanara.externaldatabase.MainActivity}
02-16 20:55:57.770 1357-1369/? W/InputDispatcher: Attempted to unregister already unregistered input channel '3605d7 com.example.jahanara.externaldatabase/com.example.jahanara.externaldatabase.MainActivity (server)'
02-16 20:55:57.800 1357-1368/? W/ActivityManager: Force removing ActivityRecord{999f3d u0 com.example.jahanara.externaldatabase/.MainActivity t135}: app died, no saved state
02-16 20:55:57.810 1357-1803/? W/ActivityManager: Spurious death for ProcessRecord{966925c 0:com.example.jahanara.externaldatabase/u0a66}, curProc for 2275: null
02-16 20:55:57.810 2304-2304/? D/AndroidRuntime: Shutting down VM
02-16 20:55:58.050 1697-1828/? W/EGL_emulation: eglSurfaceAttrib not implemented
02-16 20:55:58.050 1697-1828/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f690c260840, error=EGL_SUCCESS
02-16 20:55:58.100 1005-1005/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
02-16 20:55:58.600 2313-2313/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
02-16 20:55:58.600 2313-2313/? D/AndroidRuntime: CheckJNI is ON
02-16 20:55:58.620 2313-2313/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
02-16 20:55:58.690 2313-2313/? E/memtrack: Couldn't load memtrack module (No such file or directory)
02-16 20:55:58.690 2313-2313/? E/android.os.Debug: failed to load memtrack module: -2
02-16 20:55:58.690 2313-2313/? I/Radio-JNI: register_android_hardware_Radio DONE
02-16 20:55:58.700 2317-2317/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
02-16 20:55:58.700 2317-2317/? D/AndroidRuntime: CheckJNI is ON
02-16 20:55:58.710 2313-2313/? D/AndroidRuntime: Calling main entry com.android.commands.wm.Wm
02-16 20:55:58.720 2317-2317/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
02-16 20:55:58.740 2317-2317/? E/memtrack: Couldn't load memtrack module (No such file or directory)
02-16 20:55:58.740 2317-2317/? E/android.os.Debug: failed to load memtrack module: -2
02-16 20:55:58.740 2317-2317/? I/Radio-JNI: register_android_hardware_Radio DONE
02-16 20:55:58.750 2317-2317/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
02-16 20:55:58.760 1357-1803/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.jahanara.externaldatabase/.MainActivity} from uid 0 on display 0
02-16 20:55:59.120 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 360ms
02-16 20:55:59.270 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 440ms
02-16 20:55:59.570 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 450ms
02-16 20:55:59.730 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 460ms
02-16 20:55:59.900 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 480ms
02-16 20:56:00.050 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 480ms
02-16 20:56:00.220 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 490ms
02-16 20:56:00.240 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 340ms
02-16 20:56:00.380 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 330ms
02-16 20:56:00.530 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 310ms
02-16 20:56:00.680 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 440ms
02-16 20:56:00.830 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 450ms
02-16 20:56:00.990 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 460ms
02-16 20:56:01.150 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 470ms
02-16 20:56:01.300 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 470ms
02-16 20:56:01.600 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 450ms
02-16 20:56:01.750 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 450ms
02-16 20:56:01.910 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 460ms
02-16 20:56:02.070 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 470ms
02-16 20:56:02.210 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 460ms
02-16 20:56:02.360 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 450ms
02-16 20:56:02.510 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 440ms
02-16 20:56:02.660 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 450ms
02-16 20:56:02.810 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 450ms
02-16 20:56:02.960 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 450ms
02-16 20:56:02.980 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 320ms
02-16 20:56:03.120 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 310ms
02-16 20:56:03.120 1357-1726/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowManagerService$H.handleMessage(android.os.Message) from WindowManagerService.java:8000 waiters=2 for 160ms
02-16 20:56:03.120 1357-1803/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.doFrame(long) from WindowAnimator.java:121 waiters=2 for 140ms
02-16 20:56:03.120 2313-2313/? D/AndroidRuntime: Shutting down VM
02-16 20:56:03.290 1357-1849/? W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowManagerService$H.handleMessage(android.os.Message) from WindowManagerService.java:7820 waiters=2 for 160ms
02-16 20:56:03.290 1357-1371/? W/art: Long monitor contention event with owner method=int com.android.server.am.ActivityStackSupervisor.startActivityMayWait(android.app.IApplicationThread, int, java.lang.String, android.content.Intent, java.lang.String, android.service.voice.IVoiceInteractionSession, com.android.internal.app.IVoiceInteractor, android.os.IBinder, java.lang.String, int, int, android.app.ProfilerInfo, android.app.IActivityManager$WaitResult, android.content.res.Configuration, android.os.Bundle, boolean, int, android.app.IActivityContainer, com.android.server.am.TaskRecord) from ActivityStackSupervisor.java:946 waiters=0 for 4.470s
02-16 20:56:03.290 2317-2317/? D/AndroidRuntime: Shutting down VM
02-16 20:56:03.290 1357-1388/? W/art: Long monitor contention event with owner method=int com.android.server.am.ActivityStackSupervisor.startActivityMayWait(android.app.IApplicationThread, int, java.lang.String, android.content.Intent, java.lang.String, android.service.voice.IVoiceInteractionSession, com.android.internal.app.IVoiceInteractor, android.os.IBinder, java.lang.String, int, int, android.app.ProfilerInfo, android.app.IActivityManager$WaitResult, android.content.res.Configuration, android.os.Bundle, boolean, int, android.app.IActivityContainer, com.android.server.am.TaskRecord) from ActivityStackSupervisor.java:946 waiters=1 for 3.280s
02-16 20:56:03.290 1357-1429/? W/art: Long monitor contention event with owner method=int com.android.server.am.ActivityStackSupervisor.startActivityMayWait(android.app.IApplicationThread, int, java.lang.String, android.content.Intent, java.lang.String, android.service.voice.IVoiceInteractionSession, com.android.internal.app.IVoiceInteractor, android.os.IBinder, java.lang.String, int, int, android.app.ProfilerInfo, android.app.IActivityManager$WaitResult, android.content.res.Configuration, android.os.Bundle, boolean, int, android.app.IActivityContainer, com.android.server.am.TaskRecord) from ActivityStackSupervisor.java:946 waiters=2 for 2.440s
02-16 20:56:03.320 1357-1849/? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 2275 uid 10066
02-16 20:56:03.330 1697-1697/? I/Choreographer: Skipped 310 frames! The application may be doing too much work on its main thread.
02-16 20:56:03.790 1357-1371/? W/ActivityManager: Activity pause timeout for ActivityRecord{d0412ba u0 com.android.launcher3/.Launcher t132}
02-16 20:56:03.800 2332-2332/? I/art: Not late-enabling -Xcheck:jni (already on)
02-16 20:56:03.810 1357-1371/? I/ActivityManager: Start proc 2332:com.example.jahanara.externaldatabase/u0a66 for activity com.example.jahanara.externaldatabase/.MainActivity
02-16 20:56:03.810 2332-2332/? W/System: ClassLoader referenced unknown path: /data/app/com.example.jahanara.externaldatabase-2/lib/x86_64
02-16 20:56:03.910 1005-1122/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
02-16 20:56:03.910 2332-2347/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-16 20:56:04.190 1697-1697/? I/Choreographer: Skipped 51 frames! The application may be doing too much work on its main thread.
02-16 20:56:04.310 2332-2347/? I/OpenGLRenderer: Initialized EGL, version 1.4
02-16 20:56:05.450 1697-1697/? I/Choreographer: Skipped 73 frames! The application may be doing too much work on its main thread.
02-16 20:56:05.740 2332-2347/? W/EGL_emulation: eglSurfaceAttrib not implemented
02-16 20:56:05.740 2332-2347/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f691ce988c0, error=EGL_SUCCESS
02-16 20:56:07.210 2332-2345/? E/Entity Response :: [{"ID":"1","Name":"James Shuttleworth","EmailAddress":"[email protected]","PhoneNo":"07591231231","Department":"Computing","AvailabilityID":"1000"},{"ID":"2","Name":"Mike Morgan","EmailAddress":"[email protected]","PhoneNo":"07594422281","Department":"Computing","AvailabilityID":"1001"},{"ID":"3","Name":"Parveen Samra","EmailAddress":"[email protected]","PhoneNo":"07594423333","Department":"Environment","AvailabilityID":"1002"},{"ID":"4","Name":"Vasile Constantin","EmailAddress":"[email protected]","PhoneNo":"07598811337","Department":"Engineering","AvailabilityID":"1003"},{"ID":"5","Name":"George William","EmailAddress":"[email protected]","PhoneNo":"07897211290","Department":"Engineering","AvailabilityID":"1004"},{"ID":"6","Name":"Amanda Brooks","EmailAddress":"[email protected]","PhoneNo":"07335115226","Department":"Environment","AvailabilityID":"1005"},{"ID":"7","Name":"Sandy Taramonli","EmailAddress":"[email protected]","PhoneNo":"07777222311","Department":"Computing","AvailabilityID":"1006"},{"ID":"8","Name":"Mark Bennett","EmailAddress":"[email protected]","PhoneNo":"07747222441","Department":"Environment","AvailabilityID":"1007"},{"ID":"9","Name":"Amritpal Slaich","EmailAddress":"[email protected]","PhoneNo":"07747722141","Department":"Engineering","AvailabilityID":"1008"},{"ID":"10","Name":"Harminder Kaur","EmailAddress":"[email protected]","PhoneNo":"07669931771","Department":"Engineering","AvailabilityID":"1009"},{"ID":"11","Name":"Leon Smalov","EmailAddress":"[email protected]","PhoneNo":"07734541236","Department":"Computing","AvailabilityID":"1010"},{"ID":"12","Name":"Mark Tyers","EmailAddress":"[email protected]","PhoneNo":"07734529936","Department":"Computing","AvailabilityID":"1011"},{"ID":"13","Name":"Farzana Aslam","EmailAddress":"[email protected]","PhoneNo":"07414622990","Department":"Engineering","AvailabilityID":"1012"},{"ID":"14","Name":"Yih-Ling Hedley","EmailAddress":"[email protected]","PhoneNo":"07552410090","Department":"Engineering","AvailabilityID":"1013"},{"ID":"15","Name":"Abdullahi Ahmed","EmailAddress":"[email protected]","PhoneNo":"07552410091","Department":"Engineering","AvailabilityID":"1014"},{"ID":"16","Name":"Carl Mills","EmailAddress":"[email protected]","PhoneNo":"07552410092","Department":"Design","AvailabilityID":"1015"},{"ID":"17","Name":"Una Malone","EmailAddress":"[email protected]","PhoneNo":"07552410093","Department":"Engineering","AvailabilityID":"1016"},{"ID":"18","Name":"Reda Al Bodour","EmailAddress":"[email protected]","PhoneNo":"07552410094","Department":"Computing","AvailabilityID":"1017"},{"ID":"19","Name":"Phillip Smith","EmailAddress":"[email protected]","PhoneNo":"07552410095","Department":"Computing","AvailabilityID":"1018"},{"ID":"20","Name":"Erik Barrow","EmailAddress":"[email protected]","PhoneNo":"07552410096","Department":"Computing","AvailabilityID":"1019"},{"ID":"21","Name":"Luke Hicks","EmailAddress":"[email protected]","PhoneNo":"07552410097","Department":"Computing","AvailabilityID":"1020"},{"ID":"22","Name":"Ateya Asgar","EmailAddress":"[email protected]","PhoneNo":"07552410098","Department":"Engineering","AvailabilityID":"1021"},{"ID":"23","Name":"Xiang Fei","EmailAddress":"[email protected]","PhoneNo":"07552410099","Department":"Computing","AvailabilityID":"1022"},{"ID":"24","Name":"Zahir Ahmad","EmailAddress":"[email protected]","PhoneNo":"07552410100","Department":"Engineering","AvailabilityID":"1023"},{"ID":"25","Name":"Carey Pridgeon","EmailAddress":"[email protected]","PhoneNo":"07552410101","Department":"Computing","AvailabilityID":"1024"},{"ID":"26","Name":"Hong Guo","EmailAddress":"[email protected]","PhoneNo":"07552410102","Department":"Computing","AvailabilityID":"1025"},{"ID":"27","Name":"Richard Lane","EmailAddress":"[email protected]","PhoneNo":"07552410103","Department":"Environment","AvailabilityID":"1026"},{"ID":"28","Name":"Bill Dunn","EmailAddress":"[email protected]","PhoneNo":"07552410104","Department":"E
02-16 20:56:07.930 1357-1376/? I/ActivityManager: Displayed com.example.jahanara.externaldatabase/.MainActivity: +4s140ms
02-16 20:56:08.130 1697-1828/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f690cc1d750
是什麼意思「犯規獲得數據」? –
您是否嘗試過使用處理程序而不是AsyncTask,或者甚至使用Executor? –
@GabrieleMariotti在運行應用程序時不顯示數據。我可以在它找到數據的日誌貓中看到它,但它不顯示在應用程序中。 – Jay