gpt4 book ai didi

java - 我的主要 Activity 中出现 NullpointerException 没有结果

转载 作者:行者123 更新时间:2023-12-02 06:44:58 25 4
gpt4 key购买 nike

我被这个问题困住了。希望你能帮我。我给自己买了一个地点应用程序。我仍然不断收到使用它的人的错误。我找不到解决方案。这是我收到的错误消息:

java.lang.NullPointerException
at com.laurenswuyts.find.it.MainActivity$LoadPlaces$1.run(MainActivity.java:297)
at android.app.Activity.runOnUiThread(Activity.java:4631)
at com.laurenswuyts.find.it.MainActivity$LoadPlaces.onPostExecute(MainActivity.java:291)
at com.laurenswuyts.find.it.MainActivity$LoadPlaces.onPostExecute(MainActivity.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)

这是我主要 Activity 的一部分:

protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed Places into LISTVIEW
* */
// Get json response status

if (nearPlaces.results != null) {
String status = nearPlaces.status;

// Check for all possible status
if(status.equals("OK")){
// Successfully got places details
if (nearPlaces.results != null) {




// loop through each place
for (Place p : nearPlaces.results) {


HashMap<String, String> map = new HashMap<String, String>();

// Place reference won't display in listview - it will be hidden
// Place reference is used to get "place full details"
map.put(KEY_REFERENCE, p.reference);

//Distance
double dist, dist2, dist3, dist4;
int dist5;
String distance, distance2, distance3;
Double piem1, piem2;
String piem3, piem4;
double lat1 = gps.getLatitude();
double lng1 = gps.getLongitude();
double lat2 = p.geometry.location.lat;
double lng2 = p.geometry.location.lng;

dist = distance(lat1,lng1,lat2,lng2);

if(dist < 1) {
double meterConversion = 1.609;
double feetConversion = 5.208;
String locale = Locale.getDefault().getISO3Country();
if(locale.equals("USA")){
dist2 = dist * feetConversion;
dist3 = round(dist2,3);
dist4 = dist3 * 1000;
dist5 = (int)dist4;
distance = String.valueOf(dist5);
distance2 = distance + " ft";
}
else{
dist2 = dist * meterConversion;
dist3 = round(dist2,3);
dist4 = dist3 * 1000;
dist5 = (int)dist4;
distance = String.valueOf(dist5);
distance2 = distance + " m";}
}
else {


dist3 = round(dist,1);

String locale = Locale.getDefault().getISO3Country();
if(locale.equals("USA")){
distance = Double.toString(dist3);
distance2 = distance + " mi";
}
else{
double meterConversion = 1.609;
dist2 = dist * meterConversion;
dist3 = round(dist2,1);
distance = Double.toString(dist3);
distance2 = distance + " km";
}
}

piem1 = p.geometry.location.lat;
piem2 = p.geometry.location.lng;
piem3 = Double.toString(piem1);
piem4 = Double.toString(piem2);
distance3 = piem3 + "," + piem4;
map.put(KEY_DISTANCE, distance2);

// Place name
map.put(KEY_NAME, p.name);




//Vicinity
map.put(KEY_VICINITY, p.vicinity);

//Location
map.put(KEY_LOCATION, distance3);


if(p.photos != null){
map.put(KEY_TRUE, "speeltijd");
map.put(KEY_IMAGE, "https://maps.googleapis.com/maps/api/place/photo?maxwidth=65&photoreference="+p.photos[0].photo_reference +"&sensor=true&key=AIzaSyBqUEZXSjwqbXGfEJEO99rQAL8puy11GVg");
}else{
map.put(KEY_TRUE, "school");
}
placesListItems.add(map);

}

lv=(ListView)findViewById(R.id.list);


// Getting adapter by passing xml data ArrayList
adapter = new LazyAdapter(MainActivity.this, placesListItems);
lv.setAdapter(adapter);

// list adapter
/** ListAdapter adapter = new SimpleAdapter(MainActivity.this, placesListItems,
R.layout.list_item,
new String[] { KEY_REFERENCE, KEY_NAME, KEY_VICINITY, KEY_DISTANCE, KEY_LOCATION}, new int[] {
R.id.reference, R.id.name, R.id.vicinity, R.id.radius, R.id.location});

// Adding data into listview
lv.setAdapter(adapter);**/




}
else
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry error occured.",
false);


}

}
else if(status.equals("ZERO_RESULTS")){
// Zero results found

alert.showAlertDialog(MainActivity.this, "Near Places",
"Sorry no places found. Try to change the types of places",
false);

}
else if(status.equals("UNKNOWN_ERROR"))
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry unknown error occured.",
false);

}
else if(status.equals("OVER_QUERY_LIMIT"))
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry query limit to google places is reached",
false);

}
else if(status.equals("REQUEST_DENIED"))
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry error occured. Request is denied",
false);

}
else if(status.equals("INVALID_REQUEST"))
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry error occured. Invalid Request",
false);

}
else
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry error occured.",
false);


}
}else {
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry unknown error occured.",
false);
}
}
});


}

第 291 行从 runOnUiThread(new Runnable() 开始这是行号 291。

提前致谢

最佳答案

onPostExecute() 已在 UI Thread 上。您不需要调用 runOnUiThread()。另外,第 297 行是 if(nearPlaces.results != null) {... 吗?此时nearPlaces 为空吗?

关于java - 我的主要 Activity 中出现 NullpointerException 没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18746768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com