Java 错误NullPointerException:锁==null

Java 错误NullPointerException:锁==null,java,android,Java,Android,有人能帮我解决这个错误吗?当我运行应用程序并搜索ID时,请选择MySQL数据库到Android的值,它总是说(无效IP地址) 我的web服务器上有一个PHP文件,它连接到WampServer数据库并检索返回到Android应用程序的值 String id String name; InputStream is=null; String result=null; String line; @Override public void onCreate(Bundle savedInstanceSta

有人能帮我解决这个错误吗?当我运行应用程序并搜索ID时,请选择MySQL数据库到Android的值,它总是说(无效IP地址)

我的web服务器上有一个PHP文件,它连接到WampServer数据库并检索返回到Android应用程序的值

String id
String name;
InputStream is=null;
String result=null;
String line;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final EditText e_id=(EditText) findViewById(R.id.editText1);
    Button select=(Button) findViewById(R.id.button1);
    select.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        id=e_id.getText().toString();
        select();
    }
});
}

public void select()
{
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

nameValuePairs.add(new BasicNameValuePair("id",id));

    try
    {
    HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2/test/select.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost); 
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        Log.e("pass 1", "connection success ");
}
    catch(Exception e)
{
        Log.e("Fail 1", e.toString());
        Toast.makeText(getApplicationContext(), "Invalid IP Address",
        Toast.LENGTH_LONG).show();
}     

    try
    {
        BufferedReader reader = new BufferedReader
            (new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            while ((line = reader.readLine()) != null)
    {
            sb.append(line + "\n");
        }
            is.close();
            result = sb.toString();
        Log.e("pass 2", "connection success ");
}
    catch(Exception e)
    {
    Log.e("Fail 2", e.toString());
}     

try
    {
        JSONObject json_data = new JSONObject(result);
        name=(json_data.getString("name"));
    Toast.makeText(getBaseContext(), "Name : "+name,
        Toast.LENGTH_SHORT).show();
    }
    catch(Exception e)
    {
        Log.e("Fail 3", e.toString());
    }
}
感谢您的帮助

E/Fail 1(1073): android.os.NetworkOnMainThreadException
引发此错误的原因是您在主活动的线程上运行网络连接调用(如
httpclient
)。为了摆脱这种情况,您需要为这些调用使用另一个线程。这样做的简单方法是使用

E/Fail 1(1073): android.os.NetworkOnMainThreadException