1

その2番目のtry/catchブロック。Logcatはまだlogingsize <=0です。サーバーからの応答はあります。なぜそれが起こっているのか理解できません。誰か助けてもらえますか?もしそうなら、このリポジトリを処理する正しい方法を教えていただけますか?

public class MainActivity extends Activity implements OnClickListener {

    TextView tv;
    EditText et;
    String barcode;
    String url = null;

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv = (TextView) findViewById(R.id.textView1);
    et = (EditText) findViewById(R.id.editText1);
    Button btn = (Button) findViewById(R.id.b1);
    btn.setOnClickListener(this);

}


@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.b1:

    // create URL------------------
    barcode = et.getText().toString();
    StringBuilder sb = new StringBuilder("http://cathedralbc.web44.net/firstPHPfile.php?item=");
    sb.append(barcode);
    url= sb.toString();
    //-----------------------------

    new DoInBackGround().execute(url);

    break;

default:
    break;
    }

}



public class DoInBackGround extends AsyncTask<String, Void, String> {

String urlComplete;
BufferedReader br = null;
String result = "";


@Override
protected String doInBackground(String... params) {

    this.urlComplete = params[0];

    return getDataFrom();
}



final String getDataFrom(){


        try {
            HttpClient client = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(urlComplete);
            HttpResponse response = client.execute(httpPost);
            HttpEntity entity = response.getEntity();
            InputStream InEntity = entity.getContent();
            Log.i("log_tag", "READING1  " + InEntity.toString());   
            try{

                BufferedReader bufferInEtity = new BufferedReader(new InputStreamReader(InEntity,"iso-8859-1"),0);
                StringBuilder sbResponse = new StringBuilder();
                String line = null;
                while ((line = bufferInEtity.readLine()) != null) {
                    sbResponse.append(line + "\n");

                    }

            InEntity.close();
            result = sbResponse.toString();

                }catch(Exception e){
                Log.e("log_tag", "READING  " + e.getMessage()); 
            }

        } catch (Exception e) {
        Log.e("log_tag", "HTTPCLIENT  " + e.getMessage());
        } 

    return result;


}
@Override
protected void onPostExecute(String result) {

    try {
        JSONArray jArray = new JSONArray(result);
        for(int i=0; i<jArray.length(); i++){
            JSONObject jsonOBJ = jArray.getJSONObject(i);
            tv.setText(jsonOBJ.getInt("name"));
        }



    } catch (JSONException e) {
        Log.e("log_tag", "JSONArray  " + e.getMessage());
    }


    }

}


}
4

0 に答える 0