Hello. I have two activities:

public class MainActivity extends AppCompatActivity implements View.OnClickListener { EditText ename,eroll_no,emarks/*, gr*/; Button add,view,viewall,delete,modify, groupe, addcat; Spinner gr; SQLiteDatabase db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ename = (EditText)findViewById(R.id.name); eroll_no = (EditText)findViewById(R.id.roll_no); emarks = (EditText)findViewById(R.id.marks); //gr = (EditText)findViewById(R.id.gr); gr = (Spinner) findViewById(R.id.spinner);// сам спиннер из вида add = (Button)findViewById(R.id.addbtn); db = openOrCreateDatabase("Student_manage", Context.MODE_PRIVATE, null); db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno INTEGER UNIQUE,name VARCHAR,marks INTEGER,groupe VARCHAR);"); //вот я пытаюсь сделать: Cursor cursor = db.rawQuery("SELECT * FROM groups", null); SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor, new String[] {"name"}, new int[] {android.R.id.text1}); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); gr.setAdapter(adapter); add.setOnClickListener(new View.OnClickListener() { //тут уже другой код } } } 

And the second activity:

 public class GroupActivity extends AppCompatActivity { SQLiteDatabase db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_group); db = openOrCreateDatabase("Student_manage", Context.MODE_PRIVATE, null); db.execSQL("CREATE TABLE IF NOT EXISTS groups(_id INTEGER PRIMARY KEY AUTOINCREMENT,rollno INTEGER UNIQUE,name VARCHAR);"); adds.setOnClickListener(new View.OnClickListener() { //тут уже другой код } } } 

Now the application is not even compiled. What am I doing wrong?

Logcat writes:

 нет _id 
  • @pavlofff added error description - artem55555p
  • If it is installed and falls with an error on the device, then it still compiles normally. Below in the studio there is a tab logcat, when he writes that an error occurred in the application - look there and copy the spectra here (the block where the words execption appear, caused by and at, and not the whole log), also in which line the error (in the logcat link it is highlighted in blue and clickable) - pavlofff
  • @pavlofff added error description - artem55555p
  • one
    @pavlofff the reason was a typo and there was no _id primary key - artem55555p
  • @pavlofff can you suggest another question? I posted it below - artem55555p

1 answer 1

Found a solution. All my carelessness, in another table I looked for, corrected:

 Cursor cursor = db.query("groups", new String[]{"_id","name"}, null, null, null, null, null);