samedi 24 janvier 2015

Code(1) not found a column during compilation


package com.example.hello.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class sqlitedatahelper extends SQLiteOpenHelper {
private static final String LOGTAG = "SMILE";
private static final int DATABASE_VERSION = 1;

// Database Name
static final String DATABASE_NAME = "storesxis.db";

// Contacts table name
static final String TABLE_storesxis = "storesxis";


static final String COLUMN_ID="id";
static final String COLUMN_startx="startx";
static final String COLUMN_starty="starty";
static final String COLUMN_stopx="stopx";
static final String COLUMN_stopy="stopy";
// private static final String COLUMN_Timetaken = "totaltime";




static final String CREATE_TABLE = "CREATE TABLE " + TABLE_storesxis + "("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," + COLUMN_startx + " TEXT,"
+ COLUMN_starty + " TEXT,"
+ COLUMN_stopx + " TEXT," + COLUMN_stopy + " TEXT" + ")";



public sqlitedatahelper(Context context) {

super(context, DATABASE_NAME , null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
Log.i(LOGTAG, "hello table is created");
// TODO Auto-generated method stub

}

@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
db.execSQL("DROP TABLE IF EXISTS" + TABLE_storesxis );
onCreate(db);
// TODO Auto-generated method stub

}

}


Datasource.java



package com.example.hello.db;




import java.util.ArrayList;
import java.util.List;

//import com.example.h.MainActivity;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.example.hello.Funtionstore;


public class Datasource {
private static final String LOGTAG = "SMILE";

SQLiteOpenHelper dbhelper;
SQLiteDatabase database;
private static final String[] allcolumns ={
sqlitedatahelper.COLUMN_ID,
sqlitedatahelper.COLUMN_startx,
sqlitedatahelper.COLUMN_starty,
sqlitedatahelper.COLUMN_stopx,
sqlitedatahelper.COLUMN_stopy};
public Datasource(Context context){
dbhelper = new sqlitedatahelper(context);
}

public void open()
{
Log.i(LOGTAG, "hello open");
database = dbhelper.getWritableDatabase();
}
public void close()
{
Log.i(LOGTAG,"HELKLO");
dbhelper.close();

}


public Funtionstore create(Funtionstore storep)
{
//SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(sqlitedatahelper.COLUMN_ID, storep.getID());
values.put(sqlitedatahelper.COLUMN_startx, storep.getStartx());
values.put(sqlitedatahelper.COLUMN_starty, storep.getStartx());
values.put(sqlitedatahelper.COLUMN_stopx, storep.getStopx());
values.put(sqlitedatahelper.COLUMN_stopy, storep.getStopy());
long insertid = database.insert( sqlitedatahelper.TABLE_storesxis, null, values);
storep.setID(insertid);
return storep;

}
public List<Funtionstore> findAll(){
List<Funtionstore> storeps = new ArrayList<Funtionstore>();
Cursor cursor = database.query(sqlitedatahelper.TABLE_storesxis, allcolumns,
null, null, null, null, null);
Log.i(LOGTAG, "returned" + cursor.getCount() + "row");
if (cursor.getCount()>0) {
while (cursor.moveToNext()) {
Funtionstore storep = new Funtionstore();
storep.setID(cursor.getLong(cursor.getColumnIndex(sqlitedatahelper.COLUMN_ID)));
storep.setStartx(cursor.getFloat(cursor.getColumnIndex(sqlitedatahelper.COLUMN_startx)));
storep.setStarty(cursor.getFloat(cursor.getColumnIndex(sqlitedatahelper.COLUMN_starty)));
storep.setStopx(cursor.getFloat(cursor.getColumnIndex(sqlitedatahelper.COLUMN_stopx)));
storep.setStopy(cursor.getFloat(cursor.getColumnIndex(sqlitedatahelper.COLUMN_stopy)));
//storep.add(storep);
}

}
return storeps;
}
}


I have a problem with code on executing project system doesnt found column stopx this is the helper class dnt know whats really wrong with it .........Initially when i create table witth no values table was sucessfully created but when i try to pass values it causes problem ..... This is my full code consist of 4 classes i try to store axis at starting n ending points of writing on canvas but now at initial stage i am working with static data but have problems try to follow tutorials inorder to store data but have this issue... Any one if kindly check this code n let me know about the problem and solution i shall be very thankfull to him ....


Aucun commentaire:

Enregistrer un commentaire