Strange ArrayIndexOutOfBoundsException on some devices when drawing polylines

Below is the code that I use to draw routes. Whenever a user pauses a workout, I want to show this path as a pink polyline. So I created my own interface called MapHelper and took one logical code like isPause and lastPause . When the user saves his workout, I save all the points in the route as an array and in a typical list. I show these maps as channels, and for this I use the version of Googlemap in Lite mode. Below is the adapter class

Adapter.java

 public class FeedsAdpter extends RecyclerView.Adapter<FeedsAdpter.MyViewHolder> { private LayoutInflater inflater; private Context context; private FeedsFragment feedsFragment; RoundedTransFormation transFormation; private ArrayList<FeedsDto> allFeedsList = new ArrayList<FeedsDto>(); public FeedsAdpter(Context context, FeedsFragment feedsFragment) { this.context = context; this.feedsFragment = feedsFragment; transFormation=new RoundedTransFormation(3, 15,Color.WHITE); inflater = LayoutInflater.from(context); } @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = inflater.inflate(R.layout.item_feeds, parent, false); MyViewHolder holder = new MyViewHolder(view); return holder; } @Override public void onViewRecycled(MyViewHolder holder) { super.onViewRecycled(holder); if(Validator.isNotNull(holder.mapView.getMap())) { GoogleMap googleMap = holder.mapView.getMap(); googleMap.clear(); googleMap.setMapType(GoogleMap.MAP_TYPE_NONE); } Picasso.with(context).cancelRequest(holder.userImg); holder.userImg.setImageDrawable(null); holder.likeBtn.setOnClickListener(null); holder.commentBtn.setOnClickListener(null); holder.tvPost.setOnClickListener(null); } @Override public void onBindViewHolder(final MyViewHolder holder, int position) { final FeedsDto feeds = allFeedsList.get(position); if (Validator.isNotNull(feeds)) { if (Validator.isNotNull(feeds.getFeeds().getHistoryMap()) && feeds.getFeeds().getHistoryMap().length > 0) { if (holder.mapView != null) { holder.mapView.onCreate(null); holder.mapView.setVisibility(View.VISIBLE); holder.mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { if (Validator.isNotNull(googleMap)) { googleMap.clear(); holder.mapView.setClickable(false); googleMap.getUiSettings().setMapToolbarEnabled(false); List<HistoryMap> historyMaps = new ArrayList<HistoryMap>(); historyMaps.addAll(Arrays.asList(feeds.getFeeds().getHistoryMap())); Util.drawRouteIntoMap(historyMaps, googleMap); } } }); } } else { holder.mapView.setVisibility(View.GONE); } @Override public void onDetachedFromRecyclerView(RecyclerView recyclerView) { feedsFragment=null; if(Validator.isNotNull(allFeedsList)){ allFeedsList.clear(); } InputMethodManager methodManager = (InputMethodManager)context. getSystemService(Context.INPUT_METHOD_SERVICE); try { Field mNextServedView = methodManager.getClass().getDeclaredField("mNextServedView"); mNextServedView.setAccessible(true); mNextServedView.set(methodManager, null); Field mServedView = methodManager.getClass().getDeclaredField("mServedView"); mServedView.setAccessible(true); mServedView.set(methodManager, null); Method method = methodManager.getClass().getDeclaredMethod("finishInputLocked"); method.setAccessible(true); method.invoke(methodManager); } catch (Throwable e) { e.printStackTrace(); } super.onDetachedFromRecyclerView(recyclerView); } public static void hideKeyboard(Context context) { try { InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); View view = ((Activity) context).getCurrentFocus(); if (view != null) { inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } catch (Exception e) { e.printStackTrace(); } } public void addAll(List<FeedsDto> list) { allFeedsList.addAll(list); notifyDataSetChanged(); } public void clear() { allFeedsList = new ArrayList<FeedsDto>(); notifyDataSetChanged(); } @Override public int getItemCount() { return allFeedsList.size(); } public class MyViewHolder extends RecyclerView.ViewHolder { @Bind(R.id.img_user_pic) ImageView userImg; @Bind(R.id.tv_user_name) TextView tvUserName; @Bind(R.id.tv_duration) TextView tvDuration; @Bind(R.id.tv_msg) TextView tvMsg; @Bind(R.id.workout_map_summary) MapView mapView; @Bind(R.id.et_feeds_comment) EditText etComment; @Bind(R.id.tv_post) ImageView tvPost; @Bind(R.id.img_like_btn) ImageButton likeBtn; @Bind(R.id.img_comment_btn) ImageButton commentBtn; @Bind(R.id.tv_like_count) TextView tvLikecount; @Bind(R.id.tv_comment_count) TextView tvCommentcount; @Bind(R.id.feeds_parent) LinearLayout feedsParent; public MyViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } } 

Here is a link to the json file that I get. Here is a link to the model class that is required. When drawing polylines, it throws an arrayindexoutofbound exception only in lenovo k5 among the devices I tested on. I already asked this question on ArrayIndexOutOfBounds on a graph for an Android polyline

+5
source share

All Articles