在片段類中,我試圖調用一個AsyncTask類,其中doInBackground()我試圖獲取CurrentLocation並設置爲TextView。片段 - 使用AsyncTask
但是,當我試圖做到這一點的示值誤差波紋管,
E/AndroidRuntime(645): Caused by: java.lang.ClassCastException:com.example.MainFragmentActivity
從我MainFragmentActivity延伸FragmentActivity,我設置叫FragmentPagerAdapter和override getItem()
這個適配器中,我呼籲這樣的片段適配器波紋管,
@Override
public Fragment getItem(int position) {
if (position == 0) {
Log.i(TAG, "before return in adapter postion 0");
return ViewPageFragment.newInstance(CONTENT[position % CONTENT.length], context);
}
}
這裏是我的代碼, http://pastebin.com/gykkETJV
我該如何解決這個問題?
堆棧跟蹤:
E/ViewPageFragment(420): java.lang.ClassCastException: com.example.MainFragmentActivity
E/ViewPageFragment(420): com.example.ViewPageFragment$LocationTask.doInBackground(ViewPageFragment.java:145)
E/ViewPageFragment(420): com.example.ViewPageFragment$LocationTask.doInBackground(ViewPageFragment.java:1)
E/ViewPageFragment(420): android.os.AsyncTask$2.call(AsyncTask.java:185)
E/ViewPageFragment(420): java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
E/ViewPageFragment(420): java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
E/ViewPageFragment(420): java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
E/ViewPageFragment(420): java.lang.Thread.run(Thread.java:1096)
你可以發佈多一點你的stacktrace嗎? – kaspermoerch
我如何獲得堆棧跟蹤 – Jyosna
我編輯堆棧跟蹤 – Jyosna