Android Studio 调试出现“很抱歉,XXX已停止运行”,可代码没报错

weixin_46006421 2020-05-21 04:16:11
模拟器运行后界面显示正常:
但是点击按钮就任务结束:



这是activity_main:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/ll_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ll_phone"
android:layout_alignLeft="@+id/ll_btn"
android:layout_alignStart="@+id/ll_btn">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="姓 名:"/>
<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:hint="请输入姓名"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ll_phone"
android:layout_marginBottom="10dp"
android:layout_above="@+id/ll_btn"
android:layout_alignLeft="@+id/ll_name"
android:layout_alignStart="@+id/ll_name">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="电 话:"/>
<EditText
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:hint="请输入手机号码"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ll_btn"
android:layout_centerVertical="true">
<Button
android:id="@+id/btn_add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp"
android:background="#B9B9FF"
android:layout_marginRight="2dp"
android:text="添加"/>
<Button
android:id="@+id/btn_query"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp"
android:background="#DCB5FF"
android:layout_marginRight="2dp"
android:text="查询"/>
<Button
android:id="@+id/btn_update"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp"
android:background="#E6CAFF"
android:layout_marginRight="2dp"
android:text="修改"/>
<Button
android:id="@+id/btn_delete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp"
android:background="#ACD6FF"
android:text="删除"/>
</LinearLayout>
<TextView
android:id="@+id/tv_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_below="@+id/ll_btn"
android:textSize="20sp"/>
</RelativeLayout>



这是MainActivity:

package cn.itcast.directory;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
MyHelper myHelper;
private EditText mEtName;
private EditText mEtPhone;
private TextView mTvShow;
private Button mBtnAdd;
private Button mBtnQuery;
private Button mBtnUpdate;
private Button mBtnDelate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myHelper = new MyHelper(this);
init();
}
private void init() {
mEtName = (EditText) findViewById(R.id.et_name);
mEtPhone = (EditText) findViewById(R.id.et_phone);
mTvShow = (TextView) findViewById(R.id.tv_show);
mBtnAdd = (Button) findViewById(R.id.btn_add);
mBtnQuery = (Button) findViewById(R.id.btn_query);
mBtnUpdate = (Button) findViewById(R.id.btn_update);
mBtnDelate = (Button) findViewById(R.id.btn_delete);
mBtnAdd.setOnClickListener(this);
mBtnQuery.setOnClickListener(this);
mBtnUpdate.setOnClickListener(this);
mBtnDelate.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String name;
String phone;
SQLiteDatabase db;
ContentValues values;
switch (v.getId()) {
case R.id.btn_add:
name = mEtName.getText().toString();
phone = mEtPhone.getText().toString();
db = myHelper.getWritableDatabase();
values = new ContentValues();
values.put("name",name);
db.insert("information",null,values);
Toast.makeText(this,"信息已添加",Toast.LENGTH_SHORT).show();
db.close();
break;
case R.id.btn_query:
db = myHelper.getReadableDatabase();
Cursor cursor = db.query("information",null,null,null,null,null,null);
if (cursor.getCount() == 0) {
mTvShow.setText("");
Toast.makeText(this,"没有数据",Toast.LENGTH_SHORT).show();
} else {
cursor.moveToFirst();
mTvShow.setText("Name :" + cursor.getString(1)+" : Tel :" + cursor.getString(2));
}
cursor.close();
db.close();
break;
case R.id.btn_update:
db = myHelper.getWritableDatabase();
values = new ContentValues();
values.put("phone",phone = mEtPhone.getText().toString());
db.update("information",values,"name=?",new String[]{mEtName.getText().toString()});
Toast.makeText(this,"信息已修改",Toast.LENGTH_SHORT).show();
db.close();
break;
case R.id.btn_delete:
db = myHelper.getWritableDatabase();
db.delete("information",null,null);
Toast.makeText(this,"信息已删除",Toast.LENGTH_SHORT).show();
mTvShow.setText("");
db.close();
break;
}
}
class MyHelper extends SQLiteOpenHelper {
public MyHelper(Context context) {
super(context,"itcast.db",null,1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE information(_id INTEGER PRIMARY KEY AUTOTNCREMENT,name VARCHAR(20),phone VARCHAR(20))");
}
@Override
public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){

}
}
}
...全文
1211 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_31699831 2020-05-28
  • 打赏
  • 举报
回复
引用 10 楼 熊猫vs笨笨 的回复:
[quote=引用 9 楼 妈的_智障啊 的回复:] [quote=引用 7 楼 熊猫vs笨笨 的回复:] Android操作数据库需要在子线程中执行。你直接在主线程中操作数据库当然报错误了。修改一下数据库操作就可以了。
只能在子线程中执行?我咋没听说过这个说法,一般是单纯的非耗时数据库操作,我都是在主线程操作的,除了占用了资源之外,并未报错过,我只知道,数据库不能做并发写入操作,还真不知道不能在主线程操作。[/quote] [/quote] 我还真没注意过这个,我做的全局数据库管理,专门给数据库的创建和更新预留了线程,但是数据库的读取和写入都是同步操作,从不用子线程异步操作
熊猫vs笨笨 2020-05-27
  • 打赏
  • 举报
回复
引用 9 楼 妈的_智障啊 的回复:
[quote=引用 7 楼 熊猫vs笨笨 的回复:] Android操作数据库需要在子线程中执行。你直接在主线程中操作数据库当然报错误了。修改一下数据库操作就可以了。
只能在子线程中执行?我咋没听说过这个说法,一般是单纯的非耗时数据库操作,我都是在主线程操作的,除了占用了资源之外,并未报错过,我只知道,数据库不能做并发写入操作,还真不知道不能在主线程操作。[/quote]
qq_31699831 2020-05-26
  • 打赏
  • 举报
回复
引用 7 楼 熊猫vs笨笨 的回复:
Android操作数据库需要在子线程中执行。你直接在主线程中操作数据库当然报错误了。修改一下数据库操作就可以了。
只能在子线程中执行?我咋没听说过这个说法,一般是单纯的非耗时数据库操作,我都是在主线程操作的,除了占用了资源之外,并未报错过,我只知道,数据库不能做并发写入操作,还真不知道不能在主线程操作。
王能 2020-05-24
  • 打赏
  • 举报
回复
错误日志发的不对,再看看教程。 idea的黄色提示或者红线提示要仔细看看,如你的单词AUTOTNCREMENT,这都能打错
熊猫vs笨笨 2020-05-22
  • 打赏
  • 举报
回复
Android操作数据库需要在子线程中执行。你直接在主线程中操作数据库当然报错误了。修改一下数据库操作就可以了。
雕·不懒惰 2020-05-22
  • 打赏
  • 举报
回复
闪退没Log吗,不会过滤就去看看版主大神的文章
https://blog.csdn.net/weimingjue/article/details/87921494
weixin_46006421 2020-05-21
  • 打赏
  • 举报
回复
log cat(一直都是这段话循环): 05-21 11:23:16.980 2267-3473/com.google.android.googlequicksearchbox:search I/AudioController: internalShutdown 05-21 11:23:16.982 2267-2267/com.google.android.googlequicksearchbox:search I/MicroDetector: Keeping mic open: false 05-21 11:23:16.982 2267-2267/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: #onError(false) 05-21 11:23:16.982 2267-3472/com.google.android.googlequicksearchbox:search I/DeviceStateChecker: DeviceStateChecker cancelled 05-21 11:23:20.759 2460-2883/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.music componentName=null serviceId=SEARCH_CORPORA 05-21 11:23:20.769 2460-3334/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 05-21 11:23:20.790 2460-2883/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.music componentName=null serviceId=SEARCH_CORPORA 05-21 11:23:20.798 2460-3334/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 05-21 11:23:20.820 2460-2946/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.music componentName=null serviceId=SEARCH_CORPORA 05-21 11:23:20.830 2460-3334/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 05-21 11:23:20.836 2460-2946/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.music componentName=null serviceId=SEARCH_CORPORA 05-21 11:23:20.853 2460-3334/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 05-21 11:23:20.860 2460-2883/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.music componentName=null serviceId=SEARCH_CORPORA 05-21 11:23:20.870 2460-3334/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 05-21 11:23:20.876 2460-2946/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.music componentName=null serviceId=SEARCH_CORPORA 05-21 11:23:20.884 2460-3334/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 05-21 11:23:20.889 2460-2883/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.music componentName=null serviceId=SEARCH_CORPORA 05-21 11:23:20.901 2460-3334/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 05-21 11:23:21.989 2267-2267/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: Micro detection mode: [mDetectionMode: [1]]. 05-21 11:23:21.989 2267-2267/com.google.android.googlequicksearchbox:search I/AudioController: Using mInputStreamFactoryBuilder 05-21 11:23:21.992 2267-3481/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Starting detection. 05-21 11:23:21.993 2267-2346/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_starting com.google.android.apps.gsa.staticplugins.z.c@3abd3bb 05-21 11:23:21.996 1407-3484/? I/AudioFlinger: AudioFlinger's thread 0xb2703d00 ready to run 05-21 11:23:22.005 2267-2346/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_started com.google.android.apps.gsa.staticplugins.z.c@3abd3bb 05-21 11:23:22.006 2267-2346/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded 05-21 11:23:22.006 2267-2267/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: onReady 05-21 11:23:22.009 2267-2346/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_close com.google.android.apps.gsa.staticplugins.z.c@3abd3bb 05-21 11:23:22.010 2267-3481/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Detection finished 05-21 11:23:22.010 2267-3481/com.google.android.googlequicksearchbox:search W/ErrorReporter: reportError [type: 211, code: 524300]: Error reading from input stream 05-21 11:23:22.010 2267-2448/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Stopping hotword detection. 05-21 11:23:22.010 2267-3481/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) 
HL_GT 2020-05-21
  • 打赏
  • 举报
回复
贴logvat里面的错误日志
usecf 2020-05-21
  • 打赏
  • 举报
回复
用真机调试下 抓下adb log
weixin_46006421 2020-05-21
  • 打赏
  • 举报
回复
求大佬帮忙看看怎么解决!

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧