Reputation: 41
okay so i am new to android studios, and i was messing around with a stupid fart noise app. My first attempt was a single button that played a noise now i have three buttons but the app won't open in the emulator. all it says is app keeps closing. i have tried to google every error in the log cat but nothing worked for me so far. I tried a couple different emulators but originally it worked so not sure what to change. the sound files are .mp3 not sure if that matters.
this is my log cat
04-10 11:41:16.090 2082- 2082/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: Micro detection mode: [mDetectionMode: [1]]. 04-10 11:41:16.090 2082-2082/com.google.android.googlequicksearchbox:search I/AudioController: Using mInputStreamFactoryBuilder 04-10 11:41:16.096 2082-3754/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Starting detection. 04-10 11:41:16.096 2082-2158/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_starting com.google.android.apps.gsa.staticplugins.z.c@1f9150b 04-10 11:41:16.097 1304-2583/? W/APM_AudioPolicyManager: getInputForAttr() failed opening input: samplingRate 16000, format 1, channelMask 10 04-10 11:41:16.097 2082-2158/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 1097, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0 04-10 11:41:16.097 2082-2158/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22. 04-10 11:41:16.097 2082-2158/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object. 04-10 11:41:16.097 2082-2158/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_started com.google.android.apps.gsa.staticplugins.z.c@1f9150b 04-10 11:41:16.098 2082-2158/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded 04-10 11:41:16.098 2082-2082/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: onReady 04-10 11:41:16.101 2082-2158/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_close com.google.android.apps.gsa.staticplugins.z.c@1f9150b 04-10 11:41:16.103 2082-3754/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Detection finished 04-10 11:41:16.103 2082-3754/com.google.android.googlequicksearchbox:search W/ErrorReporter: reportError [type: 211, code: 524300]: Error reading from input stream 04-10 11:41:16.103 2082-3754/com.google.android.googlequicksearchbox:search W/ErrorProcessor: onFatalError, processing error from engine(4) com.google.android.apps.gsa.shared.speech.a.g: Error reading from input stream at com.google.android.apps.gsa.staticplugins.recognizer.i.a.a(SourceFile:342) at com.google.android.apps.gsa.staticplugins.recognizer.i.a$1.run(SourceFile:1367) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:66) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) at com.google.android.apps.gsa.shared.util.concurrent.a.ad$1.run(SourceFile:85) Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space. at com.google.android.apps.gsa.speech.audio.Tee.g(SourceFile:2531) at com.google.android.apps.gsa.speech.audio.ap.read(SourceFile:555) at java.io.InputStream.read(InputStream.java:101) at com.google.android.apps.gsa.speech.audio.al.run(SourceFile:362) at com.google.android.apps.gsa.speech.audio.ak$1.run(SourceFile:471) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:66) at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:139) at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:139) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) at com.google.android.apps.gsa.shared.util.concurrent.a.ad$1.run(SourceFile:85) 04-10 11:41:16.103 2082-3754/com.google.android.googlequicksearchbox:search I/AudioController: internalShutdown 04-10 11:41:16.103 2082-2310/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Stopping hotword detection. 04-10 11:41:16.114 2082-2082/com.google.android.googlequicksearchbox:search I/MicroDetector: Keeping mic open: false 04-10 11:41:16.114 2082-2082/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: #onError(false) 04-10 11:41:16.114 2082-3753/com.google.android.googlequicksearchbox:search I/DeviceStateChecker: DeviceStateChecker cancelled
here is my .java file
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
public class MainActivity extends AppCompatActivity {
Button button1,button2,button3;
private MediaPlayer fartSound1MP;
//private MediaPlayer fartSound2MP;
//private MediaPlayer fartSound3MP;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fartSound1MP = MediaPlayer.create(this, R.raw.fart01);
//fartSound2MP = MediaPlayer.create(this, R.raw.fart03);
//fartSound3MP = MediaPlayer.create(this, R.raw.fartsqueak01);
button1.findViewById(R.id.button1);
button2.findViewById(R.id.button2);
button3.findViewById(R.id.button3);
button1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
fartSound1MP.start();
}
});
/* button2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
fartSound2MP.start();
}
});
button3.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
fartSound3MP.start();
}
}); */
}
}
here is my .xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.francisagostini.fart"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click buttons for different fart noises!"
android:layout_marginBottom="16dp"
android:textSize="30sp"
tools:ignore="HardcodedText" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/textView" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fart1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fart2"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fart3"
tools:ignore="HardcodedText" />
</LinearLayout>
</RelativeLayout>
Upvotes: 0
Views: 3568
Reputation: 2866
The way you initialize the button is wrong. This is the correct way to initialize the view:
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
button3 = (Button)findViewById(R.id.button3);
Upvotes: 1