java.lang.NullPointerExceptionが String idd = c.getString(c.getColumnIndex(UserContract.Users._ID));
にでます。
どうぞ宜しくお願い致します。
java
1 2 3public class MainActivity extends AppCompatActivity { 4 5 SimpleAdapter mAdapter = null; 6 7 List<Map<String, String>> mList = null; 8 9 ListView list=null; 10 11 SQLiteDatabase db=null; 12 13 14 15 16 @Override 17 protected void onCreate(Bundle savedInstanceState) { 18 super.onCreate(savedInstanceState); 19 setContentView(R.layout.activity_main); 20 21 22 MemoDBHelper memoDBHelper=new MemoDBHelper(this); 23 db=memoDBHelper.getWritableDatabase(); 24 25 26 27 db.execSQL(CREATE_TABLE); 28 29 30 31 ListView list = (ListView) findViewById(R.id.listView); 32 mList = new ArrayList<Map<String, String>>(); 33 34 35 mAdapter = new SimpleAdapter(this, 36 mList, 37 38 android.R.layout.simple_list_item_2, 39 new String[]{"title", "content", "data"}, //Map側のkey 40 new int[]{android.R.id.text1, android.R.id.text2, R.id.eTxtData} //layout側のTextViewId 表示させたいMapのkey順に合わせる 41 ); 42 43 list.setAdapter(mAdapter); 44 45 list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 46 47 @Override 48 public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { 49 50 51 Intent intent = new Intent(MainActivity.this, EditActivity.class); 52 53 intent.putExtra("INSERT",""); 54 55 intent.putExtra("TITLE", mList.get(pos).get("title")); 56 intent.putExtra("CONTENT", mList.get(pos).get("content")); 57 intent.putExtra("DATA", mList.get(pos).get("data")); 58 59 60 String title1= mList.get(pos).get("title"); 61 String content1=mList.get(pos).get("content"); 62 String data1=mList.get(pos).get("data"); 63 64 65 66 String sql="SELECT * FROM UserContract.Users.TABLE_NAME\n" + 67 " WHERE UserContract.Users.COL_TITLE== title1\n" + 68 " AND UserContract.Users.COL_CONTENT == content1\")\n" + 69 " AND UserContract.Users.COL_DATA==data1\")"; 70 71////////この下の列にエラーが出ます。 72 Cursor c =db.rawQuery(sql,null); 73 74 75 if(c.moveToFirst()) { 76 String idd = c.getString(c.getColumnIndex(UserContract.Users._ID)); 77 78 79 System.out.println(idd); 80 81 c.close(); 82 83 intent.putExtra("ID", idd); 84 } 85 86 startActivity(intent); 87 } 88 }); 89 90 // ListView をコンテキストメニューに登録 91 registerForContextMenu(list); 92 } 93 94 95 96 97 98 @Override 99 protected void onResume() { 100 super.onResume(); 101 102 //open helper 103 //open db memoDBHelperに変更 104 MemoDBHelper memoDBHelper=new MemoDBHelper(this); 105 SQLiteDatabase db=memoDBHelper.getWritableDatabase(); 106 107 mList.clear(); 108 109 String id=null; 110 String title = null; 111 String content = null; 112 String data=null; 113 114 //ここからコピペ 115 116 //これはselect 117 Cursor c; 118 c=db.query( 119 UserContract.Users.TABLE_NAME, 120 null,//fields 121 null,//where 122 null,//where arg ここでは、多分何もせずに、全件取得して、リストに入れる 123 null,//groupBy 124 null,//having 125 null,//order by 126 null 127 ); 128 129 Log.v("DB_TEST","Count:"+c.getCount()); 130 131 Map<String, String> map = new HashMap<String, String>(); 132 while(c.moveToNext()){ 133 134 // id=c.getString(c.getColumnIndex(UserContract.Users._ID)); 135 title=c.getString(c.getColumnIndex(UserContract.Users.COL_TITLE)); 136 content=c.getString(c.getColumnIndex(UserContract.Users.COL_CONTENT)); 137 data=c.getString(c.getColumnIndex(UserContract.Users.COL_DATA)); 138 Log.v("DB_TEST"," id: "+id+ "title: "+title+ "content: "+content+" data: "+data); 139 140 141 map.put("title", title); 142 map.put("content", content); 143 map.put("data",data); 144 mList.add(map); 145 146 147 } 148 149 c.close(); 150 151 db.close(); 152 153 154 // ListView のデータ変更を表示に反映 155 mAdapter.notifyDataSetChanged(); 156 } 157 158 159} 160 161
java
1E/AndroidRuntime: FATAL EXCEPTION: main 2 android.database.sqlite.SQLiteException: near ".": syntax error (code 1): , while compiling: SELECT * FROM UserContract.Users.TABLE_NAME 3 WHERE UserContract.Users.COL_TITLE== title1 4 AND UserContract.Users.COL_CONTENT == content1") 5 AND UserContract.Users.COL_DATA==data1") 6 at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 7 at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893) 8 at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504) 9 at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 10 at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) 11 at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37) 12 at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 13 at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1322) 14 at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1261) 15 at com.example.android.sample.memo.MainActivity$1.onItemClick(MainActivity.java:148) 16 at android.widget.AdapterView.performItemClick(AdapterView.java:298) 17 at android.widget.AbsListView.performItemClick(AbsListView.java:1086) 18 at android.widget.AbsListView$PerformClick.run(AbsListView.java:2859) 19 at android.widget.AbsListView$1.run(AbsListView.java:3533) 20 at android.os.Handler.handleCallback(Handler.java:615) 21 at android.os.Handler.dispatchMessage(Handler.java:92) 22 at android.os.Looper.loop(Looper.java:213) 23 at android.app.ActivityThread.main(ActivityThread.java:4786) 24 at java.lang.reflect.Method.invokeNative(Native Method) 25 at java.lang.reflect.Method.invoke(Method.java:511) 26 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 27 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 28 at dalvik.system.NativeStart.main(Native Method) 29
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/18 02:35
2017/04/18 02:37
2017/04/18 02:46
2017/04/18 02:49
2017/04/18 02:54
2017/04/18 02:57
2017/04/18 03:43
2017/04/18 03:49
2017/04/18 03:57
2017/04/18 04:03
2017/04/18 04:19
2017/04/18 04:26
2017/04/18 05:25
2017/04/18 05:37
2017/04/18 05:43
2017/04/18 05:45
2017/04/18 05:45
2017/04/18 05:54
2017/04/18 06:00 編集
2017/04/18 06:35
2017/04/18 06:40
2017/04/18 06:42
2017/04/18 06:48 編集
2017/04/18 06:51
2017/04/18 06:55 編集
2017/04/18 06:56
2017/04/18 07:01
2017/04/18 07:03
2017/04/18 07:10
2017/04/18 07:14
2017/04/18 07:18
2017/04/18 07:20
2017/04/18 07:22
2017/04/18 07:25
2017/04/18 07:27
2017/04/18 07:31
2017/04/18 07:34
2017/04/18 07:35
2017/04/18 07:37
2017/04/18 07:40
2017/04/18 07:46
2017/04/18 08:57 編集
2017/04/18 09:06
2017/04/18 09:24
2017/04/18 09:40
2017/04/18 10:56 編集
2017/04/18 11:00
2017/04/18 11:01
2017/04/18 11:24
2017/04/18 11:29
2017/04/18 11:31
2017/04/18 11:49
2017/04/18 11:53
2017/04/18 11:59
2017/04/18 11:59
2017/04/18 12:01