sqliteexception:没有sutch表:文章,同时编译:select * from Article

时间:2015-08-21 11:08:19

标签: android

我正在尝试为以下图表实施者准备一个迷你项目

以下是源代码:

import android.app.Activity;
import android.app.Dialog;
import android.database.Cursor;
import android.os.Bundle;
import android.text.Spannable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

public class AddArticle extends Activity {
EditText txtName;

TextView txtarticle;
DatabaseHelper dbHelper;
Spinner spinArticle;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addarticle);
    txtName=(EditText)findViewById(R.id.txtCode);

    txtarticle=(TextView)findViewById(R.id.txtarti);
    spinArticle=(Spinner)findViewById(R.id.spinarti);

    try
    {
    super.onStart();
    dbHelper=new DatabaseHelper(this);
    txtarticle.setText(txtarticle.getText()+String.valueOf(dbHelper.getArticlesCount()));

    Cursor c=dbHelper.getAllSFamilles();
    startManagingCursor(c);



    //SimpleCursorAdapter ca=new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item, c, new String [] {DatabaseHelper.colDeptName}, new int []{android.R.id.text1});
    SimpleCursorAdapter ca=new SimpleCursorAdapter(this,R.layout.sfamillespinnerrow, c, new String [] {DatabaseHelper.colSFamName,"_id"}, new int []{R.id.txtsfamname});
    //ca.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinArticle.setAdapter(ca);
    spinArticle.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View selectedView,
                int position, long id) {
            // TODO Auto-generated method stub

        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });


    //never close cursor
    }
    catch(Exception ex)
    {
        CatchError(ex.toString());
    }
}

/*@Override
public void onStart()
{

}*/

public void btnAddEmp_Click(View view)
{
    boolean ok=true;
    try
    {

        String name=txtName.getText().toString();

        int deptID=Integer.valueOf((int)spinArticle.getSelectedItemId());
        Article emp=new Article(name,deptID);

        dbHelper.ajoutArticle(emp);

    }
    catch(Exception ex)
    {
        ok=false;
        CatchError(ex.toString());
    }
    finally
    {
        if(ok)
        {
            //NotifyEmpAdded();
            AlertsArticle.ShowEmpAddedAlert(this);
            txtarticle.setText("Number of employees "+String.valueOf(dbHelper.getArticlesCount()));
        }
    }
}

void CatchError(String Exception)
{
    Dialog diag=new Dialog(this);
    diag.setTitle("Add new Employee");
    TextView txt=new TextView(this);
    txt.setText(Exception);
    diag.setContentView(txt);
    diag.show();
}

void NotifyEmpAdded()
{
    Dialog diag=new Dialog(this);
    diag.setTitle("Add new Employee");
    TextView txt=new TextView(this);
    txt.setText("Employee Added Successfully");
    diag.setContentView(txt);
    diag.show();
    try {
        diag.wait(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        CatchError(e.toString());
    }
    diag.notify();
    diag.dismiss();
}

}

我需要帮助它已经六天了,我找不到解决方案

1 个答案:

答案 0 :(得分:0)

可能,这就是发生的事情:

您添加了表格in a second moment 但是,由于您没有增加 DATABASE_VERSION 常量,onUpgrade()方法不会被激活(因此,不会删除任何表并重新创建)。< / p>

解决方案:从您的模拟器或设备卸载并重新安装应用程序 现在,数据库将重新创建,您就可以了。