FATAL EXCEPTION: main
Process: com.application.sweetiean.stlmaintenance, PID: 7148
android.database.sqlite.SQLiteException: near "Base": syntax error (code 1): , while compiling: CREATE TABLE Maintenance Base Data Table (_id INTEGER PRIMARY KEY AUTOINCREMENT, Date TEXT, Sysaid Id TEXT, Task Type TEXT, Customer TEXT, Site Id TEXT, Address TEXT, Region TEXT, Phone TEXT, E-Mail TEXT, Location Coordinates TEXT, STL Rep Name TEXT, STL Rep Position TEXT, STL Rep Signature TEXT, Client Rep Name TEXT, Client Rep Position TEXT, Client Rep Signature TEXT);
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1806)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1737)
at com.application.sweetiean.stlmaintenance.MaintenanceAppDB$DbHelper.onCreate(MaintenanceAppDB.java:280)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
at com.application.sweetiean.stlmaintenance.MaintenanceAppDB.openForRead(MaintenanceAppDB.java:423)
at com.application.sweetiean.stlservicing.Serv_OverviewFragment.init(Serv_OverviewFragment.java:66)
at com.application.sweetiean.stlservicing.Serv_OverviewFragment.onCreateView(Serv_OverviewFragment.java:57)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:490)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1105)
at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1473)
at android.view.View.measure(View.java:17327)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:582)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:649)
at android.view.View.measure(View.java:17327)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
at android.view.View.measure(View.java:17327)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:17327)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17327)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.
Above is the error log I get when my application tries to create the data base. Below is the database class:
package com.application.sweetiean.stlmaintenance;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by sweetiean on 11/21/2015.
*/
public class MaintenanceAppDB {
private DbHelper maintenanceAppHelper;
private final Context maintenanceAppContext;
private SQLiteDatabase maintenanceAppDatabase;
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "maintenance_app_db";
private static final String TABLE_MAIN_INFO = "Maintenance Base Data Table";
private static final String TABLE_MAIN_TASK = "Task Table";
private static final String TABLE_MAIN_IMAGES = "Images";
public static final String TABLE_SERV_INFO = "Service Base Data Table";
private static final String TABLE_SERV_SERVICING = "Servicing Table";
private static final String TABLE_SERV_REPLACEMENT = "Replacement Table";
//COMMON FIELDS
public static final String ROW_ID = "_id";
public static final String SYSAID_ID = "Sysaid Id";
public static final String TASK_TYPE = "Task Type";
public static final String CUSTOMER = "Customer";
public static final String SITE_ID = "Site Id";
public static final String ADDRESS = "Address";
public static final String REGION = "Region";
public static final String LOCATION = "Location Coordinates";
public static final String STL_REP_NAME = "STL Rep Name";
public static final String STL_REP_POST = "STL Rep Position";
public static final String STL_REP_SIGN = "STL Rep Signature";
public static final String CLIENT_REP_NAME = "Client Rep Name";
public static final String CLIENT_REP_POST = "Client Rep Position";
public static final String CLIENT_REP_SIGN = "Client Rep Signature";
public static final String REMARKS = "Remarks";
public static final String DATE = "Date";
//MAINTENANCE FIELDS
public static final String PHONE = "Phone";
public static final String EMAIL = "E-Mail";
public static final String INVENTORY = "Inventory";
public static final String GEN_HOURS = "GenSet Run Hours";
public static final String BATTERY_VOLT = "Battery Voltage";
public static final String MAINTENANCE_TYPE = "Maintenance Type";
public static final String QUANTITY = "Quantity";
public long createBaseDataRecord(String sql_date, String sql_sysaid, String sql_taskType, String sql_customer,
String sql_siteId, String sql_address, String sql_region, String sql_phone,
String sql_email, String sql_location, String sql_stlRepName, String sql_stlRepPost,
String sql_stlRepSign, String sql_clientRepName, String sql_clientRepPost,
String sql_clientRepSign) {
ContentValues cv = new ContentValues();
cv.put(DATE, sql_date);
cv.put(SYSAID_ID, sql_sysaid);
cv.put(TASK_TYPE, sql_taskType);
cv.put(CUSTOMER, sql_customer);
cv.put(SITE_ID, sql_siteId);
cv.put(ADDRESS, sql_address);
cv.put(REGION, sql_region);
cv.put(PHONE, sql_phone);
cv.put(EMAIL, sql_email);
cv.put(LOCATION, sql_location);
cv.put(STL_REP_NAME, sql_stlRepName);
cv.put(STL_REP_POST, sql_stlRepPost);
cv.put(STL_REP_SIGN, sql_stlRepSign);
cv.put(CLIENT_REP_NAME, sql_clientRepName);
cv.put(CLIENT_REP_POST, sql_clientRepPost);
cv.put(CLIENT_REP_SIGN, sql_clientRepSign);
return maintenanceAppDatabase.insert(TABLE_MAIN_INFO, null, cv);
}
private class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//MAINTENANCE TABLES
db.execSQL("CREATE TABLE " + TABLE_MAIN_INFO + " ("
+ ROW_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ DATE + " TEXT, "
+ SYSAID_ID + " TEXT, "
+ TASK_TYPE + " TEXT, "
+ CUSTOMER + " TEXT, "
+ SITE_ID + " TEXT, "
+ ADDRESS + " TEXT, "
+ REGION + " TEXT, "
+ PHONE + " TEXT, "
+ EMAIL + " TEXT, "
+ LOCATION + " TEXT, "
+ STL_REP_NAME + " TEXT, "
+ STL_REP_POST + " TEXT, "
+ STL_REP_SIGN + " TEXT, "
+ CLIENT_REP_NAME + " TEXT, "
+ CLIENT_REP_POST + " TEXT, "
+ CLIENT_REP_SIGN + " TEXT);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
public MaintenanceAppDB(Context c){
maintenanceAppContext = c;
}
public SQLiteDatabase openForRead(){
maintenanceAppHelper = new DbHelper(maintenanceAppContext);
maintenanceAppDatabase = maintenanceAppHelper.getReadableDatabase();
return maintenanceAppDatabase;
}
public void close(){
maintenanceAppHelper.close();
}
}
And here is the fragment where I try to read from the database into a list view
package com.application.sweetiean.stlservicing;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.application.sweetiean.stlmaintenance.MaintenanceAppDB;
import com.application.sweetiean.stlmaintenance.R;
import java.util.ArrayList;
public class Serv_OverviewFragment extends Fragment {
View view;
ListView overview_display;
// Arraylist for overviews
private ArrayList<ArrayList<String>> overList;
private ArrayList<String> sysid;
private ArrayList<String> engName;
private ArrayList<String> taskType;
private ArrayList<String> date;
private MaintenanceAppDB db1;
private SQLiteDatabase sqldb;
private Serv_OverviewAdapter adapter;
public Serv_OverviewFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_serv__overview, container, false);
init();
return view;
}
public void init(){
overview_display = (ListView) view.findViewById(R.id.displayListView);
db1 = new MaintenanceAppDB(this.getActivity());
sqldb = db1.openForRead();
if (sqldb.isOpen()) {
Cursor cursor = sqldb.query(MaintenanceAppDB.TABLE_SERV_INFO,
new String[]{MaintenanceAppDB.SYSAID_ID, MaintenanceAppDB.TASK_TYPE, MaintenanceAppDB.STL_REP_NAME, MaintenanceAppDB.DATE}, null, null, null, null, null);
overList = new ArrayList<ArrayList<String>>();
sysid = new ArrayList<String>();
date = new ArrayList<String>();
engName = new ArrayList<String>();
taskType = new ArrayList<String>();
if (cursor.moveToFirst()) {
do {
sysid.add(cursor.getString(0));
taskType.add(cursor.getString(1));
engName.add(cursor.getString(2));
date.add(cursor.getString(3));
} while (cursor.moveToNext());
overList.add(sysid);
overList.add(taskType);
overList.add(engName);
overList.add(date);
}
cursor.close();
}
if (overList.size() != 0) {
adapter = new Serv_OverviewAdapter(this.getActivity(), overList);
overview_display.setAdapter(adapter);
}
//listview context menu
registerForContextMenu(overview_display);//takes listview as argument. can take any view tho
}
}
So I have tried replacing the spaces in the table names with underscores, I have made them all lower case but the app still crashes at onCreate.
Aucun commentaire:
Enregistrer un commentaire