초보개발자인데 로그좀 봐주시면 감사하겠습니다 .....![](http://www.masterqna.com/android/?qa=blob&qa_blobid=7218132349570726514)
저기 로그에 나와있는 main 41번째 줄 코드도 올려드리겠습니다 ..
package com.example.homework.step09_sendreceiver2;
import android.content.Intent;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setTitle("데이터베이스를 연동한 ListView");
ListView listView=(ListView)findViewById(R.id.listView);
String result=SendByHttp();
String[][] parseData=jsonParserList(result); //json 데이터 파싱
String[] member=new String[parseData.length];
for(int i=0; i<member.length; i++) {
member[i]="이름:" + parseData[i][0]
+" 나이:" + parseData[i][1]
+" 점수:" + parseData[i][2];
}
//listView에 출력------------------------------------------
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, member);
listView.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater menuInflater=getMenuInflater();
menuInflater.inflate(R.menu.menu1, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId())
{
case R.id.listAll:
Intent intent1=new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent1);
break;
case R.id.insert:
Intent intent2=new Intent(getApplicationContext(), InsertActivity.class);
startActivity(intent2);
break;
}
return false;
}
// 서버에 데이터를 보내는 메소드
private String SendByHttp() {
String strUrl = "http://192.168.43.185:8888/step9_MyServer/JSONServerList.jsp";
HttpClient client = HttpClientBuilder.create().build();
HttpGet get=new HttpGet(strUrl);
try {
//데이터 보낸 뒤 서버에서 데이터를 받아오는 과정
HttpResponse response = client.execute(get);
BufferedReader bufreader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),"utf-8"));
String line = null;
String result = "";
while ((line = bufreader.readLine()) != null) {
result += line;
}
return result;
} catch (Exception e) {
e.printStackTrace();
client.getConnectionManager().shutdown();
return "";
}
}
//받은 JSON 객체를 파싱하는 메소드
private String[][] jsonParserList(String pRecvServerPage) {
Log.i("서버에서 받은 전체 내용 : ", pRecvServerPage);
try {
JSONObject json = new JSONObject(pRecvServerPage);
JSONArray jArr = json.getJSONArray("List");
// 받아온 pRecvServerPage를 분석하는 부분
String[] jsonName = {"name", "age", "score"};
String[][] parseredData = new String[jArr.length()][jsonName.length];
for (int i = 0; i < jArr.length(); i++) {
json = jArr.getJSONObject(i);
for (int j = 0; j < jsonName.length; j++) {
parseredData[i][j] = json.getString(jsonName[j]);
}
}
// 분해 된 데이터를 확인하기 위한 부분
for (int i = 0; i < parseredData.length; i++) {
Log.i("JSON을 분석한 데이터 " + i + " : ", parseredData[i][0]);
Log.i("JSON을 분석한 데이터 " + i + " : ", parseredData[i][1]);
Log.i("JSON을 분석한 데이터 " + i + " : ", parseredData[i][2]);
}
return parseredData;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}