httppost 代码编写问题...
求各位大神给看看
Activityprivate Button mButton1,mButton2; private TextView mTextView1; private JoyHttp j;@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /*透过findViewById建构子建立TextView与Button对象*/ mButton1 =(Button) findViewById(R.id.myButton1); mButton2 =(Button) findViewById(R.id.myButton2); mTextView1 = (TextView) findViewById(R.id.myTextView1); /*设定OnClickListener来聆听OnClick事件*/ mButton1.setOnClickListener(new Button.OnClickListener() { /*重写onClick事件*/ @Override public void onClick(View v) { /*声明网址字符串*/ String uriAPI = "http://localhost:8080"; String message = "123";// post(uriAPI); mTextView1.setText(j.post(uriAPI,message)); } }); Postpublic String post(String uriAPI, String message) { String fal = "fal"; HttpPost httpRequest = new HttpPost(uriAPI); try { /* 发出HTTP request */ httpRequest.setEntity(new StringEntity(message)); // httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); /* 取得HTTP response */ HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); /* 若状态码为200 ok */ if (httpResponse.getStatusLine().getStatusCode() == 200) { /* 取出响应字符串 */ String strResult = EntityUtils.toString(httpResponse.getEntity()); // mTextView1.setText(strResult); return strResult; } // else // { // mTextView1.setText("Error Response: "+httpResponse.getStatusLine().toString()); // } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return fal; }
09-24 15:39:47.529: E/AndroidRuntime(14810): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
09-24 15:39:47.529: E/AndroidRuntime(14810): ... 11 more
这该怎么改..
[解决办法]
at irdc.EX08_01.EX08_01.onCreate(EX08_01.java:50)
没有初始化吧
[解决办法]
空指针这种错误,你把那一行找出来啊。
[解决办法]
第50行空指针