2014-02-26 61 views
0

我有一個是在崩潰的點的應用程序時崩潰了: 「新的下載(這一點,mURL);」:安卓應用程序初始化新的AsyncTask(的VerifyError)

Downloader downloader = new Downloader(this, mURL); 
    downloader.execute(0); 

Downloader.java:

public class Downloader extends AsyncTask<Integer,Integer,String>{ 

private Fragment fragment; 
private String mURL; 
private Activity activity; 

public Downloader(VertretungsplanFragment fr, String mURL) 
{ 
    fragment = fr; 
    this.mURL = mURL; 
    this.activity = fr.getActivity(); 
} 
@Override 
protected String doInBackground(Integer... integers) { 
[...]} 
} 

那麼這個錯誤顯示(重要:它只是崩潰在Android < 3)

java.lang.VerifyError

這裏的錯誤日誌:)

--startDownload:253正好是Downloader downlaoder = new Downlaoder(this,mURL);

02-25 15:40:55.405 619-619/thems.vertretungsplan E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.VerifyError: thems.vertretungsplan.Downloader at thems.vertretungsplan.VertretungsplanFragment.startDownload(VertretungsplanFragment.java:253) at thems.vertretungsplan.VertretungsplanFragment.onCreateView(VertretungsplanFragment.java:58) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467) at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472) at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) at android.support.v4.view.ViewPager.populate(ViewPager.java:1068) at android.support.v4.view.ViewPager.populate(ViewPager.java:914) at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017) at android.widget.LinearLayout.measureVertical(LinearLayout.java:386) at android.widget.LinearLayout.onMeasure(LinearLayout.java:309) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.FrameLayout.onMeasure(FrameLayout.java:250) at android.view.View.measure(View.java:8313) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.FrameLayout.onMeasure(FrameLayout.java:250) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.FrameLayout.onMeasure(FrameLayout.java:250) at android.view.View.measure(View.java:8313) at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:651) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.FrameLayout.onMeasure(FrameLayout.java:250) at android.view.View.measure(View.java:8313) at android.widget.LinearLayout.measureVertical(LinearLayout.java:531) at android.widget.LinearLayout.onMeasure(LinearLayout.java:309) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.FrameLayout.onMeasure(FrameLayout.java:250) at android.view.View.measure(View.java:8313) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.FrameLayout.onMeasure(FrameLayout.java:250) at android.view.View.measure(View.java:8313) at android.view.ViewRoot.performTraversals(ViewRoot.java:839) at android.view.ViewRoot.handleMessage(ViewRoot.java:1859) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method)

+0

您可以發佈您的錯誤日誌? – Giacomoni

+0

後編輯;) – Michael

回答

0

您必須從實例化片段的Activity獲取上下文。

context =new Context(); 
context = getActivity(); 

將此「context」作爲上下文傳遞給asynctask構造函數。

+0

我其實不明白。 - 爲什麼我需要異步任務中的上下文 – Michael

+1

當您調用Downloader downloader = new Downloader(this,mURL);你必須把當前與你的片段相關聯的活動的上下文放在上面。因此,你把我寫在你的片段中的代碼放在我的答案中,而不是「this」,你把「上下文放在你的構造函數.ie Downloader downloader = new Downloader (context,mURL); – umerbanday

+0

首先 - 感謝您的幫助,但這不是崩潰的問題 - 它實際上並沒有公開下載器(...)。任何想法? - 瘋狂的事情是它適用於Android 3+ – Michael