Office Hours — Today, December 26

Saturday, December 23

Dec 26
3:50 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
Mike
has entered the room
Mark M.
hello, Mike!
how can I help you today?
Mike
Hi Mark. Hope you are doing well. I am working on a sample app with Retrofit, and there is a line of code that I am having trouble with. I have it on Google Drive, can I paste a link, or is there a diffferent way that you would prefer to look at it. It is 5 files.
Mark M.
um, well, are you comfortable with the world seeing the files? or at least the portion of the world that stumbles upon this chat transcript?
Mike
no problem, I can remove them when we are done. would that work?
4:05 PM
Mark M.
it's more that since I archive these transcripts, I kinda like them to still be useful in the future, to the extent possible
that's a problem for larger dumps of code, since the links will stop working
can you paste in the line that is giving you trouble as a starting point?
Mike
Sure.
Mark M.
then, we can determine what else (if anything) I'll need to see to make sense of the problem
Mike
should I paste or use the "upload a file" link?
Mark M.
for a single line? just paste it into the chat message textarea
Mike
ok, let's start with that:
call.enqueue (new Callback<WeatherResults>()) {
The issue is that enqueue is unresolved
Mark M.
what is the "call" object?
Mike
View paste
WeatherClient client = retrofit.create(WeatherClient.class);
    Call<WeatherResults> call = client.weatherReturned("09105");
these lines seem ok
Mark M.
what version of Retrofit are you using?
because Retrofit 2.x definitely has enqueue() on Call: http://square.github.io/retrofit/2.x/retrofit/
4:10 PM
Mike
2
4:10 PM
Mark M.
on WeatherClient, are you sure that you are importing retrofit2.Call and not some other Call class?
and are you sure that your Callback is a retrofit2.Callback and not some other Callback class?
Mike
Yes, I have several other sample apps loaded in AS from you and other sources, and I have been carefully comparing what I am doing to what others do with Retrofit, as I can't seem to see why it doesn't like it
In the other apps, they have no problem with the enqueue
Mark M.
OK, in Android Studio, start entering a new line of code before the call.enqueue() that is giving you the error
type in call., then wait for autocomplete
is enqueue() an option in the autocomplete?
Mike
Yes, that seems to work.
Mark M.
OK, so you definitely have the right Call class
now, let it autocomplete enqueue, then inside the parentheses, start typing new Callback, until you get an autocomplete to define that
4:15 PM
Mark M.
let the autocomplete build the Callback anonymous inner class for you
and then compare and contrast that enqueue() with the one that the IDE doesn't like
Mike
well...
i do notice that when
I type call. in another app, I get all of the suggestions, but I don't get any in my app
Mark M.
I must have misunderstood -- I thought that you said it worked
Mike
oops, i misread your request. No, I don't get the autocomplete in my app, sorry.
Mark M.
is it that you are not getting any autocomplete, or that autocomplete does not have enqueue() in it?
4:20 PM
Mike
i get none
Mark M.
and you're sure that this call object is in scope at this line?
for example, if you have Call<WeatherResults> call = client.weatherReturned("09105"); in some other method, that's a problem
if it helps, at this point, feel free to upload this particular file using the "upload a file" option, or just paste the whole thing into the textarea
(there's enough context here for people who run across this chat transcript)
4:25 PM
Mike
Would it be OK to upload a zip of my app for you to look at in AS?
wait, sorry, i didn't see your response, stand by while i read
Mark M.
is it OK if I just sit by? I can stand if needed... :-)
Mike
lol
ok, i will paste in the file...
4:30 PM
Mike
View paste (33 more lines)
package net.digital_light.weather;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;


import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class DisplayWeather extends AppCompatActivity {
...
Mark M.
OK
you have an onCreate method
you then have a whole bunch of code that is not in any method
that code belongs in a method somewhere
the reason why the first few lines aren't generating errors is that the IDE thinks that they are field initializers
Mike
oh, wow, let me take a look
dumb mistake, that's what I get for copying code from different places!
Mark M.
for example, if you want that code to run when the activity is created, move it inside the closing } of the onCreate() method
4:35 PM
Mike
I think that is probably what i want, but I want to mull over the whole a little more. Thanks so much for your help!
Mark M.
you're very welcome!
Mike
I think that is all I need right now. Have a great rest of the day.
Mark M.
you too!
4:50 PM
Mike
has left the room
4:55 PM
Mark M.
turned off guest access

Saturday, December 23

 

Office Hours

People in this transcript

  • Mark Murphy
  • Mike