public class MainActivity extends AppCompatActivity {
String latitude;
String longitude;
Double a;
Double b;
String id;
String check_id_url = "http://limgaram1201.cafe24.com/kid_protector/get_nowlocation.jsp";
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
id_check();
textView.setText(latitude);
}
public void id_check() {
// call data from web URL
try {
ConnectivityManager conManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conManager.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
new CheckTask().execute(check_id_url);
} else {
Toast toast = Toast.makeText(getApplicationContext(), "Network isn't connected", Toast.LENGTH_LONG);
toast.show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private class CheckTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... arg0) {
try {
return (String) checkData((String) arg0[0]);
} catch (Exception e) {
return "Json upload failed";
}
}
protected void onPostExecute(String result) {
StringBuffer sb = new StringBuffer();
try {
JSONArray jArray = new JSONArray(result);
String[] jsonName = {"latitude","longitude"};
String[][] parsedData = new String[jArray.length()][jsonName.length];
JSONObject json = null;
for (int i = 0; i < jArray.length(); i++) {
json = jArray.getJSONObject(i);
if (json != null) {
for (int j = 0; j < jsonName.length; j++) {
parsedData[i][j] = json.getString(jsonName[j]);
}
}
}
for (int i = 0; i < parsedData.length; i++) {
//readView.setText(result); //json타입으로 출력
sb.append(parsedData[i][0]);
sb.append(parsedData[i][1]);
latitude = parsedData[i][0];
longitude = parsedData[i][1];
textView.setText(latitude);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
private String checkData(String strUrl) {
StringBuffer sb = new StringBuffer();
StringBuilder builder = new StringBuilder();
try {
Intent getIntent = getIntent();
id = getIntent.getStringExtra("id");
URL url = new URL(check_id_url+"?id="+id);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
if(con != null) {
con.setConnectTimeout(10000);
con.setUseCaches(false);
if(con.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
while(true) {
String line = reader.readLine();
if(line==null)
break;
builder.append(line+"\n");
}
reader.close();
}
con.disconnect();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}
}
}
DB에저장된 latitude longitude값을 읽어와 텍스트뷰로보여주려하는대
실행시키면 에러가나고 앱이꺼집니다. 제가 보기엔 코드엔문제없고 jsp쪽문제같은대 jsp도 원하시면 첨부해드릴께요 부탁드립니다 ㅜㅜ