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?
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
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:
/**
* 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
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.
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...
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....
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.