这个问题在这里已有答案:
这是我的logcat。我的xml和java没有错误,我不知道为什么会发生这种错误。
09-11 13:59:00.227 1358-4700/? E/AudioFlinger: not enough memory for AudioTrack size=131296
09-11 13:59:00.227 1358-4700/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
09-11 13:59:00.227 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
09-11 13:59:00.237 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
09-11 13:59:00.237 3487-8295/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
09-11 13:59:00.296 3487-8295/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
09-11 13:59:05.482 1358-2355/? E/AudioFlinger: not enough memory for AudioTrack size=131296
09-11 13:59:05.483 1358-2355/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
09-11 13:59:05.493 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
09-11 13:59:05.515 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
09-11 13:59:05.515 3487-8295/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
09-11 13:59:05.517 3487-8295/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
09-11 13:59:10.626 1358-3721/? E/AudioFlinger: not enough memory for AudioTrack size=131296
09-11 13:59:10.626 1358-3721/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
09-11 13:59:10.626 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
09-11 13:59:10.641 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
09-11 13:59:10.641 3487-8295/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
09-11 13:59:10.672 3487-8295/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
09-11 13:59:15.155 8980-8980/? E/memtrack: Couldn't load memtrack module (No such file or directory)
09-11 13:59:15.155 8980-8980/? E/android.os.Debug: failed to load memtrack module: -2
09-11 13:59:15.195 8983-8983/? E/memtrack: Couldn't load memtrack module (No such file or directory)
09-11 13:59:15.196 8983-8983/? E/android.os.Debug: failed to load memtrack module: -2
09-11 13:59:15.767 1358-1401/? E/AudioFlinger: not enough memory for AudioTrack size=131296
09-11 13:59:15.767 1358-1401/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
09-11 13:59:15.767 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
09-11 13:59:15.784 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
09-11 13:59:15.784 3487-8295/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
09-11 13:59:15.791 3487-8295/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
09-11 13:59:17.974 9008-9008/? E/memtrack: Couldn't load memtrack module (No such file or directory)
09-11 13:59:17.974 9008-9008/? E/android.os.Debug: failed to load memtrack module: -2
09-11 13:59:19.005 9017-9017/com.example.xh3al3r.myapplication2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.xh3al3r.myapplication2, PID: 9017
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xh3al3r.myapplication2/com.example.xh3al3r.myapplication2.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.xh3al3r.myapplication2.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
09-11 13:59:21.202 1358-3721/? E/AudioFlinger: not enough memory for AudioTrack size=131296
09-11 13:59:21.202 1358-3721/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
09-11 13:59:21.202 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
09-11 13:59:21.380 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
09-11 13:59:21.380 3487-8295/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
09-11 13:59:21.530 3487-8295/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
09-11 13:59:26.651 1358-1358/? E/AudioFlinger: not enough memory for AudioTrack size=131296
09-11 13:59:26.651 1358-1358/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
09-11 13:59:26.652 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
09-11 13:59:26.658 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
09-11 13:59:26.661 1250-1289/? E/vold: Failed to open /proc/7488: No such file or directory
09-11 13:59:26.663 1756-2081/system_process E/MountService: Failed to unmount appfuse.
09-11 13:59:26.664 3487-8295/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
09-11 13:59:26.687 3487-8295/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
09-11 13:59:31.792 1358-4700/? E/AudioFlinger: not enough memory for AudioTrack size=131296
09-11 13:59:31.792 1358-4700/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
09-11 13:59:31.792 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
09-11 13:59:31.802 3487-8295/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
09-11 13:59:31.802 3487-8295/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
09-11 13:59:31.804 3487-8295/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
在设置onClickListener之前,必须在oncreate()
方法中初始化按钮
yourButtonName=(Button)findViewById(R.id.yourbuttonid);
比尝试设置点击监听器。希望所以它的帮助你:)