다음 코드를 사용하면 오류는 없지만 정지 시간이 있습니다.AsyncTask 내의 텍스트 뷰에서 java.lang.NullPointerException이 발생했습니다.
`@Override 보호 공극에서 onCreate (번들 savedInstanceState) {// TODO 방법 스텁 super.onCreate (savedInstanceState) 자동 생성; StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder(). permitAll(). build(); StrictMode.setThreadPolicy (policy); setContentView (R.layout.profilepic); 나는이 같은 AsyncTask를하고해서 ProgressDialog이 코드를 사용하는 경우
initialize();
Bundle bundle = getIntent().getExtras();
email = bundle.getString("Email");
ArrayList<NameValuePair> postParameters;
String response = null;
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("emaillog", email));
try {
response = CustomHttpClient.executeHttpPost("http://whatstherex.info/checkU.php", postParameters);
res = response.toString();
res = res.replaceAll("null", "");
username = res.toString();
tvProfilePic.setText("Hi " + username + ", you are encourage to add a profile picture.");
}catch(Exception e){
res = e.toString();
tvProfilePic.setText(res);
}
}`
는하지만 :
`@Override는 보호 무효에서 onCreate (번들 savedInstanceState) { // TODO 자동 생성 방법은 스텁 super.onCreate (savedInstanceState); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder(). permitAll(). build(); StrictMode.setThreadPolicy (policy); setContentView (R.layout.profilepic);
initialize();
getUsername();
}
개인 AsyncTask를 작업;
public void getUsername(){
Bundle bundle = getIntent().getExtras();
email = bundle.getString("Email");
task = new AsyncTask<String, Void, String>() {
ProgressDialog dialog;
ArrayList<NameValuePair> postParameters;
String response = null;
@Override
protected void onPreExecute() {
//
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("emaillog", email));
dialog = new ProgressDialog(Profilepic.this, ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Loading Data...");
dialog.show();
}
@Override
protected String doInBackground(String... params) {
//
try {
response = CustomHttpClient.executeHttpPost("http://whatstherex.info/checkU.php", postParameters);
res = response.toString();
res = res.replaceAll("null", "");
username = res.toString();
return username;
}catch(Exception e){
res = e.toString();
return res;
}
}
@Override
protected void onPostExecute(String result) {
if(result.length()< 25){
username = result;
tvProfilePic.setText("Hi " + result + ", you are encourage to add a profile picture.");
dialog.dismiss();
}else{
tvProfilePic.setText(result);
dialog.dismiss();
}
}
};
task.execute();
}`
그러면 textview에서 java.lang.NullPointerException이 발생합니다.
누가 나를 안내 할 수 있습니까? 고마워요
텍스트 뷰에 대해 아무 것도 보이지 않지만 코드를 표시하고 logcat을 보겠습니다. – Graknol