JSON을 사용하여 인터넷의 PHP 파일에서 데이터를 가져 오려고합니다. 그것은 정상적인 클래스에서 작동하지만 조각을 사용할 때 작동하지 않습니다.안드로이드 조각 http 응답
public static class MagFragment extends Fragment {
public static final String ARG_MAGAZINE_NUMBER = "magazine_number";
public MagFragment() {
// Empty constructor required for fragment subclasses
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
if(i != 0){
rootView = inflater.inflate(R.layout.fragment_magazine, container, false);
TextView magText = (TextView) rootView.findViewById(R.id.textViewMag);
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://csddata.site11.com");
HttpResponse response = httpclient.execute(httppost);
HttpEntity httpEntity = response.getEntity();
InputStream inputstream = httpEntity.getContent();
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(inputstream,"iso-8859-1"),8);
magText.setText(reader.readLine());
}catch (Exception e){
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return rootView;
}
}
정상적인 클래스에서 작동하므로 조각이기 때문에 사용해야합니다.
나는 오류를 복사하여 붙여 넣기가 뜨겁지 않지만 오류가 발생한 행을 말한 유일한 오류는 "HttpResponse response = httpclient.execute (httppost);"입니다. 선!
그것은 할 수 있습니까? –
Eclipse를 사용하는 경우 log cat으로 이동하여 복사 할 행을 선택하고 다른 것과 마찬가지로 복사 할 수 있습니다. 그리고 그 작동하지 않는 경우 오류의 첫 번째 줄을 적어도 다시 입력하십시오 ... – PearsonArtPhoto
가능한 중복 [android.os.NetworkOnMainThreadException] (http://stackoverflow.com/questions/6343166/android-os- networkonmainthreadexception) – Jave