The whole process of my debugging today
1, Android found not even on the local tomcat2, using the browser to try directly, found that can be connected to 3, the suspicion is Android app and browser access is different, after the Internet search is not the app, only the browser is trying to change the IP, I should change all changed, or not 4, reflect the two kinds of access should be the same , is a URL request encapsulation, one is a manual encapsulation, a browser to you encapsulated 5, since it is not the problem, what is the problem, do not know 6, and then start Baidu, Baidu a bit, useless, no results 7, and then Google, there are suggestions city a thread or open a service, Thinking or the new startup thread is simple 8, so start writing, but the process of writing forget local variables if in the internal class object method used to satisfy what relationship, while the final modified local variables (reference or basic type) is variable, so on the web search, all said is not very clear. 9, so decided to write their own Demo10, wrote when they found a problem, has been and expected results inconsistent, so has been single-step debugging 11, with step over to each step also can not see what the specific cause of the output, as if the output is out of thin air, suddenly think of a situation, My eclipse now open two debugging projects, will not have an impact, so immediately turn off another Web service to find out the output is normal, no definition of output, but the output sequence is not correct, in a moment, I think of multithreading concurrency, and then a join () function to wait for the list to add Added to the end, and then it was normal together. 12 and then started writing my Android networking test case.
watch out.1,android main thread inside can not connect Network 2, there is a problem Google, there is a problem to do 3, there is a problem single-step to see 4,eclipse can not start at the same time a few debugging 5, cool thinking, check information, bold conjecture.
The following is the test source
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);
}
}
The following is the problem of the network connection part of the Android code, the purpose is to take the JSON from the server to the list returned, where Newsservice.getlastnews () will be enabled network connection, the implementation is not posted
Private ListFinal listthread 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;
}
Android test Local Service debugging process