我面臨一個問題,我不知道如何解決。我有一個應用程序,它使用內置的android地理編碼器。代碼很簡單 - 我得到的地址和座標顯示在地圖上。在模擬器上,它運行得很好,但在所有真正的設備上,應用程序崩潰,試圖獲得一些地址(geocoder返回null數組)。 下面是代碼:地理編碼器故障 - 有時返回空數組
@Override
protected List<Address> doInBackground(String... params) {
Log.d(TAG, "doinbackground SetRightMapDisplayAddress started");
long startTime= System.currentTimeMillis();
long threadId = Thread.currentThread().getId();
Log.d(TAG, String.format("The thread id is: %d", threadId));
context = getActivity();
String placeName = params[0];
List<Address> addressList = downloadData.findAddressesByName(context, placeName);
int returnedAddresses = addressList.size();
Log.d(TAG, String.valueOf(returnedAddresses));
long endTime = System.currentTimeMillis();
Log.d(TAG, String.valueOf(startTime-endTime));
Log.d(TAG, "doinbackground SetRightMapDisplayAddress ended");
return addressList;
}
異常(它指向這一行:
int returnedAddresses = addressList.size();
):
07-01 15:41:58.509: ERROR/AndroidRuntime(9158): FATAL EXCEPTION: AsyncTask #3
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at com.shop.pagerFragments.TorgCentrMapFragment$SetRightMapDisplayAddress.doInBackground(TorgCentrMapFragment.java:349)
at com.shop.pagerFragments.TorgCentrMapFragment$SetRightMapDisplayAddress.doInBackground(TorgCentrMapFragment.java:337)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more
我在這裏讀了很多,但我沒」能夠找到解決方案。也許有一個web api,可以抓住相同的地址列表?也許有一些服務,隱藏在設備上並不可用(也許我需要填充警報並讓用戶打開一些服務)? P.S.位置服務在所有設備上運行。拜託,我需要你的幫助,夥計們。
,我曾經歷過,有些設備沒有內置的地理編碼器像索尼愛立信新 –