Android:初始化新的AsyncTask(VerifyError)时,应用程序崩溃
我有一个应用程序在Point上崩溃:“new Downloader(this,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 <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 the android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:android.support.v4.app.Fragment.performCreateView(Fragment.java:1500) 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 。android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)上的.execPendingActions(FragmentManager.java:1467)。 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。在android.widget.LinearLayout.measureChildVertical(LinearLayout.java:386)在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) android.view.View.measure(View.java:8313)android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)android.widget.FrameLayout上的android.widget.LinearLayout.onMeasure(LinearLayout.java:309) .onMeasure(FrameLayout.java:250)在android.widget.RelativeLayout.onMeasure(RelativeLayout。)上的android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)android.view.View.measure(View.java:8313)。 android.view.measure(View.java:8313)在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)android.widget.FrameLayout.onMeasure(FrameL ayout.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.widget的android.view.View.measure(View.java:8313)处的android.widget.FrameLayout.onMeasure(FrameLayout.java:250)处的android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)。 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)在android.view.View.Group.measureChildWithMargins(ViewGroup.java:3138)android.view.View.measure(View.java:8313)android.widget.FrameLayout.onMeasure(FrameLayout.java:250)在android.widget.FrameLayout.onMea 确保(FrameLayout.java:250)在android.view.View.measure(View.java:8313)在android.view.ViewRoot.performTraversals(ViewRoot.java:839)在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 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)at dalvik.system.NativeStart.main(Native Method)
您必须从实例化片段的Activity获取上下文。
context =new Context();
context = getActivity();
将这个“上下文”作为上下文传递给asynctask构造函数。
片段是在android 3.0之后引入的,即API级别11
http://developer.android.com/reference/android/app/Fragment.html
链接地址: http://www.djcxy.com/p/84721.html上一篇: Android: App crashes when initializing new AsyncTask (VerifyError)