doInBackground(Params...)
이 때문에 쉽게
TextView
액세스하고
executed()
이었다에서
Activity
에서
setText()
방법을 수행한다 전에 UI 스레드에서 실행된다는 사실
d.android.com for onPreExecute()에 명시
. NullPointerExcepction() onPreExecute 내에서 호출 될 때()
그러나 여기 loading
텍스트 뷰 개인적으로 활동를 확장하는 클래스 SplashScreen
내부에 선언 된 아래의 코드에서
onCreate()
안에는 UI의 TextView 위젯과 링크되어 있습니다. 그러나
AsyncTask
확장 클래스
Atom
이 함수
onPreExecute()
이 실행될 때
loading.setText("Loading...");
이 내부에서 실행되는 경우
NullPointerExcepction
을 반환합니다. 여기에 코드
public class SplashScreen extends Activity implements AnimationListener{
...
TextView loading=null;
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
try {
a = (Atom) new Atom().execute(null,null,null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
finish();
}
...
loading = (TextView) findViewById(R.id.textView2);
....
}
public class Atom extends AsyncTask<RSSFeed, Void, RSSFeed>{
private RSSReader reader;
private RSSFeed feed = null;
private String uri = "http://website.com/feed/";
@Override
protected void onPreExecute() {
super.onPreExecute();
//------------problem----area-------------------
loading.setText("Loading...");
//------------problem----area-------------------
}
@Override
protected RSSFeed doInBackground(RSSFeed... arg0) {
reader = new RSSReader();
try {
feed = reader.load(uri);
Log.d("rss", feed.getTitle());
} catch (RSSReaderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return feed;
}
@Override
protected void onPostExecute(RSSFeed result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
prg.cancel();
t(result.getTitle().toString());
}
}
}
스택 : asyntask
을 실행하기 전에 TextView
를 초기화하는
03-09 10:50:12.793: W/System.err(14214): java.lang.NullPointerException
03-09 10:50:12.813: W/System.err(14214): at in.edu.ss.er.splash.SplashScreen$Atom.onPreExecute(SplashScreen.java:158)
03-09 10:50:12.827: W/System.err(14214): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
03-09 10:50:12.833: W/System.err(14214): at android.os.AsyncTask.execute(AsyncTask.java:534)
03-09 10:50:12.833: W/System.err(14214): at in.edu.ss.er.splash.SplashScreen.onCreate(SplashScreen.java:45)
당신의 XML에'R.id.textView2'라는 ID를 가진 TextView를 가지고 계십니까? – tambykojak
이 AyncTask를 어디에서 호출합니까? – Kedarnath
xml 코드도 함께 입력하십시오. –