Aotentar executar 一个类 ConectPhp
Meu LogCat traz o seguinte 错误:
错误 ao 转换器 resultado java.lang.NullPointerException
public class ConectPhp extends ListActivity {
public static InputStream inpStrin = null;
String result = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<NameValuePair> parametros = new ArrayList<NameValuePair>();
parametros.add(new BasicNameValuePair("DATA", "2011-11-05"));
try{
HttpClient httpcliente = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.254.15/mobile/ConexaoWcrm.php/");
httppost.setEntity(new UrlEncodedFormEntity(parametros));
HttpResponse response = httpcliente.execute(httppost);
HttpEntity entity = response.getEntity();
} catch (Exception e){
Log.e("log_tag", "Erro em conectar a "+e.toString());
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(inpStrin, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
sb.append(line+"\n");
}
inpStrin.close();
result=sb.toString();
}catch (Exception e){
Log.e("log_tag","Erro ao converter resultado"+e.toString());
}
try{
JSONArray jArray = new JSONArray(result);
String[] clientes = new String[jArray.length()];
for(int i=0; i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
clientes[i]=json_data.getString("clientnome");
}
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, clientes));
}catch(Exception e){
Log.e("log_tag","Erro ao popular os dados "+e.toString());
}
setContentView(R.layout.conectphp);
}}
Estrou testando uma conexão com um banco de dados externo para listra seus dados na tela do Android。