删除并添加视图NPE,蜂窝,android

删除并添加视图NPE,蜂窝,android,第1张

概述我有一个接一个地以编程方式填充Gallery组件的LinearLayoutareaForGalleries.每个库中的onItemClick方法将其从areaForGalleries中删除,并将其添加到RelativeLayoutparentLayout,它是areaForGalleries的父级.见下面的代码.LinearLayoutareaForGalleries;RelativeLayoutparen

我有一个接一个地以编程方式填充gallery组件的linearLayout areaForgallerIEs.每个库中的onItemClick方法将其从areaForgallerIEs中删除,并将其添加到relativeLayout parentLayout,它是areaForgallerIEs的父级.见下面的代码.

linearLayout areaForgallerIEs;relativeLayout parentLayout;...private voID showgallery() {final Customgallery mgallery = new Customgallery(mContext);mgallery.setonItemClickListener(new CustomAdapterVIEw.OnItemClickListener() {        public voID onItemClick(CustomAdapterVIEw<?> parent, VIEw v, int position, long ID) {            areaForgallerIEs.removeVIEw(mgallery);            parentLayout.addVIEw(mgallery);        }    });

Customgallery是我对AndroID gallery组件的实现.我只更改了左侧图库的对齐方式 – 一行代码已更改.
代码在AndroID 2.1 – 2.3.3上完美运行,但是当在Honeycomb或ICS上尝试时,它崩溃并出现以下错误:

01-31 10:31:49.596: E/AndroIDRuntime(1536): FATAL EXCEPTION: main01-31 10:31:49.596: E/AndroIDRuntime(1536): java.lang.NullPointerException01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.GestureDetector.ontouchEvent(GestureDetector.java:587)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at com.my.example.pullrefreshgallery.Customgallery.ontouchEvent(Customgallery.java:812)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEw.dispatchtouchEvent(VIEw.java:5486)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1953)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1714)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:1959)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1728)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.superdispatchtouchEvent(PhoneWindow.java:1892)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at com.androID.internal.policy.impl.PhoneWindow.superdispatchtouchEvent(PhoneWindow.java:1371)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.app.Activity.dispatchtouchEvent(Activity.java:2364)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at com.my.example.Home.dispatchtouchEvent(Home.java:883)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.dispatchtouchEvent(PhoneWindow.java:1840)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEw.dispatchPointerEvent(VIEw.java:5662)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwRootImpl.deliverPointerEvent(VIEwRootImpl.java:2863)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.vIEw.VIEwRootImpl.handleMessage(VIEwRootImpl.java:2442)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.os.Handler.dispatchMessage(Handler.java:99)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.os.Looper.loop(Looper.java:137)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at androID.app.ActivityThread.main(ActivityThread.java:4340)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at java.lang.reflect.Method.invokeNative(Native Method)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at java.lang.reflect.Method.invoke(Method.java:511)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:551)01-31 10:31:49.596: E/AndroIDRuntime(1536):     at dalvik.system.NativeStart.main(Native Method)

NullPointerException是指Customgallery方法,我根本没有改变:

@OverrIDepublic boolean ontouchEvent(MotionEvent event) {    // Give everything to the gesture detector    boolean retValue = mGestureDetector.ontouchEvent(event);    int action = event.getAction();    if (action == MotionEvent.ACTION_UP) {        // Helper method for lifted finger        onUp();    } else if (action == MotionEvent.ACTION_CANCEL) {        onCancel();    }    return retValue;}

当我评论删除和添加mgallery的行时,一切都很完美!
有similar problem,但我没有使用碎片.

有什么想法有什么不对?
谢谢!

解决方法:

我现在不是你等待的答案,但我只是在原始gallery小部件上的ICS上遇到了同样的问题(没有超载).

经过一些测试后,我最终使用了简单的方法:尝试…捕获

@OverrIDepublic boolean ontouchEvent(MotionEvent event) {    try {        return super.ontouchEvent(event);    } catch (Throwable t) {        return true;    }}

厨房仍然正常工作,onClickListener也是如此,所以对我没有任何副作用.

总结

以上是内存溢出为你收集整理的删除并添加视图NPE,蜂窝,android全部内容,希望文章能够帮你解决删除并添加视图NPE,蜂窝,android所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1109727.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存