我遇到了以下错误。
logUser("An error happend while creating graph:"+ getErrorMessage());
其中 getErrorMessage() 是 Can't create handler inside 未调用 Looper.prepare() 的线程,而 logUser 是一个仅显示 toast congaing 消息的函数。
void prepareGraph() {
logUser("loading graph (" + Helper.VERSION + "|" + Helper.VERSION_FILE
+ ") ... ");
new MyAsyncTask<Void, Void, Path>() {
protected Path saveDoInBackground(Void... v) throws Exception {
GraphHopper tmpHopp = new GraphHopper().forAndroid();
tmpHopp.contractionHierarchies(true);
tmpHopp.load(mapsFolder + currentArea);
logUser("found graph with " + tmpHopp.getGraph().nodes() + " nodes");
hopper = tmpHopp;
return null;
}
protected void onPostExecute(Path o) {
if (hasError()) {
logUser("An error happend while creating graph:"
+ getErrorMessage());
} else {
logUser("Finished loading graph. Touch to route.");
calcPath(52.534185, 13.348732, 52.53857,
13.41259);
}
finishPrepare();
}
}.execute();
}