![](/img/trans.png)
[英]Android Studio: Code is done, but app is crashing everytime I try to run
[英]Android Studio, app will not run without crashing
我正在尝试用我的Java开发的Android Studio开发一个非常简单的应用程序,这是我的第一个应用程序项目。 我目前没有编写很多代码,但是每次应用程序尝试运行时,它都会“停止工作”并且永远不会打开。
我不太肯定我正在寻找Logcat的错误部分,但这是我相信Logcat告诉我的内容。
2018-10-10 17:21:03.291 11777-20641/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)
这就是我项目的全部代码(几乎没有)
Button rollButton = findViewById(R.id.rollButton);
TextView numberRoll = findViewById(R.id.numberRoll);
SeekBar amountSeek = findViewById(R.id.amountSeek);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rollButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Random ran = new Random();
ran.nextInt(amountSeek.getProgress());
numberRoll.setText(ran.toString());
}
});
}
}
如果那是正确的错误,那么看来这是模拟器空间不足或其他问题。 但是我不知道如何解决这个问题。
有什么帮助吗?
定义布局文件后,将以下行移动到onCreate函数
Button rollButton = findViewById(R.id.rollButton);
TextView numberRoll = findViewById(R.id.numberRoll);
SeekBar amountSeek = findViewById(R.id.amountSeek);
您在定义资源文件之前调用资源。 这是定义资源文件的功能。
setContentView(R.layout.activity_main);
您的代码应为
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button rollButton = findViewById(R.id.rollButton);
TextView numberRoll = findViewById(R.id.numberRoll);
SeekBar amountSeek = findViewById(R.id.amountSeek);
rollButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Random ran = new Random();
ran.nextInt(amountSeek.getProgress());
numberRoll.setText(ran.toString());
}
});
}
或者如果你喜欢
Button rollButton;
TextView numberRoll;
SeekBar amountSeek;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rollButton = findViewById(R.id.rollButton);
numberRoll = findViewById(R.id.numberRoll);
amountSeek = findViewById(R.id.amountSeek);
rollButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Random ran = new Random();
ran.nextInt(amountSeek.getProgress());
numberRoll.setText(ran.toString());
}
});
}
并确保ID都已在您的xml文件中设置。
只需在R.id之后加上点即可。 然后等待Android Studio显示您资源文件中所有ID的下拉列表。 这样,您可以防止错别字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.