Android:初始化新的AsyncTask(VerifyError)时应用程序崩溃

时间:2014-02-26 18:03:28

标签: android android-asynctask

我有一个应用程序在Point崩溃:“新的下载程序(这个,mURL);”:

    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&lt; 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)               在android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)               在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)               在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)               在android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)               在android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)               在android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)               在android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)               在android.support.v4.view.ViewPager.populate(ViewPager.java:1068)               在android.support.v4.view.ViewPager.populate(ViewPager.java:914)               在android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)               在android.view.View.measure(View.java:8313)               在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)               在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)               在android.widget.LinearLayout.measureVertical(LinearLayout.java:386)               在android.widget.LinearLayout.onMeasure(LinearLayout.java:309)               在android.view.View.measure(View.java:8313)               在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)               在android.widget.FrameLayout.onMeasure(FrameLayout.java:250)               在android.view.View.measure(View.java:8313)               在android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:581)               在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)               在android.view.View.measure(View.java:8313)               在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)               在android.widget.FrameLayout.onMeasure(FrameLayout.java:250)               在android.view.View.measure(View.java:8313)               在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)               在android.widget.FrameLayout.onMeasure(FrameLayout.java:250)               在android.view.View.measure(View.java:8313)               在android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:651)               在android.view.View.measure(View.java:8313)               在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)               在android.widget.FrameLayout.onMeasure(FrameLayout.java:250)               在android.view.View.measure(View.java:8313)               在android.widget.LinearLayout.measureVertical(LinearLayout.java:531)               在android.widget.LinearLayout.onMeasure(LinearLayout.java:309)               在android.view.View.measure(View.java:8313)               在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)               在android.widget.FrameLayout.onMeasure(FrameLayout.java:250)               在android.view.View.measure(View.java:8313)               在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)               在android.widget.FrameLayout.onMeasure(FrameLayout.java:250)               在android.view.View.measure(View.java:8313)               在android.view.ViewRoot.performTraversals(ViewRoot.java:839)               在android.view.ViewRoot.handleMessage(ViewRoot.java:1859)               在android.os.Handler.dispatchMessage(Handler.java:99)               在android.os.Looper.loop(Looper.java:123)               在android.app.ActivityThread.main(ActivityThread.java:3683)               at java.lang.reflect.Method.invokeNative(Native Method)               在java.lang.reflect.Method.invoke(Method.java:507)               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)               在dalvik.system.NativeStart.main(本地方法)

2 个答案:

答案 0 :(得分:0)

您必须从实例化片段的Activity中获取上下文。

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

将此“context”作为上下文传递给asynctask构造函数。

答案 1 :(得分:0)

片段是在android 3.0之后引入的,即API级别11

http://developer.android.com/reference/android/app/Fragment.html