Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.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
Android 语法错误时引发SQLiteException_Android_Sqlite - Fatal编程技术网

Android 语法错误时引发SQLiteException

Android 语法错误时引发SQLiteException,android,sqlite,Android,Sqlite,这是一个获取个人信息值并存储到SQLite数据库中的代码 public class AddAPersonActivity extends Activity implements View.OnClickListener, AdapterView.OnItemSelectedListener, RadioGroup.OnCheckedChangeListener { private Button btnAdd; private EditText etName; privat

这是一个获取个人信息值并存储到SQLite数据库中的代码

public class AddAPersonActivity extends Activity implements View.OnClickListener, AdapterView.OnItemSelectedListener, RadioGroup.OnCheckedChangeListener {
    private Button btnAdd;
    private EditText etName;
    private TextView tvDob;
    private Spinner spNationality;
    private RadioButton rbMale, rbFemale;
    private Calendar birthday;
    private NameValidator nameValidator;
    private RadioGroup rgGenderGroup;
    private String gender = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_a_person);

        btnAdd = (Button) findViewById(R.id.btnAdd);
        etName = (EditText) findViewById(R.id.etName);
        tvDob = (TextView) findViewById(R.id.tvDob);
        spNationality = (Spinner) findViewById(R.id.spNationality);
        rbMale = (RadioButton) findViewById(R.id.rbMale);
        rbFemale = (RadioButton) findViewById(R.id.rbFemale);
        rgGenderGroup = (RadioGroup) findViewById(R.id.rgGenderGroup);
        nameValidator = new NameValidator();

        birthday = Calendar.getInstance();
        Locale[] locales = Locale.getAvailableLocales();
        ArrayList<String> countries = new ArrayList<>();
        for(Locale locale: locales) {
            String country = locale.getDisplayCountry();
            if(country.trim().length() > 0 && !countries.contains(country)) {
                countries.add(country);
            }
        }

        Collections.sort(countries);
        for(String country: countries) {
            System.out.println(country);
        }

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, countries);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        spNationality.setAdapter(dataAdapter);
        spNationality.setSelection(0);

        spNationality.setOnItemSelectedListener(this);
        tvDob.setOnClickListener(this);
        rgGenderGroup.setOnCheckedChangeListener(this);
        btnAdd.setOnClickListener(this);
    }

    void updateLabel() {
        String format = "MM/dd/yy";
        SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.US);
        tvDob.setText(dateFormat.format(birthday.getTime()));
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()) {
            case R.id.btnAdd:
                String name = etName.getText().toString();
                Calendar today = Calendar.getInstance();
                int age = today.get(Calendar.YEAR) - today.get(Calendar.YEAR);
                if(today.get(Calendar.MONTH) < birthday.get(Calendar.MONTH)) {
                    age--;
                } else if(today.get(Calendar.MONTH) == birthday.get(Calendar.MONTH) && today.get(Calendar.DAY_OF_MONTH) < birthday.get(Calendar.DAY_OF_MONTH)) {
                    age--;
                }

                String nationality = spNationality.getSelectedItem().toString();

                DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                java.util.Date currentDate = new java.util.Date();
                Date currentTime = new Date(currentDate.getTime());
                String created_at = dateFormat.format(currentTime);

                if(!(name.length() > 0)) {
                    Toast.makeText(this, "Please don't leave the name empty.", Toast.LENGTH_LONG).show();
                } else if(!(tvDob.getText().toString().length() > 0)) {
                    Toast.makeText(this, "Please set a valid birthday.", Toast.LENGTH_LONG).show();
                } else if(birthday.getTime().compareTo(new java.util.Date()) > 0) {
                    Toast.makeText(this, "Wrong birthday. Please set the valid birthday again.", Toast.LENGTH_LONG).show();
                } else if(!(rbMale.isChecked() || rbFemale.isChecked())) {
                    Toast.makeText(this, "Please choose your gender.", Toast.LENGTH_LONG).show();
                } else if(!nameValidator.validate(etName.getText().toString())) {
                    Toast.makeText(this, "Wrong name. Please enter a proper name.", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(this, "New person is added to the database!", Toast.LENGTH_LONG).show();
                    SQLiteHandler mDBHelper = new SQLiteHandler(this);

                    // Get the data repository in write mode
                    SQLiteDatabase db = mDBHelper.getWritableDatabase();

                    // Create a new map of values, where column names are the keys
                    ContentValues values = new ContentValues();
                    values.put(PersonalInfoEntry.COLUMN_NAME, name);
                    values.put(PersonalInfoEntry.COLUMN_AGE, age);
                    values.put(PersonalInfoEntry.COLUMN_NATIONALITY, nationality);
                    values.put(PersonalInfoEntry.COLUMN_GENDER, gender);
                    values.put(PersonalInfoEntry.COLUMN_CREATED_AT, created_at);

                    db.insert(PersonalInfoEntry.TABLE_NAME, null, values);
                    db.close();
                }
                break;

            case R.id.tvDob:
                DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        birthday.set(Calendar.YEAR, year);
                        birthday.set(Calendar.MONTH, monthOfYear);
                        birthday.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                        updateLabel();
                    }
                };
                new DatePickerDialog(this, date, birthday.get(Calendar.YEAR), birthday.get(Calendar.MONTH), birthday.get(Calendar.DAY_OF_MONTH)).show();
                break;
        }
    }

    void addPersonToGroupTable() {

    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch(checkedId) {
            case(R.id.rbMale):
                gender = "M";
                break;
            case(R.id.rbFemale):
                gender = "F";
                break;
        }
    }
}
现在我对数据库世界还很陌生。这真的是查询的问题吗?还是代码中有我没有注意到的错误


非常感谢您的帮助,如果您需要更多信息,请告诉我,我会尽快更新

不能在表创建代码中使用
,因为组是保留关键字


仅供参考:

您不能在表创建代码中使用
Group
,因为Group是保留关键字


仅供参考:

您不能在表创建代码中使用
Group
,因为Group是保留关键字


仅供参考:

您不能在表创建代码中使用
Group
,因为Group是保留关键字


供参考:

将表名更改为带有前缀或后缀的
user\u group
<代码>组是在SQLite中预定义的关键字,不能在其他情况下使用

使用前缀或后缀将表名更改为
user\u group
<代码>组是在SQLite中预定义的关键字,不能在其他情况下使用

使用前缀或后缀将表名更改为
user\u group
<代码>组是在SQLite中预定义的关键字,不能在其他情况下使用

使用前缀或后缀将表名更改为
user\u group
<代码>组是在SQLite中预定义的关键字,不能在其他情况下使用

我建议放置可疑行,因为很难通过一整串代码添加你的创建表组queryI建议放置可疑行,因为很难通过一整串代码添加你的创建表组queryI建议放置可疑行,因为很难通过一大堆代码..添加你的创建表组查询我建议把可疑的行放进去,因为很难通过一大堆代码..添加你的创建表组查询你是对的。现在例外情况消失了。非常感谢你的帮助!你是对的。现在例外情况消失了。非常感谢你的帮助!你是对的。现在例外情况消失了。非常感谢你的帮助!你是对的。现在例外情况消失了。非常感谢你的帮助!
android.database.sqlite.SQLiteException: near "Group": syntax error (code 1): , while compiling: CREATE TABLE Group ( Name TEXT NOT NULL, Age INT, Nationality TEXT NOT NULL, Gender CHAR(1) NOT NULL, Created_At TEXT);