안드로이드 개발 질문/답변
(글 수 45,052)
public class CharsettestActivity extends Activity {
static String Get_http ="http://www.google.co.kr";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView ewfi = (TextView)findViewById(R.id.textView1);
String bb = null;
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(Get_http);
HttpResponse response = null;
try {
response = httpclient.execute(httpGet);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpEntity resEntity = response.getEntity();
try {
bb = EntityUtils.toString(resEntity);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ewfi.setText(bb);
}
}전혀 문제가 없어 보이는(제 생각에) 코드인데, 컴파일하고 실행하면 에러가 나옵니다.
똑같은 코드를 복사 붙여넣기로 버튼 메쏘드에 할당하고 사용중인데 그거는 잘 됩니다.
디버그 모드로 보니 java.lang.nullpointException 오류가 나옵니다.
response = httpclient.execute(httpGet); 이 코드를 이용해서 response값에 할당이 되어야 하는데 할당이 안되고 null입니다.
이유가 뭔지 모르겠습니다.




아... 멍청하게도..
AndroidManifest.xml
에 퍼미션을 주지 않았네요 ㅠ.ㅠ