Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 列不存在:Android应用程序中存在非法参数异常_Java_Android_Sqlite_Android Sqlite - Fatal编程技术网

Java 列不存在:Android应用程序中存在非法参数异常

Java 列不存在:Android应用程序中存在非法参数异常,java,android,sqlite,android-sqlite,Java,Android,Sqlite,Android Sqlite,在下面的活动中,用户必须输入定义的字段。输入后,用户可以编辑更改并保存。但是,在我的应用程序中,条目已成功插入到数据库中,但在编辑相同字段时,我收到一个非法参数异常,即网站_1列不存在,尽管我在数据库中签入了该列。提前感谢 注意:populateFields是我得到错误的方法。活动启动后,将调用populateField方法来填充字段 public class Newform_Screen2_Likewebsite_edit extends Activity { EditText w1,

在下面的活动中,用户必须输入定义的字段。输入后,用户可以编辑更改并保存。但是,在我的应用程序中,条目已成功插入到数据库中,但在编辑相同字段时,我收到一个非法参数异常,即网站_1列不存在,尽管我在数据库中签入了该列。提前感谢

注意:populateFields是我得到错误的方法。活动启动后,将调用populateField方法来填充字段

public class Newform_Screen2_Likewebsite_edit extends Activity {
    EditText w1,c1,w2,c2,w3,c3;
    Button btn_save;
    private String srowId;
    DBAdapter dba;
    SQLiteDatabase myDB;
    private Context context;    



    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      setContentView(R.layout.newform_screen2_websites);


        dba=new DBAdapter(this);
        context=Newform_Screen2_Likewebsite_edit.this;
        final Intent intent = getIntent();
        srowId=intent.getStringExtra("KEYROWID");

        myDB=DBAdapter.openDatabase(context, DBAdapter.DATABASE_NAME);

        w1=(EditText)findViewById(R.id.www1_web_id);
        w2=(EditText)findViewById(R.id.www2_web_id);
        w3=(EditText)findViewById(R.id.www3_web_id);
        c1=(EditText)findViewById(R.id.color1_id);
        c2=(EditText)findViewById(R.id.color2_id);
        c3=(EditText)findViewById(R.id.color3_id);
        btn_save=(Button)findViewById(R.id.btn_save_web);


          populateFields();



        btn_save.setOnClickListener(new OnClickListener(){


            public void onClick(View v) {
                n2();
                n1();


            }

            private void n2() {

       dba = new DBAdapter(Newform_Screen2_Likewebsite_edit.this);


                   String s1=w1.getText().toString();
                   String s2=w2.getText().toString();
                   String s3=w3.getText().toString();
                   String s4=c1.getText().toString();
                   String s5=c2.getText().toString();
                   String s6=c3.getText().toString();

                String updatequery  = "UPDATE "+ DBAdapter.DATABASE_TABLE+ " SET ";
                updatequery = updatequery + DBAdapter.KEY_WEBSITE_1+" = '" + s1 +"',";
                updatequery = updatequery + DBAdapter.KEY_WEBSITE_2+" = '" + s2 + "',";
                updatequery = updatequery + DBAdapter.KEY_WEBSITE_3+" = '" + s3 + "',";
                updatequery = updatequery + DBAdapter.KEY_COLOR_1+" = '" + s4 + "',";
                updatequery = updatequery + DBAdapter.KEY_COLOR_2+" = '" + s5 + "',";
                updatequery = updatequery + DBAdapter.KEY_COLOR_3+" = '"+s6+"'";
                updatequery = updatequery + " WHERE _id = '" + srowId + "';";
                Log.v("updatequery-new-likewebsite-edit",updatequery);

                try{

                    Log.v("test-2","update");
                    dba.open();
                    myDB.execSQL(updatequery);

                }catch(NullPointerException e){

                    e.getMessage();
                }finally{
                    Log.v("test-3","update");

                    if(myDB != null)myDB.close();
                    dba.close();
                }

            }

            private void Log(String string) {
                Log.i("Activity-check",""+string);

            }


            private void n1() {

                Intent I = new Intent(Newform_Screen2_Likewebsite_edit.this,Newform_Screen2_edit.class);
                I.putExtra("rowid", srowId);
                startActivity(I);

            }

        });


    }


    private void populateFields() {
        dba.open();


         if (srowId != null) {
             Log.v("rowid",srowId.toString());
             long mRowId=Long.parseLong(srowId);
                Cursor cur = dba.fetchSaleseditdetails(mRowId);
                startManagingCursor(cur);
                try{

                    Log.v("test populate","test populate");

                w1.setText(cur.getString(cur.getColumnIndexOrThrow(DBAdapter.KEY_WEBSITE_1)));
                w2.setText(cur.getString(cur.getColumnIndexOrThrow(DBAdapter.KEY_WEBSITE_2)));
                w3.setText(cur.getString(cur.getColumnIndexOrThrow(DBAdapter.KEY_WEBSITE_3)));
                c1 .setText(cur.getString(cur.getColumnIndexOrThrow(DBAdapter.KEY_COLOR_1)));
                c2.setText(cur.getString(cur.getColumnIndexOrThrow(DBAdapter.KEY_COLOR_2)));
                c3.setText(cur.getString(cur.getColumnIndexOrThrow(DBAdapter.KEY_COLOR_3)));

                }
                catch(Exception e){
                    e.printStackTrace();
                }

            }
        dba.close();
    }


    protected void onDestroy() {
        super.onDestroy();
        if (dba != null) {
            dba.close();
        }
        if (myDB != null) {
            myDB.close();
        }
    }


}
Logcat文件

   02-22 10:49:29.717: W/System.err(20723): java.lang.IllegalArgumentException: column 'website_1' does not exist
02-22 10:49:29.717: W/System.err(20723):    at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:302)
02-22 10:49:29.717: W/System.err(20723):    at com.example.exa_sales_new.Newform_Screen2_Likewebsite_edit.populateFields(Newform_Screen2_Likewebsite_edit.java:135)
02-22 10:49:29.717: W/System.err(20723):    at com.example.exa_sales_new.Newform_Screen2_Likewebsite_edit.onCreate(Newform_Screen2_Likewebsite_edit.java:48)
02-22 10:49:29.717: W/System.err(20723):    at android.app.Activity.performCreate(Activity.java:5008)
02-22 10:49:29.717: W/System.err(20723):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-22 10:49:29.717: W/System.err(20723):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
02-22 10:49:29.717: W/System.err(20723):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-22 10:49:29.717: W/System.err(20723):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-22 10:49:29.717: W/System.err(20723):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-22 10:49:29.717: W/System.err(20723):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 10:49:29.717: W/System.err(20723):    at android.os.Looper.loop(Looper.java:137)
02-22 10:49:29.717: W/System.err(20723):    at android.app.ActivityThread.main(ActivityThread.java:4745)
02-22 10:49:29.717: W/System.err(20723):    at java.lang.reflect.Method.invokeNative(Native Method)
02-22 10:49:29.717: W/System.err(20723):    at java.lang.reflect.Method.invoke(Method.java:511)
02-22 10:49:29.717: W/System.err(20723):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-22 10:49:29.717: W/System.err(20723):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-22 10:49:29.717: W/System.err(20723):    at dalvik.system.NativeStart.main(Native Method)
  • 我想你在呼叫
    populateFields()
    以访问列,但 表尚未创建,这就是为什么您会得到列 “网站1”不存在“例外

  • 我强烈建议您查看一下如何管理数据库的类。它将在内部处理何时创建数据库的模式或何时升级数据库

下面是一个示例,它将让您了解如何升级数据库或执行ALTERQUERY

public class OpenHelper extends SQLiteOpenHelper {

    private final static int DB_VERSION = 2;

    public TracksDB(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        final String CREATE_TBL =
            "create table " + ANIMALS_TABLE +
            " (_id integer primary key autoincrement, " + 
            "animal_name text not null, " +
            "biography text not null);";
             db.execSQL(CREATE_TBL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (oldVersion < 2) {
            final String ALTER_TBL = 
                "ALTER TABLE " + ANIMALS_TABLE +
                " ADD COLUMN biography text not null;";
            db.execSQL(ALTER_TBL);
        }
    }
} 
public类OpenHelper扩展了SQLiteOpenHelper{
私有最终静态int DB_版本=2;
公共轨道数据库(上下文){
super(上下文,数据库名称,空,数据库版本);
}
@凌驾
public void onCreate(SQLiteDatabase db){
最终字符串创建\u TBL=
“创建表”+动物表+
(_idinteger主键自动递增,“+
动物名称文本不为空+
“传记文本不为空);”;
db.execSQL(创建_TBL);
}
@凌驾
public void onUpgrade(SQLiteDatabase db,int-oldVersion,int-newVersion){
如果(旧版本<2){
最终字符串更改\u TBL=
“改变表”+动物表+
“添加列传记文本不为空;”;
db.execSQL(ALTER_TBL);
}
}
} 
有关升级数据库的详细信息,请参阅

注意:

  • onCreate()
    仅在您第一次安装应用程序时调用,
    onUpgrade()
    仅在应用程序已安装且您刚刚更新时调用

希望这能帮助您解决问题。

尝试卸载并重新安装该应用。@sha404也这么做了。。但仍面临问题请将日志放在日志上。。here@altaf当前位置发布请看一看