Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference #326

Closed
sanxianlee opened this issue Nov 20, 2019 · 6 comments

Comments

@sanxianlee
Copy link

sanxianlee commented Nov 20, 2019

AudioCache _tipsPlayer = AudioCache(prefix: 'audio/', fixedPlayer: _alarmPlayer);
static AudioPlayer _alarmPlayer = AudioPlayer(mode: PlayerMode.LOW_LATENCY);
bool _isAlarmOn = false;

// open alarm

  void actionAlarmOn () async {
    if(_alarmPlayer != null){
      int state = await _alarmPlayer.stop();
      if(state == 1) {
        _alarmPlayer = await audio.loop("alarm.mp3");
        setState(() => _isAlarmOn = true);
      }
    }else{
      _alarmPlayer = await audio.loop("alarm.mp3");
      setState(() => _isAlarmOn = true);
    }

    Timer(Duration(seconds: 5), () {
      if (mounted) actionAlarmOff();
    });
  }

// close alarm function

void actionAlarmOff () async {
  if(_alarmPlayer  != null) {
    int state = await _alarmPlayer.stop(); // Unhandled Exception: PlatformException(error, Unsupported value: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null
    print("stop alarm:state:$state");
    if(state == 1){
      _alarmPlayer = null;
      setState(() => _isAlarmOn = false);
    }
  }
}

E/AudioplayersPlugin( 1861): Unexpected error!
E/AudioplayersPlugin( 1861): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/AudioplayersPlugin( 1861): 	at xyz.luan.audioplayers.WrappedSoundPool.stop(WrappedSoundPool.java:65)
E/AudioplayersPlugin( 1861): 	at xyz.luan.audioplayers.AudioplayersPlugin.handleMethodCall(AudioplayersPlugin.java:78)
E/AudioplayersPlugin( 1861): 	at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.java:41)
E/AudioplayersPlugin( 1861): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/AudioplayersPlugin( 1861): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/AudioplayersPlugin( 1861): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
E/AudioplayersPlugin( 1861): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/AudioplayersPlugin( 1861): 	at android.os.MessageQueue.next(MessageQueue.java:323)
E/AudioplayersPlugin( 1861): 	at android.os.Looper.loop(Looper.java:136)
E/AudioplayersPlugin( 1861): 	at android.app.ActivityThread.main(ActivityThread.java:6121)
E/AudioplayersPlugin( 1861): 	at java.lang.reflect.Method.invoke(Native Method)
E/AudioplayersPlugin( 1861): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
E/AudioplayersPlugin( 1861): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
E/MethodChannel#xyz.luan/audioplayers( 1861): Failed to handle method call
E/MethodChannel#xyz.luan/audioplayers( 1861): java.lang.IllegalArgumentException: Unsupported value: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:70)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:230)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.java:44)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at android.os.MessageQueue.next(MessageQueue.java:323)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at android.os.Looper.loop(Looper.java:136)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at android.app.ActivityThread.main(ActivityThread.java:6121)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
E/MethodChannel#xyz.luan/audioplayers( 1861): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
E/flutter ( 1861): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unsupported value: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null)
E/flutter ( 1861): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 1861): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
E/flutter ( 1861): <asynchronous suspension>
E/flutter ( 1861): #2      AudioPlayer._invokeMethod (package:audioplayers/audioplayers.dart:211:10)
E/flutter ( 1861): #3      AudioPlayer.stop (package:audioplayers/audioplayers.dart:268:30)
E/flutter ( 1861): <asynchronous suspension>
E/flutter ( 1861): #4      _AutoModeState.actionAlarmOff (package:zhct/views/business/autoMode_page.dart:475:38)
E/flutter ( 1861): <asynchronous suspension>
E/flutter ( 1861): #5      _AutoModeState.actionAlarmOn.<anonymous closure> (package:zhct/views/business/autoMode_page.dart:468:20)
E/flutter ( 1861): #6      _rootRun (dart:async/zone.dart:1120:38)
E/flutter ( 1861): #7      _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 1861): #8      _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter ( 1861): #9      _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter ( 1861): #10     _rootRun (dart:async/zone.dart:1124:13)
E/flutter ( 1861): #11     _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 1861): #12     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
E/flutter ( 1861): #13     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:21:15)
E/flutter ( 1861): #14     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
E/flutter ( 1861): #15     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
E/flutter ( 1861): #16     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
E/flutter ( 1861): 
@sanxianlee
Copy link
Author

thinks!

@mooreorless555
Copy link

I'm also having this issue! Any updates?

@Amberon
Copy link

Amberon commented Apr 28, 2020

Another example

E/AudioplayersPlugin(12635): Unexpected error!
E/AudioplayersPlugin(12635): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/AudioplayersPlugin(12635): 	at xyz.luan.audioplayers.WrappedSoundPool.setVolume(WrappedSoundPool.java:186)
E/AudioplayersPlugin(12635): 	at xyz.luan.audioplayers.AudioplayersPlugin.handleMethodCall(AudioplayersPlugin.java:64)
E/AudioplayersPlugin(12635): 	at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.java:44)

@yourshinsuke
Copy link

: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference

@pgainullin
Copy link

same thing happens to me but also preceded by:

E/AudioAttributes(20124): Invalid stream type -2147483648 for AudioAttributes
W/SoundPool(20124): App requested 100 channels

(from #335)

@erickzanardo
Copy link
Member

Closing this due to reports of this being fixed on newer versions. Feel free to open a new issue in case of this still happening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants