尝试调用虚拟方法 'java.lang.Object android.content.Context.getSystemService(java.lang.String)
我想问,为什么我的代码在设备上运行时不起作用,但是当我像Genymotion一样在模拟器Android上运行时,它工作得很好。
有人像这样在这个链接上说:除非在某些情况下,否则在super.onCreate()之后,你不能在Active超类上调用方法。请推迟对 promptsView 的初始化,直到调用 super.onCreate() 之后。
我仍然不明白,如果你有同样的问题,请告诉我。
无论如何,如果我的解释不好,我很抱歉。
public class DestinationListAdapter extends ArrayAdapter<DestinationModel> {
Context context;
int layoutResourceId;
List<DestinationModel> data = Collections.emptyList();
public DestinationListAdapter(Context context, int layoutResourceId, List<DestinationModel> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
DestinationHolder holder = null;
if(row == null)
{
// Predicted Error At Line Below
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new DestinationHolder();
holder.destination_id = (TextView) row.findViewById(R.id.destination_id);
holder.destination_name = (TextView) row.findViewById(R.id.destination_name);
row.setTag(holder);
}
else
{
holder = (DestinationHolder)row.getTag();
}
DestinationModel weather = data.get(position);
holder.destination_id.setText(weather.getDestination_id());
holder.destination_name.setText(weather.getDestination_name());
return row;
}