当我尝试执行此应用时,我收到此错误。我不知道为什么我收到这个错误。在创建表时,是否将其留空或尝试用值填充它以启动,因为我的应用程序使用EasyModbusJava库并且需要一个从属ID来连接我没有通过,我不希望它能够连接当前。如果这只是使用表创建的问题,我需要做出哪些更改?
08-21 13:31:48.342 8821-8821 /? E / Zygote:v2 08-21 13:31:48.344 8821-8821 /? E / Zygote:accessInfo:0 08-21 13:31:49.407 8821-8821 / com.wavefloatrooms.wavefloatrooms E / SQLiteLog:(1)near" Rooms":语法错误 08-21 13:31:49.418 8821-8821 / com.wavefloatrooms.wavefloatrooms E / AndroidRuntime:FATAL EXCEPTION:main 过程:com.wavefloatrooms.wavefloatrooms,PID:8821 java.lang.RuntimeException:无法启动活动ComponentInfo {com.wavefloatrooms.wavefloatrooms / com.wavefloatrooms.wavefloatrooms.OverviewListActivity}:android.database.sqlite.SQLiteException:near" Rooms":语法错误(代码1 ):,同时编译:create table Float Rooms(_id整数主键自动增量,从属ID,房间名称) ################################################## ############### 错误代码:1(SQLITE_ERROR) 引起:SQL(查询)错误或缺少数据库。 (附近"房间&#34 ;:语法错误(代码1):,编译时:创建表格浮动房间(_id整数主键自动增量,从属ID,房间名称)) ################################################## ############### 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008) 在android.app.ActivityThread.-wrap14(ActivityThread.java) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1650) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6688) at java.lang.reflect.Method.invoke(Native Method) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1468) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 引起:android.database.sqlite.SQLiteException:near" Rooms&#34 ;:语法错误(代码1):,同时编译:create table Float Rooms(_id整数主键自动增量,slave ID,房间名称) ################################################## ############### 错误代码:1(SQLITE_ERROR) 引起:SQL(查询)错误或缺少数据库。 (附近"房间&#34 ;:语法错误(代码1):,编译时:创建表格浮动房间(_id整数主键自动增量,从属ID,房间名称)) ################################################## ############### 在android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法) 在android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1005) 在android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:570) 在android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:59) 在android.database.sqlite.SQLiteStatement。(SQLiteStatement.java:31) 在android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1976) 在android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1907) 在com.wavefloatrooms.wavefloatrooms.database.FloatBaseHelper.onCreate(FloatBaseHelper.java:23) 在android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251) 在android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163) 在com.wavefloatrooms.wavefloatrooms.FloatLab。(FloatLab.java:35) 在com.wavefloatrooms.wavefloatrooms.FloatLab.get(FloatLab.java:28) 在com.wavefloatrooms.wavefloatrooms.OverviewListFragment.updateUI(OverviewListFragment.java:45) at com.wavefloatrooms.wavefloatrooms.OverviewListFragment.onCreateView(OverviewListFragment.java:34) 在android.support.v4.app.Fragment.performCreateView(Fragment.java:2192) 在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299) 在android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528) 在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595) 在android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758) 在android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363) 在android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149) 在android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103) 08-21 13:31:49.418 8821-8821 / com.wavefloatrooms.wavefloatrooms E / AndroidRuntime:at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013) 在android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388) 在android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607) 在android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178) 在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1256) 在android.app.Activity.performStart(Activity.java:6929) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910) ... 9更多
public class FloatBaseHelper extends SQLiteOpenHelper {
private static final int VERSION = 1;
private static final String DATABASE_NAME = "floatBase.db";
public FloatBaseHelper(Context context){
super(context, DATABASE_NAME, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("create table " + RoomTable.NAME + "(" +
"_id integer primary key autoincrement, " + RoomTable.Cols.SLAVE_ID +
", " + RoomTable.Cols.ROOM_NAME + ")");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
public class FloatRoomCursorWrapper extends CursorWrapper {
public FloatRoomCursorWrapper(Cursor cursor) {
super(cursor);
}
public FloatRoom getFloatRoom(){
int slaveID = getInt(getColumnIndex(RoomTable.Cols.SLAVE_ID));
String roomName = getString(getColumnIndex(RoomTable.Cols.ROOM_NAME));
FloatRoom room = new FloatRoom(slaveID);
room.setRoomName(roomName);
return room;
}
}
public class OverviewListFragment extends Fragment {
private RecyclerView mRoomRecyclerView;
private RoomAdapter mAdapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_overview_list, container, false);
mRoomRecyclerView = (RecyclerView) view.findViewById(R.id.floatroom_recylerview);
mRoomRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
updateUI();
return view;
}
@Override
public void onResume() {
super.onResume();
updateUI();
}
private void updateUI() {
FloatLab floatlab = FloatLab.get(getActivity());
List<FloatRoom> rooms = floatlab.getFloatRooms();
if(mAdapter == null){
mAdapter = new RoomAdapter(rooms);
mRoomRecyclerView.setAdapter(mAdapter);
}else{
mAdapter.setFloatRooms(rooms);
mAdapter.notifyDataSetChanged();
}
}
private class RoomHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView mTimeRemainingTextView;
private TextView mRoomNameTextView;
private ImageButton mControlPanelBtn;
private ProgressBar mTimeProgressBar;
private FloatRoom mFloatRoom;
public RoomHolder(LayoutInflater inflater, ViewGroup parent) {
super(inflater.inflate(R.layout.list_item_floatroom, parent, false));
initializeVariables();
}
private void initializeVariables() {
mTimeRemainingTextView = (TextView) itemView.findViewById(R.id.time_remaining_textView);
mRoomNameTextView = (TextView) itemView.findViewById(R.id.room_name_textView);
mControlPanelBtn = (ImageButton) itemView.findViewById(R.id.control_panel_btn);
mTimeProgressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
}
public void bind(FloatRoom room) {
mFloatRoom = room;
mRoomNameTextView.setText(mFloatRoom.getRoomName());
mTimeRemainingTextView.setText("Time Remaining: " + mFloatRoom.getSessionTimeRemaining() + " minutes");
mControlPanelBtn.setOnClickListener(this);
}
@Override
public void onClick(View view) {
startControlPanel();
}
private void startControlPanel() {
Intent intent;
switch (mFloatRoom.getRoomType()){
case 0:
intent = new StandardRoomActivity().newIntent(getActivity(), mFloatRoom.getSlaveID());
startActivity(intent);
break;
case 1:
intent = new EliteRoomActivity().newIntent(getActivity(), mFloatRoom.getSlaveID());
startActivity(intent);
break;
default:
Toast.makeText(getActivity(), "ERROR Starting Auto mode!", Toast.LENGTH_LONG);
}
}
}
private class RoomAdapter extends RecyclerView.Adapter<RoomHolder> {
private List<FloatRoom> mRooms;
public RoomAdapter(List<FloatRoom> rooms){
mRooms = rooms;
}
@Override
public RoomHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
return new RoomHolder(layoutInflater, parent);
}
@Override
public void onBindViewHolder(RoomHolder holder, int position) {
FloatRoom room = mRooms.get(position);
holder.bind(room);
}
@Override
public int getItemCount() {
return mRooms.size();
}
public void setFloatRooms(List<FloatRoom> rooms){
mRooms = rooms;
}
}
}
答案 0 :(得分:1)
RoomTable.NAME
似乎是Float Rooms
。表名中不能有空格。将其重命名为其中没有空格的其他内容。