当前位置: 代码迷 >> Eclipse >> eclipse顶用线程 为什么在start后不运行RUN中程序
  详细解决方案

eclipse顶用线程 为什么在start后不运行RUN中程序

热度:5   发布时间:2016-04-23 00:53:04.0
eclipse中用线程 为什么在start后不运行RUN中程序
程序如下帮忙分析下:

为什么不执行RUN中的程序

public void Onclick_button1(View view)
{
EditText editview1 = (EditText) findViewById(R.id.editview2);
  TextView text = (TextView) findViewById(R.id.textView1);
final String name1 = editview1.getText().toString();//此时name是一个string类型

Thread th = new Thread(new Runnable()
{
@Override
public void run()
{
String name = name1;
String ak = "v5EmLKE9gcVPK9pXFqar5gfX";
String geotype = "1";
String is_published = "1";
String url = "http://api.map.baidu.com/geodata/v2/geotable/create";
int liret = -1;

try
{
    DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
    HttpPost localHttpPost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name",name));
params.add(new BasicNameValuePair("ak",ak));
params.add(new BasicNameValuePair("geotype",geotype));
params.add(new BasicNameValuePair("is_published",is_published));

UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params,"UTF-8");
localHttpPost.setEntity(entity);
HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpPost);
String resp = EntityUtils.toString(localHttpResponse.getEntity());
JSONObject jsonObject = new JSONObject(resp);
Log.v("KKHP", resp);
String statuscode = jsonObject.getString("status");
String statusmsg = jsonObject.getString("message");
String id = jsonObject.getString("id");
Myapp myapp = (Myapp) getApplicationContext();

liret = Integer.parseInt(statuscode);

if(0==liret)
{
myapp.message = statusmsg;
myapp.status = statuscode;
myapp.id = id;
return;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}

});
th.start();
------解决方案--------------------
结构看上去没问题。有报什么错没
------解决方案--------------------
看看是否调用了这个Onclick_button2方法
  相关解决方案