• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps String problem (sqlite-query)

the only thing I can think of is that the query1 String is null at the time that SQL is executed. Have you logged out the fully formed SQL string to verify that your query1 variable is initialized when the emulator force closes?
 
Ok, so you are using a toast to see what is in query1... and can I assume that query1 = "Test"?

where in the code are you calling the toast? Could the value of query1 have changed by the time the SQL is called?

Put your Toast.makeText(...) call right before
Code:
String keyword = "name1 LIKE '%"+query1+"%'";

Is it still the string you expect it to be?
 
Seems like the Toast will not be shown, when I put it right before this line?! It all seems to be very slow....but it seems, you`re right.

I call ladeDaten(String query1) at the end of an onItemSelected (OnItemSelectedListener).
query1 = selecteditem...it looks like the value (query1) of item is still null?! ...any ideas or workaround for that?
As I said, I
 
post your code for the selected item listener... maybe we can figure out what's wrong there.

I'm a Java developer for web applications (J2EE) but not really for Android, so I haven't really worked with Android event handlers a lot... But maybe an extra pair of eyes on your code is all we need here :)
 
thanks :-)
It`s just this:

public class MyOnItemSelectedListener1 implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
ladeDaten(parent.getItemAtPosition(pos).toString());
}

public void onNothingSelected(AdapterView<?> parent) {
// Do nothing. }}
}
}


This was the one with the toast:

public
class MyOnItemSelectedListener1 implements OnItemSelectedListener {
publicvoid onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(),
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show();
ladeDaten(parent.getItemAtPosition(pos).toString());
}

publicvoid onNothingSelected(AdapterView<?> parent) {
// Do nothing. }}
}
}

 
I had to do some googling to figure out how the listener works. Seems to me you are missing a constructor for your listener class, where you would define the activity and adapter for your listener. See this example:

SpinnerActivity.java | Android Developers

Note the constructor:

Code:
        /**
         *  Constructor
         *  @param c - The activity that displays the Spinner.
         *  @param ad - The Adapter view that
         *    controls the Spinner.
         *  Instantiate a new listener object.
         */
        public myOnItemSelectedListener(Activity c, ArrayAdapter<CharSequence> ad) {

          this.mLocalContext = c;
          this.mLocalAdapter = ad;

        }


I don't see a constructor in your code block. Which means your listener is listening to nothing. That could explain the null :)
 
BTW, welcome to the forums :)

I'm going to move your post from the Android Lounge to the Android Development area. Perhaps the people there, who surely are more versed than me, can help you get past your current issue.
 
Thanks, I will try to check, how to do this...

My code comes from here (I just adapted it):
Spinner | Android Developers ...but it still amost the same.

It`s really strange, because I made a .setText(query1) right before the query (one line before) -> and query1 is displayed correctly in the TextView....Hmmm...
 
Another problem, but I think, that`s my very small knowledge:

This one works:
Cursor klassenCursor = mDatenbank.query(
"Tabelle",
new String[] {
"feld1",
"feld2"
},
null, null, null, null,null );


this not:
String keyword = null;
Cursor klassenCursor = mDatenbank.query(
"Tabelle",
new String[] {
"feld1",
"feld2"
},
keyword, null, null, null,null );


Anyone, who could tell me why?

Thank you
 
Oh, my third post in a row...I have solved the first issue:

onItemSelected will also be called at onCreate and that`s the problem...at least it seems, it`s okay now :-)
I just use a boolean to check, if onItemSelected is called for the first time...

But I still don`t know, why I can`t set a string to null....
 
do a null check and convert it to an empty string. the null is causing the SQL query to be malformed.



Code:
if (query1 == null) query1 = "";
String keyword = "name1 LIKE '%"+query1+"%'";

that should fix it I think.
 
btw, just to clarify, you shouldn't *technically* need a constructor for listener objects. Though the code and examples above make use of them.

Also @OP you should, when you get some time learn about binding your SQL queries

Also, the reason you cant convert null to a string is that you cant point to null.

To phrase it differently, you cant convert "nothing" into a string.
 
Back
Top Bottom