Choreographer NullPointerException - android

I've been working on an existing codebase for a while and from browsing our crash log service I've noticed an exception that happens pretty frequently, I am not able to reproduce this issue, nor do I have the context for the scenario to try and dig in, as this is a pretty big project it has become increasingly hard to find out the cause of this exception.
I have been searching online for similar issues and couldn't find any useful information.
If anyone is familiar with this issue, your help would be greatly appreciated.
Stacktrace is as follows:
java.lang.NullPointerException
at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:505)
at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:487)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:517)
at android.animation.ValueAnimator.start(ValueAnimator.java:936)
at android.animation.ValueAnimator.start(ValueAnimator.java:946)
at android.animation.ObjectAnimator.start(ObjectAnimator.java:465)
at android.animation.AnimatorSet$1.onAnimationEnd(AnimatorSet.java:579)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1056)
at android.animation.ValueAnimator.access$400(ValueAnimator.java:50)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:644)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:660)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:543)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
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:5105)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(NativeStart.java)
Cheers.

The issue turned out to be an animation being invoked from a Handler using postDelayed(), which eventually resulted in attempting to animate a null View reference, since it wasn't cleared properly according to it's host lifecycle events.

maybe you tagret is null, print log with animatorSet.getTarget() to see

I also get this stack trace when I use :
ObjectAnimator animator = ObjectAnimator.ofFloat(this, "scale", 1);
....
animator.start()
run in android 4.0.X, but it's ok for higher version, you can also refer this guy's commit, though I don't how to fix, however this is the root cause definitely.

I went through this exception now and find out that I was getting the instance of the View with animation from getActivity().findViewById. While being in a fragment I had to instantiate it from the rootview inflated containing the view.
I basically moved the view from the Activity to the Fragment layout, but didn't change the code.
So the rootview.findViewById resolved my problem.
My stacktrace:
java.lang.NullPointerException
at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:505)
at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:392)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:495)
at android.animation.ValueAnimator.start(ValueAnimator.java:913)
at android.animation.ValueAnimator.start(ValueAnimator.java:923)
at android.animation.ObjectAnimator.start(ObjectAnimator.java:370)
at eu.davidea.passwordcloud.ui.ItemDetailFragment$3.onClick(ItemDetailFragment.java:162)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Trust me, I found the solution of this crash issue on 4.0.x devices.
The problem is when you use ObjectAnimator without 'start' and 'end' value, the api on 4.0.x devices can't find the 'start' value to implement.
For example, this will lead to crash on 4.0.x devices
int endRadiusValue = 10;
ObjectAnimator
.ofFloat(roundedGradientDrawable, "cornerRadius", endRadiusValue)
.setDuration(200)
.start();
And this code work perfect on all api level devices
int startRadiusValue = 0;
int endRadiusValue = 10;
ObjectAnimator
.ofFloat(roundedGradientDrawable, "cornerRadius", startRadiusValue, endRadiusValue)
.setDuration(200)
.start();

The reason is the target view is null. ObjectAnimator ofFloat(Object target, ...).
This crash will only throw in 4x device.
There is no crash in another device

I solve the problem by adding the animation to a animationSet just like this:

Related

Java nullpointer exception from Webview

I tried to search for this problem but this error doesn't look to be the same as this error (my google play version is newer and notice that the error is at a different line of WebViewClassic, so might be different error or the same in a newer version) but I have received the exactly same error exception from webview
java.lang.NullPointerException
at android.webkit.WebViewClassic$WebViewInputConnection.setNewText(WebViewClassic.java:583)
at android.webkit.WebViewClassic$WebViewInputConnection.setComposingText(WebViewClassic.java:323)
at android.webkit.WebViewClassic$WebViewInputConnection.commitText(WebViewClassic.java:339)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:279)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
However I am not using any webview class directly. However, this problem might be related to AdView, but I don't understand how. My code is the following:
#Override
public void onPause() {
//TODO: these lines are created because onPuase of Adview doesn't work
if ( adView != null ) {
adView.pause();
adView.destroy();
adView = null;
Log.i(ApplicationData.APP_TAG, TAG + ": OnPause, pausing the Adview");
}
super.onPause();
}
The error appears after the Log.i line, I would have expected this error to appear when AdView was called but not after. Is possible that this error is coming from a threaded action? Any idea how to avoid the problem?
As the example in https://developer.android.com/reference/com/google/android/gms/ads/AdView.html and the document for AdView.destroy(), you should only call adView.pause() in onPause(), and call adView.destroy() later in onDestroy().
The stack dump looks like another thread is accessing the destroyed AdView instance.

Crash when starting activity on certain devices

I just released an alarm app and it's been hell. It's breaking on certain devices when they try to open up the alarm list screen. I have no idea why it's breaking on some devices and not others. Every phone I've seen it tried on it works perfectly, but opening up the alarm list on some other devices blows it up. I'm really out of my depth for this kind of specific device compatibility issue.
The code at AlarmClock line 227 is this:
View changeSettings = findViewById(R.id.alarm_settings);
changeSettings.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
}
});
And it references this line of xml:
<Button
android:id="#+id/alarm_settings"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0.0dip" android:layout_height="fill_parent"
android:text="#string/menu_settings"
android:layout_weight="1.0" />
This links to a settings activity I borrowed the source of from an adapted version of the android stock alarm, but it uses addPreferencesFromResource which is allegedly deprecated. Is that what's causing this problem?
This is the stack trace from the user's device:
Nexus 7
Touched setup alarm button and then it crashed
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nathantempelman.GoodMorningAlarmFree/com.nathantempelman.alarmclockfree.AlarmClock}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
at android.app.ActivityThread.access$600(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4931)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.nathantempelman.alarmclockfree.AlarmClock.updateLayout(AlarmClock.java:227)
at com.nathantempelman.alarmclockfree.AlarmClock.onCreate(AlarmClock.java:210)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
... 11 more
Any help would be splendiferous. I know that it's happened on someone else's tablet as well, not sure if it's a tablet issue.
The app is here if anyone wants to give it a test: https://play.google.com/store/apps/details?id=com.nathantempelman.GoodMorningAlarmFree
you have a NullPointerException in your AlarmClock class in updateLayout method in line 227 :)
Caused by: java.lang.NullPointerException
at com.nathantempelman.alarmclockfree.AlarmClock.updateLayout(AlarmClock.java:227)
at com.nathantempelman.alarmclockfree.AlarmClock.onCreate(AlarmClock.java:210)
i would check that code first.
as you didn't post any code, i cant help more at the moment :)
Just in case someone else stumbles across this, the problem in the end was that there was a separate layout file for tablets which I hadn't seen in the source codebase I borrowed for a part of my application. I had obviously added a bunch of functionality, but hadn't updated the tablet layout. The buttons to access the things I had added weren't in the tablet layout file. Ergo, null pointer exception only when a tablet device loaded the tablet layout file and searched for non existent objects in the display. When I deleted that file, everything worked perfectly.
I know, hurp and or durp. But maybe someone has the same problem and might want to check for this.

Android Gallery Widget Error: java.lang.NullPointerException at android.widget.Gallery.setUpChild

The main Activity in my Android app has a Gallery widget that loads XML layouts (containing TextViews and Images) through an efficient ImageAdapter. For the most part this works fine and I haven't had any problems on any of my devices or the emulator, but I have seen the following error in my logs. It looks like this is affecting less than 1% of users, but I'd like to know what's causing it, how to resolve it, or at least "catch" it and resolve gracefully. Any ideas?
java.lang.NullPointerException at
android.widget.Gallery.setUpChild(Gallery.java:772) at android.widget.Gallery.makeAndAddView(Gallery.java:751) at android.widget.Gallery.fillToGalleryLeft(Gallery.java:667) at android.widget.Gallery.trackMotionScroll(Gallery.java:378) at android.widget.Gallery$FlingRunnable.run(Gallery.java:1369) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3695) 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:842) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) at dalvik.system.NativeStart.main(Native Method)
I get this problem several days ago, please check your own gallery's adpater check its getView() methods,see if you return null in some if-cases,just replace return null with new View(context) (or other view but null) will simply solve this problem.Good luck

Null Pointer Exception-android.widget.onTouchEvent

I got the following crash report in the android market place. While testing I haven't found any crash and my app works fine. Once I published my app I got the following crash report which I have shown below.
But I am not able to find where the crash occurs, I checked in some stack overflow question and there in some cases I got that use of setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); make cause crash in some devices. Is it true because in my app in some activity I have used this line of code in order to change the input type of EditText from password-text / text-password?
Please help me to solve this out.
Stack Trace
java.lang.NullPointerException
at android.widget.TextView.onTouchEvent(TextView.java:7529)
at android.view.View.dispatchTouchEvent(View.java:3933)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1877)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1211)
at android.app.Activity.dispatchTouchEvent(Activity.java:2198)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1852)
at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2382)
at android.view.ViewRoot.handleMessage(ViewRoot.java:2010)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4385)
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:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
<EditText
android:id="#+id/txt_edit_passwrd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_passwrd_title"
android:background="#drawable/img_password_textbox"
android:cursorVisible="true"
android:layout_marginTop="195dp"
android:hint="#string/passwrd_hint_text"
android:inputType="textPassword"
android:maxLength="10"
android:padding="10dp"
android:textColor="#121212" >
</EditText>
NullPointerException in my own experience tends to mean it cannot find a reference object for instance the edit text your setting the input type for cannot be found, check your layout references and how you've declared the EditText itself.
First check , Have you mention Minimum_sdk_version in android-manifest?
if not then following may be the reason of crashing your application--
If you are using that functionality of android o.s that does not support on customer device.Say you are using Finger_Pointer(as MotionEvent.ACTION_POINTER_DOWN) which does not support before android 2.0.
Or you are using onBackPressed() which does not support for android 1.6.I just gave you hint you can check other issue like this if you have
Updated
For HTC device, TextView's property InputType.TYPE_CLASS_NUMBER lead to crash
Here is the same problem discussed you can refer to this also.
The Solution is not to use "setInputType" with a TextView. You don't need input type filtering for TextViews anyway since they are for displaying text only. Input type is only needed for EditText (and there it works). I had the same problem with Android versions below 4.2.
The disadvantage is, that applying input type "password" on a textview actually makes sense as it masks the password, which may be intended (it was in my case). But this causes random crashes when touching or scrolling over the textview.

Android: Applying an animation to a view creates RuntimeException

I am setting an animation on my view from following the ApiDemo example (see layout_grid_fade.html):
<?xml version="1.0" encoding="utf-8"?>
<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:rowDelay="50%"
android:directionPriority="column"
android:animation="#anim/fade" />
and below is my code
mView.startAnimation(AnimationUtils.loadAnimation(ViewModel.this, R.anim.layout_grid_fade));
mView.setImage(modelImages.get(0).image);
but i get exception dont know why? below is my log trace
FATAL EXCEPTION: main
java.lang.RuntimeException: Unknown animation name: gridLayoutAnimation
at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:116)
at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:83)
at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:64)
at nick.kimK.ViewModel$1$1.run(ViewModel.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at dalvik.system.NativeStart.main(Native Method)
UPD:
Not every xml in res/anim folder declares an animation. Some of them might declare Animators or LayoutAnimationControllers. Those are not Animations, thus they can't be loaded with the loadAnimation() call.
--
It looks like the gridLayoutAnimation tag describes not a particular basic animation type but rather a GridLayoutAnimationController. So it can be loaded directly with AnimationUtils.loadAnimation() but rather should be set to a ViewGroup (a layout) throuh layoutAnimation property. If you still want to obtain the AnimationController instance in code, use AnimationUtils.loadLayoutAnimation() method:
LayoutAnimationController layoutAnimation = AnimationUtils.loadLayoutAnimation(ViewModel.this, R.anim.layout_grid_fade)
But you hardly can use the layoutAnimation in the way you're doing in your example.
I found this article quite useful for understanding the layout animations.

Categories

Resources