-3

When executing the query below, I get a "Stopped Unexpectedly" error.

I am trying to pull only records that contain "movie", in my "KEY_TYPE" column from my android Sql table.

This is what I have right now:

/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.media_list);
    setTitle(R.string.movie_list);

    mDb.query("records", new String[] {MediaDbAdapter.KEY_TYPE}, "KEY_TYPE LIKE '%movie%'", null, null, null, null);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Warren
  • 29
  • 3
  • 3
    Please provide a descriptive title. – aioobe Aug 23 '11 at 20:37
  • Please post more code, the stacktrace and edit the title. Thanks. –  Aug 23 '11 at 20:38
  • 1
    This has been asked and answered: http://stackoverflow.com/questions/5179563/sqlite-like-problem-in-android/5179749#5179749 – Eugene S Aug 23 '11 at 20:41
  • alextsc: /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.media_list); setTitle(R.string.movie_list); mDb.query("records", new String[] {MediaDbAdapter.KEY_TYPE}, "KEY_TYPE LIKE '%movie%'", null, null, null, null); I'm working on the "mdb.query" part. – Warren Aug 23 '11 at 21:07
  • @Warren: I edited your question to include the code you posted in your comment. You still haven't shown the logcat / stack trace to explain what error you are getting though - "Stopped unexpectedly" will be caused by any number of unhandled exceptions. – Squonk Aug 23 '11 at 21:22
  • @MisterSquonk: here is the error roport from log cat when i run the app. – Warren Aug 23 '11 at 21:30
  • @MisterSquonk: 08-23 16:28:46.665: ERROR/AndroidRuntime(1660): Caused by: java.lang.NullPointerException – Warren Aug 23 '11 at 21:33
  • @MisterSquonk: 08-23 16:28:46.665: ERROR/AndroidRuntime(1660): at com.android.wwarren07.mediapro.Movie.onCreate(Movie.java:32) – Warren Aug 23 '11 at 21:34
  • @Warren: Assuming line 32 of `Movie.java` is where you are getting the `NullPointerException`, are you absolutely sure that `mDb` is valid? In other words, are you sure it isn't `null`? BTW, I've voted to reopen this question as the other one deals with a `SQLiteException` and not an NPE. – Squonk Aug 23 '11 at 21:47
  • Give line 32 of Movie.java. Basically a null pointer exception occur when you do A.B or A.B() and A is null. More generally, in a statement like A.B.C.D.E, something at the left of a dot is null. – Snicolas Aug 23 '11 at 22:31
  • @Warren: Just to correct my last comment above - I meant "Assuming line 32 of `Movie.java` is the line with `mDb.query(...)`...". If it's causing the NPE then check `mDb` has been declared and instantiated correctly befor trying to execute the query. – Squonk Aug 23 '11 at 22:46

2 Answers2

0

It looks like you need something like

mDb.query("records", new String[] {MediaDbAdapter.KEY_TYPE}, "KEY_TYPE LIKE '%movie%'", null, null, null, null);

The % signs around "movie" tell the SQL engine to search for records that contain the string "movie" somewhere in them.

Peter C
  • 6,219
  • 1
  • 25
  • 37
0

I think this is a simple quoting problem:

mDb.query("records", new String[] {MediaDbAdapter.KEY_TYPE}, "KEY_TYPE LIKE '%movie%'", null, null, null, null);
antlersoft
  • 14,636
  • 4
  • 35
  • 55