E / AndroidRuntime(1163):致命异常:主要

时间:2013-07-18 12:34:25

标签: php android

这是我的代码,

  

我想在我的服务器中执行menurestaurant.php(apache tomcat)   连接到数据库,我认为问题出在服务器上   地址

public class Menu2 extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.i("","avantOnCreateMenu2");
        super.onCreate(savedInstanceState);
        Log.i("","OnCreateMenu2");
        //setContentView(R.layout.activity_menu2);
        String result = null;
         InputStream is = null;
         JSONObject json_data=null;
         ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
         ArrayList<String> donnees = new ArrayList<String>();
         try{

             Log.i("","avantappelphp");
             //commandes httpClient
                HttpClient httpclient = new DefaultHttpClient();
               HttpPost httppost = new HttpPost("http://10.0.2.2:8080/menurestaurant.php");
                Log.i("","apresappelphp");
               httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              HttpResponse response = httpclient.execute(httppost);



                HttpEntity entity = response.getEntity();
                is = entity.getContent();
             }
             catch(Exception e){
              Log.i("taghttppost",""+e.toString());
                    Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
               }


             //conversion de la réponse en chaine de caractère
                try
                {
                 BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));

                 StringBuilder sb  = new StringBuilder();

                 String line = null;

                 while ((line = reader.readLine()) != null)
                 {
                 sb.append(line + "\n");
                 }

                 is.close();

                 result = sb.toString();
                }
                catch(Exception e)
                {
                 Log.i("tagconvertstr",""+e.toString());
                }
                //recuperation des donnees json
                try{
                  JSONArray jArray = new JSONArray(result);

                     for(int i=0;i<jArray.length();i++)
                     {

                           json_data = jArray.getJSONObject(i);
                           donnees.add(json_data.getString("nom"));
                           //r.add(json_data.getString("categorie"));

                       }
                        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, donnees));
                    }
                    catch(JSONException e){
                     Log.i("tagjsonexp",""+e.toString());
                    } catch (ParseException e) {
                     Log.i("tagjsonpars",""+e.toString());
               }

            }
        }

这是我的日志:

07-18 12:10:04.997: D/dalvikvm(1163): GC_FOR_ALLOC freed 47K, 7% free 2614K/2792K, paused 54ms, total 58ms
07-18 12:10:05.027: I/dalvikvm-heap(1163): Grow heap (frag case) to 3.283MB for 635812-byte allocation
07-18 12:10:05.117: D/dalvikvm(1163): GC_FOR_ALLOC freed 2K, 6% free 3233K/3416K, paused 86ms, total 86ms
07-18 12:10:05.207: D/dalvikvm(1163): GC_CONCURRENT freed <1K, 5% free 3248K/3416K, paused 10ms+5ms, total 93ms
07-18 12:10:05.547: I/Choreographer(1163): Skipped 62 frames!  The application may be doing too much work on its main thread.
07-18 12:10:05.607: D/gralloc_goldfish(1163): Emulator without GPU emulation detected.
07-18 12:10:21.777: I/(1163): avantSwitch
07-18 12:10:21.848: I/(1163): apresSwitch
07-18 12:10:21.848: I/Choreographer(1163): Skipped 38 frames!  The application may be doing too much work on its main thread.
07-18 12:10:22.007: I/(1163): avantOnCreateMenu2
07-18 12:10:22.007: I/(1163): OnCreateMenu2
07-18 12:10:22.017: I/(1163): avantappelphp
07-18 12:10:22.107: I/(1163): apresappelphp
07-18 12:10:22.668: I/taghttppost(1163): android.os.NetworkOnMainThreadException
07-18 12:10:22.877: D/dalvikvm(1163): GC_CONCURRENT freed 141K, 8% free 3543K/3816K, paused 71ms+117ms, total 413ms
07-18 12:10:22.947: I/tagconvertstr(1163): java.lang.NullPointerException: lock == null
07-18 12:10:22.988: D/AndroidRuntime(1163): Shutting down VM
07-18 12:10:22.997: W/dalvikvm(1163): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-18 12:10:23.147: E/AndroidRuntime(1163): FATAL EXCEPTION: main
07-18 12:10:23.147: E/AndroidRuntime(1163): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.catalogue/com.example.catalogue.Menu2}: java.lang.NullPointerException
07-18 12:10:23.147: E/AndroidRuntime(1163):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-18 12:10:23.147: E/AndroidRuntime(1163):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-18 12:10:23.147: E/AndroidRuntime(1163):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-18 12:10:23.147: E/AndroidRuntime(1163):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-18 12:10:23.147: E/AndroidRuntime(1163):     at android.os.Handler.dispatchMessage(Handler.java:99)

我使用@IP并没有改变任何帮助我的事情

0 个答案:

没有答案