Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.activeandroid.TableInfo.getIdName()' on a null object reference
が出ます。
Tableを設定しているクラスは
lang
1import com.activeandroid.Model; 2import com.activeandroid.annotation.Column; 3import com.activeandroid.annotation.Table; 4 5@Table(name = "memo_table") 6public class MemoDB extends Model{ 7 @Column (name = "title") 8 public String title; 9 10 @Column (name = "memo") 11 public String memo; 12 13 @Column (name = "date") 14 public String date; 15 16 @Override 17 public String toString(){ 18 return title; 19 } 20}
これを使っているクラスは、
lang
1public class MemoCreateActivity extends AppCompatActivity { 2 3 MemoDB mMemoDB = new MemoDB(); 4 EditText mTitle; 5 EditText mMemo; 6 @Override 7 protected void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.activity_memo_create); 10 11 mTitle = (EditText)findViewById(R.id.create_title); 12 mMemo = (EditText)findViewById(R.id.create_memo); 13 } 14 @Override 15 public boolean onCreateOptionsMenu(Menu menu) { 16 getMenuInflater().inflate(R.menu.menu_memo_create, menu); 17 return true; 18 } 19 @Override 20 public boolean onOptionsItemSelected(MenuItem item) { 21 // Handle action bar item clicks here. The action bar will 22 // automatically handle clicks on the Home/Up button, so long 23 // as you specify a parent activity in AndroidManifest.xml. 24 int id = item.getItemId(); 25 26 //noinspection SimplifiableIfStatement 27 if (id == R.id.create_save) { 28 saveMemo(); 29 finish(); 30 return true; 31 } 32 return super.onOptionsItemSelected(item); 33 } 34 void saveMemo(){ 35 mMemoDB.title = mTitle.getText().toString(); 36 mMemoDB.memo = mMemo.getText().toString(); 37 Date date = new Date(); 38 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.JAPANESE); 39 mMemoDB.date = sdf.format(date); 40 mMemoDB.save(); 41 } 42} 43
です。どこがおかしいのでしょうか。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。