2017-04-11 91 views
-1

好吧,所以我是新的android工作室,我搞亂了一個愚蠢的放屁噪聲應用程序。我的第一次嘗試是一個單一的按鈕,現在我有三個按鈕,但應用程序無法在模擬器中打開。它說的是應用程序不斷關閉。我試圖谷歌log貓的每一個錯誤,但迄今沒有任何工作。我嘗試了幾個不同的模擬器,但最初它工作,所以不知道要改變什麼。聲音文件是.mp3不確定是否重要。Android工作室應用程序不斷關閉

這是我的日誌貓

11月4日至10日:41:16.090 2082- 2082/com.google.android.googlequicksearchbox:搜索I/MicroDetectionWorker:微檢測模式:[mDetectionMode:[1] ]。 04-10 11:41:16.090 2082-2082/com.google.android.googlequicksearchbox:搜索I/AudioController:使用mInputStreamFactoryBuilder 04-10 11:41:16.096 2082-3754/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner:開始檢測。 04-10 11:41:16.096 2082-2158/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream:mic_starting [email protected] 04-10 11:41: 16.097 1304-2583 /? W/APM_AudioPolicyManager:getInputForAttr()未能打開輸入:samplingRate 16000,format 1,channelMask 10 04-10 11:41:16.097 2082-2158/com.google.android.googlequicksearchbox:search E/AudioRecord:無法獲取音頻輸入對於會話1097,記錄源1999,採樣率16000,格式0x1,通道掩碼0x10,標記0 04-10 11:41:16.097 2082-2158/com.google.android.googlequicksearchbox:搜索E/AudioRecord-JNI:錯誤創建AudioRecord實例:初始化檢查失敗,狀態爲-22。 04-10 11:41:16.097 2082-2158/com.google.android.googlequicksearchbox:在初始化本地AudioRecord對象時搜索E/android.media.AudioRecord:錯誤代碼-20。 04-10 11:41:16.097 2082-2158/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream:mic_started [email protected] 04-10 11:41: 16.098 2082-2158/com.google.android.googlequicksearchbox:search E/ActivityThread:無法找到com.google.android.apps.gsa.testing.ui.audio.recorded的提供者信息 04-10 11:41:16.098 2082-2082/com.google.android.googlequicksearchbox:搜索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.zc @ 1f9150b 04-10 11:41:16.103 2082-3754/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner:檢測完成 04-10 11:41:16.103 2082-3754 /com.google.android.googlequicksearchb ox:搜索W/ErrorReporter:reportError [type:211,code:524300]:從輸入流讀取時出錯 04-10 11:41:16.103 2082-3754/com.google.android.googlequicksearchbox:search W/ErrorProcessor:onFatalError ,來自引擎的處理錯誤(4) com.google.android.apps.gsa.shared.speech.ag:從輸入流 (從com.google.android.apps.gsa.staticplugins.recognizer.iaa(SourceFile: 342) at com.google.android.apps.gsa.staticplugins.recognizer.ia $ 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。運行(SourceFile:85) 引起:com.google.android.apps.gsa.shared.exception.GsaIOException:錯誤代碼:393238 |緩衝區溢出,沒有可用空間。 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。在java.util.concurrent.Exccutors $ 1.run(SourceFile:471) $ RunnableAdapter.call(Executors.java:428) ) 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。運行(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:搜索I/AudioController:internalShutdown 04-10 11:41:16.103 2082-2310/com.google .android.googlequicksearchbox:搜索I/MicroRecognitionRunner:停止熱門詞彙檢測。 04-10 11:41:16.114 2082-2082/com.google.android.googlequicksearchbox:search I/MicroDetector:保持麥克風打開:false 04-10 11:41:16.114 2082-2082/com.google.android。 googlequicksearchbox:搜索I/MicroDetectionWorker:#onError(假) 11月4日至10日:41:16.114 2082-3753/com.google.android.googlequicksearchbox:搜索I/DeviceStateChecker:DeviceStateChecker取消

這裏是我的。 Java文件

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(); 
       } 
      }); */ 


     } 
    } 

這裏是我的.xml文件

<?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> 
+1

您的放屁問題是使用AS還是您的應用程序?不知道爲什麼人們堅持要開發Android Studio ...我從來沒有看到過這款應用。 IDE是一個(非常基本)的東西,APP是其他的,同意?對。您的logcat說:com.google.android.apps.gsa.shared.exception.GsaIOException:錯誤代碼:393238 |緩衝區溢出,沒有可用空間。可能你做錯了閱讀策略。另外,我看到你沒有回收你的媒體播放器。搜索媒體播放器生命週期,這是你的問題。你必須釋放它。在Android中,它不僅僅是實例化mp並點擊,沒有 – statosdotcom

+1

請過濾您的logcat,以便僅顯示您的應用程序上下文 –

+1

這是您的應用程序崩潰。不是Android Studio –

回答

1

您初始化按鈕的方式是錯誤的。這是初始化視圖的正確方法:

button1 = (Button)findViewById(R.id.button1); 
button2 = (Button)findViewById(R.id.button2); 
button3 = (Button)findViewById(R.id.button3); 
+0

:)我喜歡當我忽略簡單的東西...也謝謝你有趣的部分是我一見到它就去哇我爲什麼要這樣做自己。 –

相關問題