Android testing local service debugging process and android debugging process
The entire debugging process today
1. Android finds that it cannot connect to the local Tomcat 2, and uses a browser to directly try it. It may be connected to 3. It is suspected that there is a difference between the Android APP and the browser, and no APP can be found on the Internet, only the browser tries not to change the IP address. I should have changed all the changes, but I still cannot do it. 4. reflection that the two types of access should be the same, both of which are encapsulation of url requests, one is manual encapsulation, and the other is 5 encapsulated by the browser. Since it is not the problem, what is the problem? I don't know 6. Then I started Baidu and Baidu. It's useless, no result 7 is used, and then google, there is a suggestion to start a new thread or start a service, think about whether it is 8 simple to start a new thread, so handwriting, however, during the write process, the local variables are forgotten. If the relationship to be satisfied is used in the internal Class Object method, and whether the local variables (reference or basic type) modified by final are variable, so I searched the internet and said it was not clear. 9. I decided to write Demo10 by myself. I found another problem during the writing, which was inconsistent with the expected results. So I had to debug it in one step for 11, when I use step over to each step, I cannot see the specific cause of the output. It seems that the output is out of thin air. Suddenly, I think of a situation where two debugging projects are open in eclipse, will there be any impact, so I immediately turned off another web Service and found that the output was normal. There was no output out of definition, but the output sequence was wrong. In an instant, I thought of multi-thread concurrency, therefore, a join () function is used to wait for the list to be added, and then it will work normally together. 12. Then I began to write my android networking test case.
Notes1. The main thread of android cannot connect to Network 2. If there is a problem with google, you can do it yourself. 3. If there is a problem with one-step debugging, you can step by step. 4. eclipse cannot start several debugging at the same time. 5, think calmly, query data, and boldly guess.
The following is the test source code.
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 android code for network connection after the problem is solved. The purpose is to convert the json value from the server to the list and return the result. NewsService. getLastNews () will enable the network connection.
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;
}