Dec 13 | 9:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Dec 13 | 10:00 AM |
JY | has entered the room |
Mark M. |
howdy, JY
|
Mark M. |
how can I help you today?
|
Gabriele | has entered the room |
Mark M. |
howdy, Gabriele!
|
JY |
Hi Mark, I have some trouble regarding SQLiteDatabase. I can't solve it even after I looked for help on stackoverflow
|
JY | |
Gabriele |
Hi :) I don't have questions for now, just here observing! :P
|
Mark M. |
Gabriele: OK
|
Mark M. |
"it didn't work" is a useless description of your symptoms
|
Mark M. |
please explain *precisely* what "didn't work"
|
Mark M. |
oh, wait, never mind
|
JY |
OK, the app crashes.
|
Mark M. |
java.lang.RuntimeException: Unable to start
activity
ComponentInfo{com.demostudio.restaurants/com.demostudio.restaurants.AllRestaurants}:
java.lang.IllegalArgumentException: column '_id' does not exist
|
Mark M. |
you are not creating an _id column
|
Mark M. |
your CREATE TABLE has RestaurantID, not _id
|
Dec 13 | 10:05 AM |
Mark M. |
and CursorAdapter needs the Cursor to have _id as a column
|
Mark M. |
your query is trying to rename colRestaurantID as _id
|
Mark M. |
but you do not have a colRestaurantID column
|
Mark M. |
you have a RestaurantID column
|
Mark M. |
you appear to be mixing up your Java constants (colRestaurantID) with your chosen representation in your SQL (RestaurantID)
|
JY |
Oh ok, so in my SQL, I need to use RestaurantID?
|
Mark M. |
in the SELECT statement for rawQuery(), yes
|
Mark M. |
I am a bit surprised that you got the error you did -- I would have expected SQLite to complain about missing columns
|
Mark M. |
your other column names in that SELECT statement also need to be adjusted
|
JY |
How about in other cases like onCreate where I also use SQL?
|
JY |
Or is it just in rawQuery?
|
Mark M. |
you need to be consistent
|
Mark M. |
in onCreate(), you are using the *value* of the
*Java constant*, whereas in rawQuery(), you are treating
"colRestaurantID" as a string itself
|
Mark M. |
so, for example, you could change your rawQuery() to concatenate things the way your CREATE TABLE statement is constructed
|
Dec 13 | 10:10 AM |
JY |
OK, I think I kind of understand. Alright, let me try and I will get back to you. Thanks Mark.
|
Mark M. |
OK
|
Mark M. |
if either of you has a question, while nobody else is in the chat, feel free to chime in
|
Gabriele |
eheh thank you :)
|
Gabriele |
I have one, if I have to execute http request,
it's good to execute them on a separate thread (maybe using asynctask),
but If I need to wait its result (so it should be synchronous) what can I
do?
|
Mark M. |
rework your UI so that you do not "need to wait its result"
|
Dec 13 | 10:15 AM |
Gabriele |
what I'm doing it's a client which sends the request to BlueSocket (maybe you know)
|
Gabriele |
it's a public wifi of the university
|
Gabriele |
but you need to login before access
|
Gabriele |
I'm sending login data, but I have to wait its answer before proceed
|
Mark M. |
no, you need to continue doing your work after the answer is ready
|
Mark M. |
that does not mean that it is synchronous
|
Gabriele |
ah
|
Mark M. |
continue your work from `onPostExecute()`
|
Mark M. |
disable anything in the UI that cannot be used while you are waiting for the result
|
Gabriele |
another question, is it a bad thing to execute a new asynctask from onPostExecute?
|
Mark M. |
no, that works OK
|
Mark M. |
you cannot start an AsyncTask from doInBackground()
|
Mark M. |
but starting one from onPostExecute() is within reason
|
Mark M. |
however, you might consider simply merging the two tasks
|
Gabriele |
ok, so I can move the other task inside onPostExecute
|
Gabriele |
ah
|
Gabriele |
then I will merge them
|
Mark M. |
JY: I added an answer on your SO question that may help
|
JY |
OK, it works now!
|
JY |
I can't believe this simple thing has been bothering me in the past few days..
|
Dec 13 | 10:20 AM |
Mark M. |
one suggestion: it is standard in Java to have your static final data members be in all caps, such as COL_RESTAURANT_ID
|
Gabriele |
another question, it seems that something in my
wikipedia app is incompatible with android 4 (I'm saying it because I
can't select it from my emulator dropdown selector), but I remember that
time ago I had warning saying something about incompatibility on
methods with a specific version
|
Mark M. |
that might help you keep track of the difference between the literal SQL and the Java representations of those SQL pieces
|
Mark M. |
Gabriele: if you cannot choose an emulator, that typically is due to your <uses-sdk> element
|
Mark M. |
mostly, you will see that for older emulators, where android:minSdkVersion is set higher than the emulator
|
Gabriele | |
Mark M. |
you should be able to run that on any emulator for API Level 11 or higher
|
JY |
Another related question. Can I not concatenate
things but use RestaurantID and the like in onCreate to create table? I
think it looks cleaner that way.
|
JY |
OK, I will do that then. Thanks.
|
Mark M. |
JY: you are welcome to concatenate or not, you just have to be consistent about the values that you are concatenating
|
Gabriele |
ah, I had to restart the ide after adding it
|
JY |
OK, I saw your reply on SO. Thanks!
|
Dec 13 | 10:25 AM |
Gabriele |
View paste
|
Mark M. |
that method was added in API Level 16
|
Mark M. |
you will need to avoid calling it on older versions of Android
|
Gabriele |
but I'm only doing host.startActionMode, is this wrong?
|
Mark M. |
somebody is calling setTitleOptionalHint()
|
Gabriele |
oh no true
|
Mark M. |
you can use Build.VERSION to conditionally call that method on supported versions
|
Gabriele |
but if I'm using minsdkversion to 11, shouldn't the ide tell me "ehy you can't use this method"?
|
Mark M. |
in theory, Lint should be yelling at you
|
Mark M. |
do you have a @TargetApi annotation on the method where you are calling setTitleOptionalHint(), or on the class?
|
Mark M. |
or perhaps a @SuppressLint annotation on the method or class?
|
Dec 13 | 10:30 AM |
Gabriele |
no I don't think I've ever added it and I can't see this in the file
|
Mark M. |
try manually running Lint (right-click over project, choose Android Tools > Run Lint from the context menu)
|
JY |
So now I have a listview XML layout and also a
textview XML layout. What I actually want is only the textview. However,
if I change setContentView(R.layout.activity_listview) to
setContentView(R.layout.activity_all_restaurants) which is the textview
XML, it won't work. Is there anyway I can fix this?
|
Mark M. |
JY: that does not make much sense
|
Mark M. |
why are you querying a database for all restaurants if you do not want to show a list of those restaurants?
|
Mark M. |
your "textview XML layout" is for your rows in your list, as you have things presently set up
|
Mark M. |
(at least, based on the code in the SO question)
|
JY |
I want a list of restaurants, but right now what it is giving me is many lines of the same restaurant.
|
JY |
It gives me many lines of Restaurant AAA and then many lines of Restaurant BBB.
|
Mark M. |
then that is what is in your database
|
Dec 13 | 10:35 AM |
Mark M. |
your code is populating the ListView rows based on the query results
|
Mark M. |
if you are seeing "many lines of Restaurant AAA
and then many lines of Restaurant BBB", then that is what is coming back
in the query results
|
JY |
OK. I might have inadvertently created many records when I ran the app.
|
Mark M. |
you might consider clearing your data or uninstalling the app, to start with a fresh database, then go from there
|
Gabriele |
hm no Lint isn't saying anything
|
Mark M. |
Gabriele: perhaps you accidentally disabled that Lint check
|
Mark M. |
that could be at the project level or the workspace level
|
Dec 13 | 10:40 AM |
Mark M. |
for the project, Project Properties > Android Lint Preferences
|
Gabriele |
how can this option be called?
|
Mark M. |
how can what option be called?
|
Gabriele |
this one which enables warnings
|
Mark M. |
by default, it is enabled
|
Gabriele |
if I'm using a method I can't use
|
Mark M. |
however, you might have accidentally told Eclipse to ignore it.
|
Mark M. | |
Mark M. |
for the project, Project Properties > Android Lint Preferences
|
Mark M. |
type ~ignore in the search field
|
Mark M. |
and see what comes up
|
Mark M. |
or, search for NewApi, which I think is the actual Lint check in question
|
Mark M. |
yeah, NewApi appears to be it
|
Mark M. |
check what the severity is on it -- if it is set to "ignore", switch it to "error"
|
JY |
I thought each XML file correspond to one layout.
How can two XML files be used in a source file and display both of them?
In my case which is listview XML file and textview XML file. How does
it work actually?
|
Gabriele |
maybe is something to do with intellij then, I can't find it
|
Mark M. |
Gabriele: oh, sorry, I though you were using Eclipse
|
Mark M. |
I have no idea what/how IDEA does in this area, sorry
|
Dec 13 | 10:45 AM |
Gabriele |
I hate eclipse because it always gives a lot of error and I have to spend my time resolving eclipse problems TT
|
Mark M. |
JY: when you search your AllRestaurants class for t
|
Mark M. |
er, let me try that again
|
Mark M. |
JY: when you search your AllRestaurants class for activity_all_restaurants, what do you see?
|
Mark M. |
you should see that you are referencing that layout resource in your SimpleCursorAdapter constructor
|
Mark M. |
this indicates a layout resource to use for rows in your ListView
|
Mark M. |
this is separate from the layout you use for your overall activity
|
JY |
OK.
|
JY |
Thanks!
|
Mark M. |
I would recommend that you review my book, pages 1-200, and then 467-484 (using page numbers from the current Version 4.4)
|
Mark M. |
specifically, pages 171-200 cover the use of AdapterViews like List View, and 487-484 cover using a database
|
JY |
I did read those pages quite a few times actually. I guess I have to spend more time on them then.
|
Dec 13 | 10:50 AM |
Mark M. |
in the chapter on AdapterView, you will see how we use layout files to define rows in a ListView, using an ArrayAdapter
|
Mark M. |
SimpleCursorAdapter and a database work on the same principle
|
JY |
I closed my emulator and reopen it and then
relaunch the app, but I am still seeing the same thing (many lines of
the same restaurant). Does closing the emulator not uninstall the app?
|
Mark M. |
no, it does not, any more than rebooting your phone uninstalls the apps on your phone
|
Mark M. |
to uninstall an app on the emulator, you can go into Settings, the same as you would on your phone
|
Dec 13 | 10:55 AM |
JY |
Mark, any way to save this conversation other than copy and paste?
|
Mark M. |
it will be archived to http://commonsware.com/office-hours/ shortly after the chat is over
|
JY |
Ok, great.
|
Gabriele |
nice
|
JY |
Alright, thanks Mark.
|
JY | has left the room |
Gabriele |
thank you very much Mark, see you the next time!
|
Mark M. |
next chat is Tuesday, 10am Eastern
|
JY | has entered the room |
Dec 13 | 11:00 AM |
Gabriele |
ok, thank you
|
JY |
I uninstall the app and try to relaunch it, then it crashes again this time.
|
Mark M. |
JY: we will have to pick that up in the next chat
|
JY |
I didn't change anything in the codes.
|
Mark M. |
as this chat hour is over
|
JY |
OK. Thanks
|
Mark M. |
the next chat is Tuesday at 10am Eastern
|
Mark M. |
have a pleasant day, all!
|
JY |
You too.
|
JY | has left the room |
Gabriele | has left the room |
Mark M. | turned off guest access |