Reputation: 189
I know it's have been asked several time, but in all answers, i don't find solution so I come to ask myself.
In an Activity named "DeAs" I have an adress editText, and I want to display a list of potential adress below the editText the user is editing.
So first in the Android Manifest, I've wrote this:
<activity android:name=".DeAs">
<uses-library android:required="true" android:name="com.google.android.maps" />
</activity>
I've transform my build.gradle to load Google API:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:22'
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.example.fabien.rh"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.google.android.gms:play-services:7.5.0'
}
I have declared a Listener on my editText:
adressete = (EditText) rootView.findViewById(R.id.daadressete);
adressete.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
new SearchClicked(adressete.getText().toString(),getActivity()).execute();
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
@Override
public void afterTextChanged(Editable arg0) {}
});
First I've wrote a EditorActionListener but it was not working and I've read that for several Android versions the editorlisteneer was never called. In this Listener I call the class SearchClicked which is below:
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;
import android.util.Log;
import com.google.android.maps.GeoPoint;
import java.util.List;
import java.util.Locale;
public class SearchClicked extends AsyncTask<Void, Void, Boolean> {
private String toSearch;
private Address address;
private Context c;
public SearchClicked(String toSearch, Context c) {
this.toSearch = toSearch;
this.c= c;
}
@Override
protected Boolean doInBackground(Void... voids) {
try {
Geocoder geocoder = new Geocoder(c, Locale.UK);
List<Address> results = geocoder.getFromLocationName(toSearch, 1);
if (results.size() == 0) {
return false;
}
address = results.get(0);
// Now do something with this GeoPoint:
GeoPoint p = new GeoPoint((int) (address.getLatitude() * 1E6), (int) (address.getLongitude() * 1E6));
} catch (Exception e) {
Log.e("", "Something went wrong: ", e);
return false;
}
return true;
}
}
When i run it, it well loads, but when I try writing something on the edittext i have an error:
Could not find class 'com.google.android.maps.GeoPoint'
ATAL EXCEPTION: AsyncTask #1
Process: com.example.fabien.rh, PID: 26795
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NoClassDefFoundError: com.google.android.maps.GeoPoint
at com.example.fabien.renthelper.SearchClicked.doInBackground(SearchClicked.java:40)
at com.example.fabien.renthelper.SearchClicked.doInBackground(SearchClicked.java:16)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
On this topic, I've have potentially found a solution: Libraries do not get added to APK anymore after upgrade to ADT 22 But I don't find "Order and Export" in Android Studio, and I don't have "Android Private Libraries": when I look for Libraries in "Project Structure" all i have is this:
"support-annotations (com.android.support-annotations:22.2.1)
support-v4 (com.android.support:support-v4:22.2.1)
support-v13 (com.android.support-v13:22.2.1)
appcompat-v7 (com.android.support:appcompat-v7:22.2.1)
design (com.android.design:22.2.1)
gridlayout-v7 (com.android.support.gridlayout-v7:22.2.1)
mediarouter-v7 (com.android.support:mediarouter-v7:22.2.1)
play-services (com.google.android.gms:play-services:7.5.0)
play-service-wearable (com.google.android.gms:play-services_wearable:7.5.0)
cardview-v7 (com.android.support-cardview-v7:22.2.1)
palette-v7 (com.android.support-palette-v7:22.2.1)
[...]"
If you can help, thank you in advance! ;)
Upvotes: 0
Views: 6287
Reputation: 3540
I don't know how that code could compile and from the posted elements it's not 100% clear how you configured the build on android studio, but in any case, there is no GeoPoint in google maps API v2.
You should instead use LatLng object: https://developers.google.com/android/reference/com/google/android/gms/maps/model/LatLng
Upvotes: 1