0

我正在动态生成表格行以填充来自我的 Android 版本的 json 数据:4.2

这是我的代码:

try {
                   //HttpResponse response = httpClient.execute(httpGet, localContext);
                   HttpResponse response = httpClient.execute(httpGet, localContext);
                   HttpEntity entity = response.getEntity();

                       text = getASCIIContentFromEntity(entity);


                   //InputStream input = new BufferedInputStream( response.getEntity().getContent() );


                       JSONArray ja = new JSONArray(text) ;
                       // ITERATE THROUGH AND RETRIEVE CLUB FIELDS
                                    int n = ja.length();
                                    for (int i = 0; i < n; i++) {
                                        // GET INDIVIDUAL JSON OBJECT FROM JSON ARRAY
                                     JSONObject jo = ja.getJSONObject(i);

                                     title= jo.getString("Title");
                                     url= jo.getString("URL");
                                     desc.add(jo.getString("Description"));                             



                                    }
             } catch (Exception e) {
                         e.getLocalizedMessage();
                       }


             return desc;                


        }   

        protected void onPostExecute(ArrayList<String> desc) {
            int count=0;
            TableLayout tl;
            TableRow tr;

            tl=(TableLayout)findViewById(R.id.tableLayout1);

            if (desc!=null) {


                    for (int current = 0; current < desc.size(); current++) {

                     tr = new TableRow(VideoCategory.this);


                    TextView tv2 = (TextView)findViewById(R.id.vtext2);
                    tv2.setText(desc.get(count));

                    tr.addView(tv2);



                     tl.addView(tr, new TableLayout.LayoutParams(
                     LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));



                }
            }
            }

输出: 它说:

没想到应用程序已停止

这是我的日志猫:

01-11 16:01:03.452: I/Process(548): Sending signal. PID: 548 SIG: 9
01-11 16:01:03.795: I/WindowManager(59): WIN DEATH: Window{44013600 com.example.erpsecurity/com.example.erpsecurity.SecurityOnline paused=false}
01-11 16:01:03.795: I/ActivityManager(59): Process com.example.erpsecurity (pid 548) has died.
01-11 16:01:03.803: I/WindowManager(59): WIN DEATH: Window{43fee618 com.example.erpsecurity/com.example.erpsecurity.Login paused=false}
01-11 16:01:03.842: I/ActivityManager(59): Start proc com.example.erpsecurity for activity com.example.erpsecurity/.SecurityOnline: pid=564 uid=10037 gids={3003}
01-11 16:01:03.862: I/WindowManager(59): WIN DEATH: Window{440c11a8 com.example.erpsecurity/com.example.erpsecurity.VideoCategory paused=false}
01-11 16:01:03.862: I/WindowManager(59): WIN DEATH: Window{44021798 com.example.erpsecurity/com.example.erpsecurity.FreeCategory paused=false}
01-11 16:01:04.002: I/UsageStats(59): Unexpected resume of com.example.erpsecurity while already resumed in com.example.erpsecurity
01-11 16:01:04.859: D/dalvikvm(564): GC_EXTERNAL_ALLOC freed 854 objects / 61840 bytes in 183ms
01-11 16:01:05.202: W/ActivityManager(59): Activity destroy timeout for HistoryRecord{43fc4668 com.example.erpsecurity/.VideoCategory}
01-11 16:01:05.702: W/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 548 uid 10037
01-11 16:01:05.863: I/ActivityManager(59): Displayed activity com.example.erpsecurity/.SecurityOnline: 2068 ms (total 2068 ms)
01-11 16:04:58.495: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
01-11 16:09:58.509: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
01-11 16:14:58.574: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
01-11 16:18:25.153: I/ActivityManager(59): Starting activity: Intent { cmp=com.example.erpsecurity/.FreeCategory }
01-11 16:18:25.383: D/dalvikvm(564): GC_EXTERNAL_ALLOC freed 2682 objects / 155896 bytes in 99ms
01-11 16:18:26.592: D/dalvikvm(564): GC_EXTERNAL_ALLOC freed 1449 objects / 65872 bytes in 54ms
01-11 16:18:27.023: I/ActivityManager(59): Displayed activity com.example.erpsecurity/.FreeCategory: 1809 ms (total 1809 ms)
01-11 16:19:58.628: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
01-11 16:24:58.687: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
01-11 16:28:35.442: D/AndroidRuntime(572): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
01-11 16:28:35.442: D/AndroidRuntime(572): CheckJNI is ON
01-11 16:28:37.163: D/AndroidRuntime(572): --- registering native functions ---
01-11 16:28:38.753: D/dalvikvm(251): GC_EXPLICIT freed 167 objects / 8464 bytes in 58ms
01-11 16:28:54.824: D/PackageParser(59): Scanning package: /data/app/vmdl50860.tmp
01-11 16:28:56.398: D/dalvikvm(59): GC_FOR_MALLOC freed 15803 objects / 870720 bytes in 660ms
01-11 16:29:05.996: D/dalvikvm(251): GC_EXPLICIT freed 119 objects / 9872 bytes in 142ms
01-11 16:29:07.145: I/PackageManager(59): Removing non-system package:com.example.erpsecurity
01-11 16:29:07.145: I/ActivityManager(59): Force stopping package com.example.erpsecurity uid=10037
01-11 16:29:07.263: I/Process(59): Sending signal. PID: 564 SIG: 9
01-11 16:29:07.263: I/ActivityManager(59):   Force finishing activity HistoryRecord{4405b650 com.example.erpsecurity/.SecurityOnline}
01-11 16:29:07.263: I/ActivityManager(59):   Force finishing activity HistoryRecord{43f834f8 com.example.erpsecurity/.Login}
01-11 16:29:07.374: I/WindowManager(59): WIN DEATH: Window{4404bd38 com.example.erpsecurity/com.example.erpsecurity.FreeCategory paused=false}
01-11 16:29:07.374: I/WindowManager(59): WIN DEATH: Window{44114388 com.example.erpsecurity/com.example.erpsecurity.SecurityOnline paused=true}
01-11 16:29:07.423: I/UsageStats(59): Unexpected resume of com.android.launcher while already resumed in com.example.erpsecurity
01-11 16:29:07.834: W/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 564 uid 10037
01-11 16:29:08.272: D/PackageManager(59): Scanning package com.example.erpsecurity
01-11 16:29:08.272: I/PackageManager(59): Package com.example.erpsecurity codePath changed from /data/app/com.example.erpsecurity-2.apk to /data/app/com.example.erpsecurity-1.apk; Retaining data and using new
01-11 16:29:08.288: I/PackageManager(59): /data/app/com.example.erpsecurity-1.apk changed; unpacking
01-11 16:29:08.313: D/installd(35): DexInv: --- BEGIN '/data/app/com.example.erpsecurity-1.apk' ---
01-11 16:29:10.862: D/dalvikvm(579): DexOpt: load 802ms, verify 1003ms, opt 28ms
01-11 16:29:10.912: D/installd(35): DexInv: --- END '/data/app/com.example.erpsecurity-1.apk' (success) ---
01-11 16:29:10.912: W/PackageManager(59): Code path for pkg : com.example.erpsecurity changing from /data/app/com.example.erpsecurity-2.apk to /data/app/com.example.erpsecurity-1.apk
01-11 16:29:10.912: W/PackageManager(59): Resource path for pkg : com.example.erpsecurity changing from /data/app/com.example.erpsecurity-2.apk to /data/app/com.example.erpsecurity-1.apk
01-11 16:29:10.912: D/PackageManager(59):   Activities: com.example.erpsecurity.Login com.example.erpsecurity.SecurityOnline com.example.erpsecurity.FreeCategory com.example.erpsecurity.PaidCategory com.example.erpsecurity.PrivilegeCategory com.example.erpsecurity.SwitchCategory com.example.erpsecurity.VideoCategory com.example.erpsecurity.PdfCategory com.example.erpsecurity.PaidVideo com.example.erpsecurity.PaidPdf com.example.erpsecurity.GridView com.example.erpsecurity.PrivilegeAdapter com.example.erpsecurity.PrivilegeVideo com.example.erpsecurity.PrivilegePdf com.example.erpsecurity.VideoPage
01-11 16:29:10.933: I/ActivityManager(59): Force stopping package com.example.erpsecurity uid=10037
01-11 16:29:11.082: I/installd(35): move /data/dalvik-cache/data@app@com.example.erpsecurity-1.apk@classes.dex -> /data/dalvik-cache/data@app@com.example.erpsecurity-1.apk@classes.dex
01-11 16:29:11.082: D/PackageManager(59): New package installed in /data/app/com.example.erpsecurity-1.apk
01-11 16:29:11.292: I/ActivityManager(59): Force stopping package com.example.erpsecurity uid=10037
01-11 16:29:11.422: D/dalvikvm(126): GC_EXPLICIT freed 78 objects / 3880 bytes in 114ms
01-11 16:29:11.523: D/dalvikvm(59): GC_EXPLICIT freed 13166 objects / 702256 bytes in 166ms
01-11 16:29:12.672: D/dalvikvm(59): GC_EXPLICIT freed 7538 objects / 370168 bytes in 346ms
01-11 16:29:12.783: D/dalvikvm(159): GC_EXPLICIT freed 2276 objects / 116080 bytes in 1150ms
01-11 16:29:14.303: W/RecognitionManagerService(59): no available voice recognition services found
01-11 16:29:15.693: I/installd(35): unlink /data/dalvik-cache/data@app@com.example.erpsecurity-2.apk@classes.dex

任何人请提前向我推荐解决方案谢谢。

4

1 回答 1

0

替换这一行

tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

有了这个

tl.addView(tr,t1.getChildCount(), new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
于 2013-01-11T11:35:03.067 回答