我正在开发一个从连接到音频插孔的设备获取一些信息的API,但是当我尝试在华硕MEMO Pad 7(使用android 4.3)上调试我的应用程序时,我收到此错误:
java.lang.RuntimeException: Unable to start service com.walker.integration.WalkerService@21a3f7e0 with Intent { cmp=mx.com.mitec.testmit/com.walker.integration.WalkerService (has extras) }: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2877)
at android.app.ActivityThread.access$1900(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1452)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5406)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
at android.media.AudioRecord.startRecording(AudioRecord.java:537)
at com.bbpos.emvswipe.k.b(SourceFile:73)
at com.bbpos.emvswipe.EmvSwipeController.startAudio(SourceFile:3410)
at com.walker.integration.WalkerService.initEmvSwipeController(SourceFile:61)
at com.walker.integration.WalkerService.onStart(SourceFile:96)
at android.app.Service.onStartCommand(Service.java:450)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2860)
at android.app.ActivityThread.access$1900(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1452)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5406)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
当我试图在我的手机Moto G(使用android 4.4)上运行它时,不会发生某些事情,我不知道发生了什么或者如何解决它。
我看着我的清单,看看我是否付出了错误,或者我犯了错误的minsdkversion,但这不是问题所在。
这是我的清单:
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.GET_TASKS"></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
答案 0 :(得分:0)
错误应该准确描述问题。 AudioRecord对象未初始化,您在其上调用了startRecording。
要初始化AudioRecord对象,请尝试
audioRecordObj = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, sampleRate, channelConfiguration, audioEncoding, bufferSize);
其中`
int sampleRate = 8000; //Hz
int channelConfiguration = AudioFormat.CHANNEL_IN_MONO;
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
int bufferSize = 60000;
仅作为一个例子。请参阅docs。
中的详情