- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 blah.startAnimation(anim)
上收到 NullPointerException,它位于 LongClickListener
内。我想要做的是在 DragListener 的 GridLayout 中获取子项的数量,并在您开始拖动 ImageView 时为所有子项设置动画。由于某种原因,这将返回 NullPointerException,
它的来源是:
@Override
public boolean onLongClick(View v) {
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
v.startDrag(null, shadowBuilder, v, 0);
deleteAreaForAdapter.setVisibility(View.VISIBLE);
deleteAreaForAdapter.startAnimation(slide_in);
for(int i=0; i<middleViewForAdapter.getChildCount(); i++) {
int middleChildCount = middleViewForAdapter.getChildCount();
int middleChildCount1 = middleViewForAdapter.getChildCount();
int topChildCount = middleViewForAdapter.getChildCount();
int topChildCount1 = middleViewForAdapter.getChildCount();
int bottomChildCount = middleViewForAdapter.getChildCount();
LinearLayout topChild = (LinearLayout)topViewForAdapter.getChildAt(i);
LinearLayout topChild1 = (LinearLayout)topViewForAdapter1.getChildAt(i);
LinearLayout bottomChild = (LinearLayout)bottomViewForAdapter.getChildAt(i);
Context context = mContext;
Animation shakeAnim = AnimationUtils.loadAnimation(context, R.anim.shake);
// do stuff with child view
//ll.clearAnimation();
/*middleChild1.startAnimation(shakeAnim);
topChild.startAnimation(shakeAnim);
topChild1.startAnimation(shakeAnim);
bottomChild.startAnimation(shakeAnim);*/
if(middleChildCount > 0)
{
GridLayout hjk = middleViewForAdapter;
LinearLayout middleChild = (LinearLayout)hjk.getChildAt(i);
middleChild.startAnimation(shakeAnim);
ll.clearAnimation();
}
if(middleChildCount1 > 0)
{
GridLayout hjs = middleLayoutForAdapter1;
LinearLayout middleChild1 = (LinearLayout)hjs.getChildAt(i);
middleChild1.startAnimation(shakeAnim); //Line it's coming from!
ll.clearAnimation();
}
if(topChildCount > 0)
{
topChild.startAnimation(shakeAnim);
ll.clearAnimation();
}
if(topChildCount1 > 0)
{
topChild1.startAnimation(shakeAnim);
ll.clearAnimation();
}
}
v.setVisibility(View.INVISIBLE);
return true;
}
});
日志:
08-14 07:47:18.281 2078-2078/com.matt.cards.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.matt.cards.app, PID: 2078
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.startAnimation(android.view.animation.Animation)' on a null object reference
at com.matt.cards.app.DrawerLongClickListener$1.onLongClick(DrawerLongClickListener.java:169)
at android.view.View.performLongClick(View.java:4474)
at android.view.View$CheckForLongPress.run(View.java:18401)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
谢谢!
编辑:谁能帮忙!?!?!?
最佳答案
你只需要使用
Animation shakeAnim = AnimationUtils.loadAnimation(v.getContext(), R.anim.shake);
代替
Animation shakeAnim = AnimationUtils.loadAnimation(context, R.anim.shake);
关于java - startAnimation(anim) 上的 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25302916/
我正在尝试学习如何在 objc 中使用 UIViewPropertyAnimator。我用一个名为“blueBox”的对象制作了一个简单的测试应用程序。我想改变 blueBox 的属性。 我在@imp
我正在开发一个使用动画的应用程序。为了给我的图像添加动画效果,我使用了一些 NSArray : @property (retain) NSArray * imagePig1; 当我第一次打开UIVie
这个问题在这里已经有了答案: Cocoa animationImages finish detection (3 个答案) 关闭 7 年前。 我希望在单击按钮时运行一个简单的图像数组动画。下面的代码
我有一个带有两个 ImageView 的框架布局。一个在另一个之上。 我想默认隐藏第二个 ImageView,并在用户双击帖子时将其显示在第一个 ImageView 的顶部,动画持续 1000
我正在尝试为 TableView 单元格中的一系列图标图像设置动画,但无法让 ImageView.StartAnimating 工作。 TableView 位于 UITableViewControll
我有一个动画由于某种原因没有动画。 - (void)viewDidLoad { [super viewDidLoad]; self.navigationController.navig
我在 blah.startAnimation(anim) 上收到 NullPointerException,它位于 LongClickListener 内。我想要做的是在 DragListener 的
我有一个 21 帧的菜单背景动画。我在 View 的 viewDidLoad 方法中使用以下代码将它们加载到内存中。 NSMutableArray *menuanimationImages = [[N
我正在尝试通过使图像按钮在单击时 Swing 来为它们设置动画。 @Override public void onClick(View v) { switch (v.getId())
我无法解决的问题是,当我执行时,我的 View 中的 UIActivityIndicatorView 不会开始动画 [UIActivityIndicatorView startAnimating]
我尝试搜索,但没有找到任何线索。我还依赖于放下一个按钮,当我尝试在该按钮的功能中设置事件指示器的动画时,它正在设置动画。 只要我在按钮的方法中编写代码,事件指示器讲解器就会工作。 请提出改进建议
时不时来这里几个月后,终于轮到我提交问题了: 我有一个带有自定义 ArrayAdapter 的 ListView,它从 Internet 加载图像(每行一个图像)。我制作了一个 ImageCache
我创建了一个自定义 View ,它使用一个虚拟的 TranslateAnimation 来设置一些布局属性。我使用 Interpolator 计算高度,并将其应用于 TranslateAnimatio
我基本上想将 View 从一个位置移动到另一个位置,而且我还想逐渐增加它的高度,那么我应该使用 setAnimation 还是 startAnimation。 TranslateAnimation t
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) findViewById() returns nul
我想在调用 segue 之前启动等待动画/显示 UIAlertView,以便用户知道他们必须等待几秒钟,同时处理 segue 并且下一个 ViewController 会填充相关数据并显示! 问题是
我已经使用 将放大动画应用到我的 Imageview myImageView.startAnimation(AnimationUtils.loadAnimation(this,R.anim.zoom_
我正在 Controller.ViewDidLoad 中创建 UIActivityIndicatorView UIActivityIndicatorView spinner = new UIAct
首先声明,以下内容均基于cocos2d-x-2.1.4。 在cocos2d-x的HelloCpp工程中,可以看到在void AppDelegate::applicationDidEnterBackgr
我有一个 UIImageView 扩展,其中包含下载设置图像的方法,该扩展还包含一个 UIActivityIndicatorView,我在加载图像之前将其设置为 View 图像已加载,我从 UII
我是一名优秀的程序员,十分优秀!