Flutter app login Exception has occurred. PlatformException error - flutter

I have a flutter app but every time I login I get an exception error and I have to press f5 to ensure the process is completed. This is the error
Exception has occurred.
PlatformException (PlatformException(error, Task io.flutter.plugins.sharedpreferences.MethodCallHandlerImpl$1#f33e5c6 rejected from java.util.concurrent.ThreadPoolExecutor#63f5987[Running, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 0], null, java.util.concurrent.RejectedExecutionException: Task io.flutter.plugins.sharedpreferences.MethodCallHandlerImpl$1#f33e5c6 rejected from java.util.concurrent.ThreadPoolExecutor#63f5987[Running, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2085)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:848)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1394)
at io.flutter.plugins.sharedpreferences.MethodCallHandlerImpl.commitAsync(MethodCallHandlerImpl.java:137)
at io.flutter.plugins.sharedpreferences.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:96)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6820)
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:922)
))

It seems the bug is fixed in shared_preferences 2.0.4 (at least for me it worked)

you should downgrade to
shared_preferences: 2.0.1
not
shared_preferences: ^2.0.1
if you used the beta version or use the stable version
shared_preferences: ^0.5.12+4

Related

Fatal exception : Couldn't inflate contentViewsjava.lang.IllegalArgumentException: setShowActionsInCompactView: action 0 out of bounds (max -1)

i use test lab to find bugs on my apps and i have an but that i can't find the origins. I think it came from just_audio or audio_service.
This is the test issues :
android.app.RemoteServiceException: Bad notification(tag=null, id=1124) posted from package com.our_unseen_nature, crashing app(uid=10274, pid=22490): Couldn't inflate contentViewsjava.lang.IllegalArgumentException: setShowActionsInCompactView: action 0 out of bounds (max -1)
FATAL EXCEPTION: main
Process: com.our_unseen_nature, PID: 22490
android.app.RemoteServiceException: Bad notification(tag=null, id=1124) posted from package com.our_unseen_nature, crashing app(uid=10274, pid=22490): Couldn't inflate contentViewsjava.lang.IllegalArgumentException: setShowActionsInCompactView: action 0 out of bounds (max -1)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2005)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Thank you everyone.
Thanks all, I've found the solution and It was really easy. The error occured because i didn't choose correctly the actions to show in Android's compact view based by those i've selected as my controls.
controls: [
MediaControl. skipToPrevious,
MediaControl.pause,
MediaControl.skipToNext,
],
// Which controls to show in Android's compact view
//from the lists of controls selected.
androidCompactActionIndices: const[0, 1, 2],

Flutter crashes when using AudioPlayers and Future.wait to play a list of sound effects simultaneously

I'd like to create a list of List<Future<void>> that represent executions of sound effects.
I therefore iterate through a list of event types/formats (ie. "sword") and map each to a sound effect play execution.
I wrap these Futures in a Future.delayed for each with a random number of milliseconds from 30 to 100 just to have a little random occurance of when the sound effects are played in order (to add a pause between two sound effects).
The list of those sound effect Futures is then called by Future.wait where I expected the list to be resolved and the Future.delay might take effect.
This is my code
_playActionEventSounds() async {
if (widget.log.isNotEmpty) {
final lastRound = widget.log.map((e) => e.round).reduce(max);
final lastActionEvents = widget.log.where((actionEvent) => actionEvent.round == lastRound);
final List<Future<void>> eventSounds = lastActionEvents.map((actionEvent) async {
if (actionEvent.format == "sword") {
return Future.delayed(Duration(milliseconds: next(30, 100)), () => _soundPlayer.punch());
}
if (actionEvent.format == "damage") {
return Future.delayed(Duration(milliseconds: next(30, 100)), () => _soundPlayer.pain());
}
return Future.value(null);
}).toList();
await Future.wait(eventSounds);
}
}
SoundPlayer class:
import 'package:audioplayers/audioplayers.dart';
class SoundPlayer {
Future<void> punch() async {
final player = AudioPlayer();
player.setReleaseMode(ReleaseMode.stop);
return await player.play(AssetSource("sounds/punch.wav"));
}
Future<void> pain() async {
final player = AudioPlayer();
player.setReleaseMode(ReleaseMode.stop);
return await player.play(AssetSource("sounds/pain.wav"));
}
}
I now can run the process multiple times. I do hear the sounds appear as expected. But after the 4th execution the app crashes.
This is the error:
I/flutter (28346): Unexpected platform error: MediaPlayer error with what:MEDIA_ERROR_UNKNOWN {what:1} extra:MEDIA_ERROR_UNKNOWN {extra:-19}
E/MediaPlayerNative(28346): pause called in state 0, mPlayer(0xb400007a92646810)
E/MediaPlayerNative(28346): error (-38, 0)
E/MediaPlayerNative(28346): Attempt to call getDuration in wrong state: mPlayer=0xb400007a92646810, mCurrentState=0
E/MediaPlayerNative(28346): error (-38, 0)
E/MediaPlayerNative(28346): stop called in state 0, mPlayer(0xb400007a92646810)
E/MediaPlayerNative(28346): error (-38, 0)
E/MediaPlayerNative(28346): prepareAsync called in state 0, mPlayer(0xb400007a92646810)
D/AndroidRuntime(28346): Shutting down VM
E/AndroidRuntime(28346): FATAL EXCEPTION: main
E/AndroidRuntime(28346): Process: com.example.app, PID: 28346
E/AndroidRuntime(28346): java.lang.IllegalStateException
E/AndroidRuntime(28346): at android.media.MediaPlayer._prepare(Native Method)
E/AndroidRuntime(28346): at android.media.MediaPlayer.prepare(MediaPlayer.java:1313)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.MediaPlayerPlayer.prepare(MediaPlayerPlayer.kt:89)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.WrappedPlayer.stop(WrappedPlayer.kt:185)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.WrappedPlayer.onCompletion(WrappedPlayer.kt:248)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.MediaPlayerPlayer.createMediaPlayer$lambda-5$lambda-1(MediaPlayerPlayer.kt:17)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.MediaPlayerPlayer.$r8$lambda$3fK1i48Yert5dbg2Q8ZiB5tiKHg(Unknown Source:0)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.MediaPlayerPlayer$$ExternalSyntheticLambda1.onCompletion(Unknown Source:2)
E/AndroidRuntime(28346): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:3559)
E/AndroidRuntime(28346): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(28346): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(28346): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(28346): at android.app.ActivityThread.main(ActivityThread.java:7842)
E/AndroidRuntime(28346): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(28346): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(28346): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I/Process (28346): Sending signal. PID: 28346 SIG: 9
Lost connection to device.
I guess I somewhat messed up the resource management due the repeated execution. Therefore I guess the error lies somewhat in the API usage of audioplayers.dart?
I had to change the ReleaseMode to release. What I did was using stop that kept the resources in memory I guess and therefore cluttered the memory?

pyspark foreach/foreachPartition send http request failed

I use urllib.request to send http request in foreach/foreachPartition. pyspark throw error as follow:
objc[74094]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
20/07/20 19:05:58 ERROR Executor: Exception in task 7.0 in stage 0.0 (TID 7)
org.apache.spark.SparkException: Python worker exited unexpectedly (crashed)
at org.apache.spark.api.python.BasePythonRunner$ReaderIterator$$anonfun$1.applyOrElse(PythonRunner.scala:536)
at org.apache.spark.api.python.BasePythonRunner$ReaderIterator$$anonfun$1.applyOrElse(PythonRunner.scala:525)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:38)
at org.apache.spark.api.python.PythonRunner$$anon$3.read(PythonRunner.scala:643)
at org.apache.spark.api.python.PythonRunner$$anon$3.read(PythonRunner.scala:621)
at org.apache.spark.api.python.BasePythonRunner$ReaderIterator.hasNext(PythonRunner.scala:456)
at org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:37)
at scala.collection.Iterator.foreach(Iterator.scala:941)
at scala.collection.Iterator.foreach$(Iterator.scala:941)
at org.apache.spark.InterruptibleIterator.foreach(InterruptibleIterator.scala:28)
at scala.collection.generic.Growable.$plus$plus$eq(Growable.scala:62)
at scala.collection.generic.Growable.$plus$plus$eq$(Growable.scala:53)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:105)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:49)
at scala.collection.TraversableOnce.to(TraversableOnce.scala:315)
at scala.collection.TraversableOnce.to$(TraversableOnce.scala:313)
at org.apache.spark.InterruptibleIterator.to(InterruptibleIterator.scala:28)
at scala.collection.TraversableOnce.toBuffer(TraversableOnce.scala:307)
at scala.collection.TraversableOnce.toBuffer$(TraversableOnce.scala:307)
at org.apache.spark.InterruptibleIterator.toBuffer(InterruptibleIterator.scala:28)
at scala.collection.TraversableOnce.toArray(TraversableOnce.scala:294)
at scala.collection.TraversableOnce.toArray$(TraversableOnce.scala:288)
at org.apache.spark.InterruptibleIterator.toArray(InterruptibleIterator.scala:28)
at org.apache.spark.rdd.RDD.$anonfun$collect$2(RDD.scala:1004)
at org.apache.spark.SparkContext.$anonfun$runJob$5(SparkContext.scala:2133)
_
when i call rdd.foreach(send_http), rdd=sc.parallelize(["http://192.168.1.1:5000/index.html"]),
send_http defined as follow:
def send_http(url):
req = urllib.request.Request(url)
resp = urllib.request.urlopen(req)
anyone can tell me the problem? thanks.
This is #tmylt's answer in the comment above, but I too can confirm that using http.client instead of requests.get does work. I'm sure there's a reason why this is happening, but using python http.client is a quick fix.

contact picker causing app crash after I am selecting contact from contact list

I am using Flutter contact picker 0.0.2. But it is giving some weird error. It shows the contact list when I call selectContact Future, however, after selecting a particular contact from the list, the app crashes, and it gives me the below-mentioned error on console.
I have also tried with adding permission in android, even though it is not required, still, it does not work.
Code :
class _MobileNumberWidgetState extends State<MobileNumberWidget> {
final TextEditingController _phoneNumberController = TextEditingController();
final ContactPicker _contactPicker = new ContactPicker();
Contact _contact;
#override
Widget build(BuildContext context) {
return AppWidgets.shadowContainerComplete(
child:Row(
children: <Widget>[
Expanded(
child: TextField(
controller: _phoneNumberController,
decoration: AppStyles.textField(hint: "Enter Phone Number", iconData: Icons.phone_iphone),
),
),
IconButton(
icon: Icon(Icons.format_list_numbered),
onPressed: () async{
Contact contact = await _contactPicker.selectContact();
setState(() {
_contact = contact;
});
},
)
],
)
);
}
}
Console :
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
D/FlutterActivity(17398): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate(17398): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(17398): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate(17398): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView(17398): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine#43c3a74
D/FlutterActivityAndFragmentDelegate(17398): Executing Dart entrypoint: main, and sending initial route: /
Debug service listening on ws://127.0.0.1:28145/jPIcHt_yF9E=/ws
Syncing files to device Android SDK built for x86...
D/EGL_emulation(17398): eglMakeCurrent: 0xe121a6c0: ver 3 1 (tinfo 0xe120f8a0)
D/eglCodecCommon(17398): setVertexArrayObject: set vao to 0 (0) 1 0
D/EGL_emulation(17398): eglMakeCurrent: 0xe121a180: ver 3 1 (tinfo 0xe120fa70)
D/FlutterView(17398): Detaching from a FlutterEngine: io.flutter.embedding.engine.FlutterEngine#43c3a74
D/AndroidRuntime(17398): Shutting down VM
E/AndroidRuntime(17398): FATAL EXCEPTION: main
E/AndroidRuntime(17398): Process: maaz.easyapproach.kashbak, PID: 17398
E/AndroidRuntime(17398): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2015, result=-1, data=Intent { dat=content://com.android.contacts/data/1 flg=0x1 }} to activity {maaz.easyapproach.kashbak/maaz.easyapproach.kashbak.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ContentResolver android.app.Activity.getContentResolver()' on a null object reference
E/AndroidRuntime(17398): at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
E/AndroidRuntime(17398): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
E/AndroidRuntime(17398): at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
E/AndroidRuntime(17398): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(17398): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(17398): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
E/AndroidRuntime(17398): at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(17398): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(17398): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(17398): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17398): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(17398): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime(17398): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ContentResolver android.app.Activity.getContentResolver()' on a null object reference
E/AndroidRuntime(17398): at net.goderbauer.flutter.contactpicker.ContactPickerPlugin.onActivityResult(ContactPickerPlugin.java:68)
E/AndroidRuntime(17398): at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEnginePluginRegistry.java:634)
E/AndroidRuntime(17398): at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onActivityResult(FlutterEnginePluginRegistry.java:367)
E/AndroidRuntime(17398): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:546)
E/AndroidRuntime(17398): at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:594)
E/AndroidRuntime(17398): at android.app.Activity.dispatchActivityResult(Activity.java:8110)
E/AndroidRuntime(17398): at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
E/AndroidRuntime(17398): ... 11 more
I/Process (17398): Sending signal. PID: 17398 SIG: 9
Lost connection to device.

Why android 5.0 occur error java.lang.RuntimeException: start smooth zoom failed?

This is my code set zoom of camera:
// 10 Set zoom value to camera
if (p.isZoomSupported() && p.isSmoothZoomSupported()) {
// most phones
mCamera.startSmoothZoom(zoomvalue);
} else if (p.isZoomSupported() && !p.isSmoothZoomSupported()) {
p.setZoom(zoomvalue);
mCamera.setParameters(p);
mCamera.setParameters(p);
mCamera.startPreview();
}
But it occur exception on Canvas Spark (Q380) android 5.0:
java.lang.RuntimeException: start smooth zoom failed
at android.hardware.Camera.startSmoothZoom(Native Method)
jat android.app.Activity.dispatchTouchEvent(Activity.java:2775)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2326)
at android.view.View.dispatchPointerEvent(View.java:8687)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4485)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4343)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3884)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3937)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3903)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4013)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3911)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4070)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3884)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3937)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3903)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3911)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3884)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6300)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6256)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6209)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6462)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6421)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6493)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:795)
at android.view.Choreographer.doCallbacks(Choreographer.java:598)
at android.view.Choreographer.doFrame(Choreographer.java:565)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:781)
at android.os.Handler.handleCallback(Handler.java:810)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5529)
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:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
Why android 5.0 occur error java.lang.RuntimeException: start smooth zoom failed?