Hello fellow developers,
I am a total newbie in Android development and I am trying to write an application that uses the Google Places Api. I have done a lot of research in setting up Eclipse and finding out where to place the various jar files. (Boy that was a project y itself). Okay so now my problem is that I have been following Davy’s Tech Blog (http://ddewaele.blogspot.com/2011/05/introducing-google-places-api.html) and I am running into some problems.
I have downloaded the following Jars:
google-api-client-1.4.1.beta
google-api-client-1.8.0.beta (with dependecies)
google-collect-1.0-rc1
and I have added these to my libs folder
The application can compile correctly, but when the application runs on the Android simulator it comes up with an error message stating “Unfortunately, the application has stopped”
Looking into the Log Cat I can see the following:
05-10 04:26:32.456: I/System.out(1408): Perform Search ….
05-10 04:26:32.456: I/System.out(1408): ——————-
05-10 04:26:32.486: I/dalvikvm(1408): Could not find method com.google.api.client.googleapis.GoogleHeaders.setUserAgent, referenced from method com.google.api.client.googleapis.GoogleHeaders.setApplicationName
05-10 04:26:32.486: W/dalvikvm(1408): VFY: unable to resolve virtual method 279: Lcom/google/api/client/googleapis/GoogleHeaders;.setUserAgent (Ljava/lang/String;)V
05-10 04:26:32.486: D/dalvikvm(1408): VFY: replacing opcode 0x6e at 0x0000
The method looks like this:
public static HttpRequestFactory createRequestFactory(final HttpTransport transport) {
return transport.createRequestFactory(new HttpRequestInitializer() {
public void initialize(HttpRequest request) {
GoogleHeaders headers = new GoogleHeaders();
headers.setApplicationName("MyFirstLocationApp");
request.headers=headers;
JsonHttpParser parser = new JsonHttpParser();
parser.jsonFactory = new JacksonFactory();
request.addParser(parser);
}
});
}
I think it has something to do with the Jar files that I have included. I believe that setApplicationName is found in google-api-client-1.8.0.beta and the setUserAgent is located in the google-api-client-1.4.1.beta (Under the Http class).
The problem however is that most of my objects I need are not found in google-api-client-1.8.0.beta but in google-api-client-1.4.1.beta
These are the imports I have:
import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.http.json.JsonHttpParser;
import com.google.api.client.json.jackson.JacksonFactory;
Any help is appreciated. This is driving me nuts.
/Imran
So I included only the 1.8.0 stuff which is below and included just the jars suggested by the usage doc’s of the API ( Just D&D’d them into the lib’s folder ) using eclipse indigo which just lets you drop files into the folder (not sure which version your using but indigo handles this stuff better then the previous version)
Then modified your code a bit for the newer API
It compiles and seems to work fine for a trivial test, I suggest you try it using straight 1.8.0 and see if that works.