java.lang.RuntimeException: setAudioSource failed.

最近写个android程序,遇到下面这个错误:
java.lang.RuntimeException: setAudioSource failed.
详细报错如下:

12-16 22:04:41.637 14031-14031/com.hust.blue.xiaoxian E/AndroidRuntime: FATAL EXCEPTION: main                                                                        
Process: com.hust.blue.xiaoxian, PID: 14031
java.lang.RuntimeException: setAudioSource failed.
      at android.media.MediaRecorder.setAudioSource(Native Method)
      at com.hust.blue.xiaoxian.MainActivity.prepareVideoRecorder(MainActivity.java:104)
      at com.hust.blue.xiaoxian.MainActivity.access$400(MainActivity.java:24)
      at com.hust.blue.xiaoxian.MainActivity$1.onClick(MainActivity.java:71)
      at android.view.View.performClick(View.java:4457)
      at android.view.View$PerformClick.run(View.java:18491)
      at android.os.Handler.handleCallback(Handler.java:733)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:136)
      at android.app.ActivityThread.main(ActivityThread.java:5336)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
      at dalvik.system.NativeStart.main(Native Method)

解决办法:
在AndroidManifest.xml中添加如下权限:

<uses-permission  android:name="android.permission.RECORD_AUDIO"/>

你可能感兴趣的:(android)