I am trying to obtain the current background color of a button from a randomized color palette. However, my app is always crashing when I try the following code.
int activeColor = ((ColorDrawable)color1.getBackground()).getColor();
I always get this error message.
Process: com.boredgiant.chora, PID: 17418
java.lang.ClassCastException: android.graphics.drawable.RippleDrawable cannot be cast to android.graphics.drawable.ColorDrawable
at com.boredgiant.chora.DrawActivity$103.onClick(DrawActivity.java:850)
at android.view.View.performClick(View.java:6314)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View$PerformClick.run(View.java:24793)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6543)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
You need to cast it to RippleDrawable
int activeColor = ((RippleDrawable)color1.getBackground()).getColorStateList().getDefaultColor();
Related
I have a Recyclerview and some items in it like imageviews and textviews.
I need to open a bottom sheet using model class, when I click the imageview in the recyclerview.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.storeeval, PID: 21795
java.lang.IllegalStateException: Fragment BottomSheetDialog{6a325f6} (605326f6-5f11-4029-9b55-15c136b1aa75) has not been attached yet.
at androidx.fragment.app.Fragment.getChildFragmentManager(Fragment.java:1075)
at com.app.storeeval.store_elements_adapter$ElementsViewHolder$1.onClick(store_elements_adapter.java:86)
at android.view.View.performClick(View.java:6616)
at android.view.View.performClickInternal(View.java:6593)
at android.view.View.access$3100(View.java:785)
at android.view.View$PerformClick.run(View.java:25929)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
I/Process: Sending signal. PID: 21795 SIG: 9
I have tried some methods to resolve these errors from here but I couldn't succeed.
please help me in clearing this error.
MLImageSegmentationSetting analyzerSetting = (new MLImageSegmentationSetting.Factory()).setExact(true).setAnalyzerType(MLImageSegmentationSetting.BODY_SEG).setScene(2).create();
MLImageSegmentationSetting setting = new MLImageSegmentationSetting.Factory().setAnalyzerType(MLImageSegmentationSetting.BODY_SEG).create();
this.analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(analyzerSetting);//error on this line
error :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.brandpost.brandpro365, PID: 9861
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2001, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/61/ORIGINAL/NONE/image/png/1980871995 flg=0x1 clip={text/uri-list {U(content)}} }} to activity {com.brandpost.brandpro365/com.mlkit.sample.activity.StillCutPhotoActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:5301)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5340)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
at com.huawei.agconnect.config.a.c.a(Unknown Source:0)
at com.huawei.agconnect.config.a.g.(Unknown Source:41)
at com.huawei.agconnect.config.a.a.getString(Unknown Source:43)
at com.huawei.agconnect.config.a.a.getString(Unknown Source:1)
at com.huawei.hms.mlsdk.common.AgConnectInfo.(AgConnectInfo.java:53)
at com.huawei.hms.mlsdk.common.MLApplicationSetting.fromResource(MLApplicationSetting.java:262)
at com.huawei.hms.mlsdk.common.MLApplication.initialize(MLApplication.java:180)
at com.huawei.hms.mlsdk.common.MLApplication.getInstance(MLApplication.java:125)
at com.huawei.hms.mlsdk.MLAnalyzerFactory.getInstance(MLAnalyzerFactory.java:53)
at com.mlkit.sample.activity.StillCutPhotoActivity.createImageTransactor(StillCutPhotoActivity.java:149)
at com.mlkit.sample.activity.StillCutPhotoActivity.onActivityResult(StillCutPhotoActivity.java:101)
at android.app.Activity.dispatchActivityResult(Activity.java:8382)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5294)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5340)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Please follow the instuctions for HMS ML SDK : https://developer.huawei.com/consumer/en/doc/development/hiai-Guides/image-segmentation-0000001050040109
First, check the preparations:
Configure App info. in AGC: https://developer.huawei.com/consumer/en/doc/development/hiai-Guides/config-agc-0000001050990353
Enabling the service: https://developer.huawei.com/consumer/en/doc/development/hiai-Guides/enable-service-0000001050038078
Then, as for how to Create an image segmentation analyzer, please refer here: https://developer.huawei.com/consumer/en/doc/development/hiai-Guides/image-segmentation-0000001050040109
// Method 1: Use default parameter settings to configure the image segmentation analyzer.
// The default mode is human body segmentation in fine mode. All segmentation results of human body segmentation are returned (pixel-level label information, human body image with a transparent background, gray-scale image with a white human body and black background, and an original image for segmentation).
MLImageSegmentationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer();
// Method 2: Use MLImageSegmentationSetting to customize the image segmentation analyzer.
MLImageSegmentationSetting setting = new MLImageSegmentationSetting.Factory()
// Set whether to support fine segmentation. The value true indicates fine segmentation, and the value false indicates fast segmentation.
.setExact(false)
// Set the segmentation mode to human body segmentation.
.setAnalyzerType(MLImageSegmentationSetting.BODY_SEG)
// Set returned result types.
// MLImageSegmentationScene.ALL: All segmentation results are returned (pixel-level label information, human body image with a transparent background, gray-scale image with a white human body and black background, and an original image for segmentation).
// MLImageSegmentationScene.MASK_ONLY: Only pixel-level label information and an original image for segmentation are returned.
// MLImageSegmentationScene.FOREGROUND_ONLY: A human body image with a transparent background and an original image for segmentation are returned.
// MLImageSegmentationScene.GRAYSCALE_ONLY: A gray-scale image with a white human body and black background and an original image for segmentation are returned.
.setScene(MLImageSegmentationScene.FOREGROUND_ONLY)
.create();
MLImageSegmentationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting);
I want to use the background of an Activity as a part of SharedElementTransition, but when adding DecorView to the transition, the app crashes with the following trace:
java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.ViewGroup
at android.app.ActivityTransitionCoordinator.setSharedElementMatrices(ActivityTransitionCoordinator.java:571)
at android.app.ActivityTransitionCoordinator.moveSharedElementsToOverlay(ActivityTransitionCoordinator.java:858)
at android.app.EnterTransitionCoordinator.viewsReady(EnterTransitionCoordinator.java:144)
at android.app.EnterTransitionCoordinator.lambda$triggerViewsReady$0(EnterTransitionCoordinator.java:164)
at android.app.-$$Lambda$EnterTransitionCoordinator$wYWFlx9zS3bxJYkN44Bpwx_EKis.run(Unknown Source:4)
at com.android.internal.view.OneShotPreDrawListener.onPreDraw(OneShotPreDrawListener.java:78)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2478)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1462)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7187)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:951)
The main reason for the crash is that the parent of DecorView when called by view.getParent() is not a ViewGroup. Is there another way to animate the background of an Activity when entering it from another Activity as a part of SharedElementTransition?
It's worth mentioning that I'm using changeImageTransform in windowSharedElementEnterTransition right now.
We're debugging a crash in a Cordova app that seems to happen on launch / foregrounding, after the app was backgrounded for a moderate amount of time and has been to some extent killed by the OS.
At the time of the crash the app is attempting to show a native dialog fragment for Fingerprint Authentication. For some reason in this case the resources for this fragment cannot be found.
It's been reported for Android 6 and 7, on older and newer devices.
java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.koho/ca.koho.Koho}: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2421)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.access$900(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:5440)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1437)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2887)
at android.content.res.Resources.getLayout(Resources.java:1251)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at com.cordova.plugin.android.fingerprintauth.FingerprintAuthenticationDialogFragment.onCreateView(FingerprintAuthenticationDialogFragment.java:85)
at android.app.Fragment.performCreateView(Fragment.java:2220)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1130)
at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1953)
at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:152)
at android.app.Activity.performCreateCommon(Activity.java:6279)
at android.app.Activity.performCreate(Activity.java:6287)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2374)
... 9 more
Here's the problematic bit of code, from the DialogFragment's onCreateView:
int fingerprint_dialog_container_id = getResources()
.getIdentifier("fingerprint_dialog_container", "layout",
FingerprintAuth.packageName);
View v = inflater.inflate(fingerprint_dialog_container_id, container, false);
When the crash happens, getIdentifier(...) is for some reason returning 0. Most of the time the actual identifier is returned.
I have not found a way to reproduce the crash, and advice to enable developer options like 'Don't keep activities' and 'Background process limit' had did not help.
Thanks for any help.
I have a problem with my app. The app works perfectly. If I press the back button the app obviously closes without any problems. If I press the home button the app is in the background. If I open the app immediately this works, but if I open other apps and then I open my app often crashes.
How can I fix? I have to implement the method onPause? But how?
26 21:46:27.341 29621-29621/parlamento_italiano.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: parlamento_italiano.android, PID: 29621
java.lang.RuntimeException: Unable to start activity ComponentInfo{parlamento_italiano.android/com.prova.prova3.Quarta}: java.lang.NumberFormatException: Invalid int: ""
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.parseInt(Integer.java:334)
at com.prova.prova3.R2.onCreateView(R2.java:77)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1026)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1207)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1189)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2001)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:165)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:507)
at com.prova.prova3.Quarta.onStart(Quarta.java:291)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1250)
at android.app.Activity.performStart(Activity.java:6538)
This cause the crash
int x = Integer.parseInt(numVoti.replaceAll("[\\D]", ""));
Firstly, your app does not go in the background, when you press the Home button. It just gets added in the Back Stack. Second, try to explain to us the resources your app uses, how they interact with other apps, possibly.