nisrulz / screenshott

[Android Library] Take a screenshot of your view layout , programmatically!
http://nisrulz.github.io/screenshott/
Apache License 2.0
326 stars 74 forks source link

Taking a screenshot within a fragment causes a crash #8

Open TrentPierce opened 7 years ago

TrentPierce commented 7 years ago

Do you want to request a feature or report a bug? Report A Bug

What is the current behavior? My app is crashing upon trying to take a screenshot in a fragment

If the current behavior is a bug, please provide the steps to reproduce.

Any logs, error output, bugreport etc?

07-30 22:32:47.013 2675-2675/com.octothorpeplus.evanstonsubaru E/AndroidRuntime: FATAL EXCEPTION: main Process: com.octothorpeplus.evanstonsubaru, PID: 2675 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.measure(int, int)' on a null object reference at github.nisrulz.screenshott.ScreenShott.takeScreenShotOfJustView(ScreenShott.java:98) at com.octothropeplus.octolib.fragments.RewardFragment.saveScreenshot(RewardFragment.java:71) at com.octothropeplus.octolib.fragments.RewardFragment.onCreateView(RewardFragment.java:63) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

What is the expected behavior? I expect it to take and save the screenshot Any other comments?

What versions of software are you using?

nisrulz commented 7 years ago

Looks like your view is null when you are trying to take the screenshot. Make sure you have the view available of which you take the screenshot of.

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.measure(int, int)' on a null object reference
at github.nisrulz.screenshott.ScreenShott.takeScreenShotOfJustView(ScreenShott.java:98)

I don't think it's a problem of the fragment itself. Could you share a barebone implementation where the lib crashes because its been called inside a fragment? I would make sure that its being called once the view is created and then try to take the screenshot.