我的Android应用程序正在遭遇这些崩溃,但我无法弄明白。代码似乎很好。奇怪的是,这似乎只发生在三星手机上。除了三星手机,我无法在任何手机上复制它。
java.lang.NullPointerException: Attempt to read from field 'double
com.google.android.gms.maps.model.LatLng.a' on a null object reference
at com.myapp.mapapp.helper.SavedItemsAdapter.access$000(SavedItemsAdapter.java:16)
at com.myapp.mapapp.helper.SavedItemsAdapter$ViewHolder.build(SavedItemsAdapter.java:47)
at com.myapp.mapapp.helper.SavedItemsAdapter.getView(SavedItemsAdapter.java:33)
at android.widget.AbsListView.obtainView(AbsListView.java:2929)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1305)
at android.widget.ListView.onMeasure(ListView.java:1212)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:20151)
at android.support.v7.widget.AlertDialogLayout.tryOnMeasure(AlertDialogLayout.java:135)
at android.support.v7.widget.AlertDialogLayout.onMeasure(AlertDialogLayout.java:63)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:20151)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3158)
at android.view.View.measure(View.java:20151)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2594)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1524)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1841)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7397)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
这是来自文件的代码,它说是导致它的。我查了一下,但一切都很好。
package com.myapp.mapapp.helper;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.google.android.gms.maps.model.LatLng;
import com.myapp.mapapp.R;
/**
* Created by Alexey Rogovoy (lexapublic@gmail.com) on 23.06.2015.
*/
public class SavedItemsAdapter extends ArrayAdapter<SaveLocationHelper.SavedLocation>{
private LayoutInflater mInflater;
public SavedItemsAdapter(Context context,SaveLocationHelper helper){
super(context,0,helper.getItems());
mInflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView==null){
convertView = mInflater.inflate(R.layout.saved_location_list_item,parent,false);
holder = new ViewHolder(convertView);
}
else{
holder = (ViewHolder)convertView.getTag();
}
holder.build(position);
return convertView;
}
private class ViewHolder{
private TextView title;
private TextView location;
public ViewHolder(View rootView){
title = (TextView)rootView.findViewById(R.id.title);
location = (TextView)rootView.findViewById(R.id.location);
rootView.setTag(this);
}
public void build(int position){
SaveLocationHelper.SavedLocation item = getItem(position);
title.setText(item.name);
location.setText(getLocationAsText(item.location));
}
}
private String getLocationAsText(LatLng location) {
return "@"+String.format("%.5f-%.5f",location.latitude,location.longitude);
}
}
答案 0 :(得分:1)
item.location
似乎正在返回null
,因此当您使用location.latitude