标签:
我今天调试的整个过程
package test.OO.innerClass.innerClassObject;
import java.util.ArrayList;
import java.util.List;
public class testLocalVariableInFunction {
public static void main(String [] args){
final List<String> list = new ArrayList<String>();
list.add("kitty");
System.out.println("1,"+list);
Thread t1 = new Thread(new Runnable(){
public void run(){
System.out.println("2,"+list);
list.add("raoxiang");
System.out.println("3,"+list);
list.add("yan");
System.out.println("4,"+list);
}
});
// Thread t1 = new Thread(){
// public void run(){
// System.out.println("2,"+list);
// list.add("raoxiang");
// System.out.println("3,"+list);
// list.add("yan");
// System.out.println("4,"+list);
//
// }
// };
t1.start();
System.out.println("5,************************end1");
try {
t1.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("6,************************end2");
System.out.println("7"+list);
}
}
t1.start();
System.out.println("5,************************end1");
try {
t1.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("6,************************end2");
System.out.println("7"+list);
}
}
以下是解决问题后的网络连接部分的android代码,目的是从服务器取json转换为list返回,其中 NewsService.getLastNews()会启用网络连接,具体实现就不贴了
private List<HashMap<String,Object>> getNewes(){
final List<HashMap<String,Object>> data = new ArrayList<HashMap<String,Object>>();
Thread t1 = new Thread(){
@Override
public void run() {
try {
List<News> newes = NewsService.getLastNews();
for(News news : newes ){
HashMap<String,Object> item = new HashMap<String,Object>();
item.put("title",news.getTitle());
item.put("timelength",news.getTimelength());
data.add(item);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
t1.start();
try {
t1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
return data ;
}
标签:
原文地址:http://www.cnblogs.com/luoziyihao/p/4471354.html