请教一个编写电话本app中的问题

作为一个初学者,第一次尝试写一个电话本的app,但是总是在手机上无法运行,一打开app就显示“已停止运行”。java代码如下:(代码挺长的,如果哪位大神帮我可以指出问题,那真是感谢啦!)
package com.example.phonecall;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity
implements AdapterView.OnItemLongClickListener, AdapterView.OnItemClickListener {
static final String DB_NAME="HotlineDB";
static final String TB_NAME="hotlist";
static final int MAX=8;
static final String[] FROM=
new String []{"name","phone","email"};
SQLiteDatabase db;
Cursor cur;
SimpleCursorAdapter adapter;
EditText etName,etPhone,etEmail;
Button btInsert,btUpdate,btDelete;
ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    etName=(EditText)findViewById(R.id.etName);
    etPhone=(EditText)findViewById(R.id.etPhone);
    etEmail=(EditText)findViewById(R.id.etEmail);
    btInsert=(Button)findViewById(R.id.btInsert);
    btUpdate=(Button)findViewById(R.id.btUpdate);
    btDelete=(Button)findViewById(R.id.btDelete);
    db=openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE,null);
    String createTable="CREATE TABLE IF NOT EXIST"+TB_NAME+
            "(_ID INTEGER PRIMARY KEY AUTOINCREMENT,"+
            "name VARCHAR(32),"+
            "phone VARCHAR(16),"+
            "email VARCHAR(64))";
    db.execSQL(createTable);

    cur=db.rawQuery("SELECT*FROM"+TB_NAME,null);
    if(cur.getCount()==0){
        addData("企标公司","02-23963257","service@flag.com");
        addData("七旬公司","02-23786787","bxjx@hja.com");

    }
    adapter=new SimpleCursorAdapter(this,R.layout.item,cur,FROM,
            new int[]{R.id.name,R.id.phone,R.id.email},0);
    lv=(ListView)findViewById(R.id.lv);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(this);
    requery();

}

private void addData(String name, String phone, String email) {
    ContentValues cv=new ContentValues(3);
    cv.put(FROM[0],name);
    cv.put(FROM[1],phone);
    cv.put(FROM[2],email);
    db.insert(TB_NAME,null,cv);

}
private void update(String name, String phone, String email,int id){
    ContentValues cv=new ContentValues(3);
    cv.put(FROM[0],name);
    cv.put(FROM[1],phone);
    cv.put(FROM[2],email);
    db.update(TB_NAME,cv,"_id="+id,null);
}

private void requery() {
    cur=db.rawQuery("SELECT*FROM"+TB_NAME,null);
    adapter.changeCursor(cur);
    if(cur.getCount()==MAX)
        btInsert.setEnabled(false);
    else
        btInsert.setEnabled(true);
    btUpdate.setEnabled(false);
    btDelete.setEnabled(false);
}


@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    cur.moveToPosition(position);
    etName.setText(cur.getString(
            cur.getColumnIndex(FROM[0])));
    etPhone.setText(cur.getString(
            cur.getColumnIndex(FROM[1])));
    etEmail.setText(cur.getString(
            cur.getColumnIndex(FROM[2])));
    btUpdate.setEnabled(true);
    btDelete.setEnabled(true);

}
public void onInsertUpdate(View v){
    String nameStr=etName.getText().toString().trim();
    String phoneStr=etPhone.getText().toString().trim();
    String emailStr=etEmail.getText().toString().trim();
    if(nameStr.length()==0 || phoneStr.length()==0 ||emailStr.length()==0)
        return;


    if(v.getId()==R.id.btUpdate)
        update(nameStr,phoneStr,emailStr,cur.getInt(0));
    else
        addData(nameStr,phoneStr,emailStr);
    requery();
}
public void onDelete(View v){
    db.delete(TB_NAME,"_id="+cur.getInt(0),null);
    requery();
}
public void call(View v){
    String uri="tel:"+cur.getString(
            cur.getColumnIndex(FROM[1]));
    Intent it=new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    startActivity(it);
}

public void mail(View v){
    String uri="mailto:"+cur.getString(
            cur.getColumnIndex(FROM[2])
    );
    Intent it=new Intent(Intent.ACTION_SENDTO,Uri.parse(uri));
    startActivity(it);
}


@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    return false;
}

}
![图片说明](https://img-ask.csdn.net/upload/201702/04/1486203476_235630.png)图片说明

2个回答

连接手机或者用模拟器调试下,输出异常信息才好判断。如果你的代码都是抄来的,并且人家能运行,那么检查下数据库的驱动,连接,数据库文件和权限。

用数据库存储数据,什么数据库,数据库名写在哪里没看到?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!