简体   繁体   English

滚动到特定位置时,Recyclerview崩溃

[英]Recyclerview crashed when scrolled to particular position


I have RecyclerView and it has Pagination, When I scroll some times it is being crashed. 我有RecyclerView ,它具有分页功能,当我滚动几次时,它崩溃了。 When I scroll slowly it is not being crashed. 当我缓慢滚动时,它不会崩溃。 I have provided Adapter and Activity code. 我提供了适配器和活动代码。 Please let me know any mistake here I did. 请让我知道我在这里犯的任何错误。 I have searched for same issues , but I am not able to catch error here. 我已经搜索了相同的问题,但是我无法在此处捕获错误。

private class GetTrending extends AsyncTask<Void, Void, Void> {
    BufferedReader bufferedReader = null;
    private StringBuffer stringBuffer = new StringBuffer();
    private JSONArray jArray = new JSONArray();
    private int pageNum;
    private boolean value;

    public GetTrending(int pageNum, boolean value) {
        this.pageNum = pageNum;
        this.value = value;
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {

            HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet();
            URI uri = new URI(getString(R.string.url) +
                    "products?bestsellers=on&items_per_page=24&page=" + pageNum + mWholeSaleUrlTag);

            httpGet.setURI(uri);
            httpGet.addHeader(BasicScheme.authenticate(
                    new UsernamePasswordCredentials(getString(R.string.username), getString(R.string.password)),
                    HTTP.UTF_8, false));
            HttpResponse httpResponse;
            Log.e("Trending-Before", "Date" + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date()));
            httpResponse = httpClient.execute(httpGet);
            Log.e("Trending-After", "New Date" + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date()));
            InputStream inputStream = httpResponse.getEntity().getContent();
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            //Log.e("Hi", String.valueOf(bufferedReader));
            String readLine = bufferedReader.readLine();
            while (readLine != null) {
                stringBuffer.append(readLine);
                //stringBuffer.append("\n");
                readLine = bufferedReader.readLine();

            }
            //Log.e("BestSellers", String.valueOf(stringBuffer));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        try {
            JSONObject prodObjects = new JSONObject(String.valueOf(stringBuffer));
            jArray = prodObjects.optJSONArray("products");
            if (jArray.length() < 24) {
                shouldFetchTrending = false;
            }

            for (int i = 0; i < jArray.length(); i++) {
                Home home = new Home();
                prodObjects = jArray.getJSONObject(i);
                home.setProduct_id(prodObjects.getString("product_id"));
                // Log.e("Trending id", jobj.getString("product_id"));
                home.setProduct_name(prodObjects.getString("product"));
                NumberFormat nf = NumberFormat.getInstance();
                nf.setMinimumFractionDigits(2);
                nf.setMaximumFractionDigits(2);
                home.setProduct_price(nf.format(Double.parseDouble(prodObjects.getString("price"))));
                home.setProduct_listprice(nf.format(Double.parseDouble(prodObjects.getString("list_price"))));
                String mAmount = prodObjects.getString("amount");
                home.setAmount(mAmount);


                Item item = new Item();

                item.setName(prodObjects.getString("product"));
                item.setProductId(prodObjects.getString("product_id"));
                item.setPrice(nf.format(Double.parseDouble(prodObjects.getString("price"))));
                item.setListPrice(nf.format(Double.parseDouble(prodObjects.getString("list_price"))));
                item.setImage(prodObjects.getJSONObject("main_pair").getJSONObject("detailed").getString("image_path"));
                item.setAmount(mAmount);


                home.setProduct_image(prodObjects.getJSONObject("main_pair").getJSONObject("detailed").getString("image_path"));

                if (prodObjects.getString("status").equalsIgnoreCase("A") && !prodObjects.getString("amount").equalsIgnoreCase("0")) {
                    Sports.add(home);
                    trendingItemList.add(item);
                }


            }
            // Log.e("Length", String.valueOf(Sports.size()));
        } catch (JSONException e) {
            e.printStackTrace();
        }


        return null;
    }

    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        shouldFetchTrending = true;
        if (value) {
            trendingItemAdapter = new ItemAdapter(HomeActivity.this, trendingItemList);
            mTrendingRecyclerView.setAdapter(trendingItemAdapter);
        }
        trendingItemAdapter.notifyDataSetChanged();


        mTrendingRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(HomeActivity.this, new RecyclerItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                ((CardView) view).setCardElevation(100);
                Intent myintent = new Intent(HomeActivity.this, ProductPageActivity.class);
                myintent.putExtra("Prodid", trendingItemList.get(position).getProductId());
                myintent.putExtra("FromHome", "Home");
                startActivity(myintent);
            }
        }));

        try {
            for (int i = 0; i < Sports.size(); ++i) {
                trendinglinear[i].setVisibility(View.VISIBLE);
                tname[i].setText(Sports.get(i).getProduct_name());
                tprice[i].setText(Sports.get(i).getProduct_price());
                ((View) tname[i].getParent()).setTag(Sports.get(i).getProduct_id());
                String[] simg = new String[25];
                simg[i] = Sports.get(i).getProduct_image();
                //Log.e("image", simg[i]);
                Picasso.with(getApplicationContext()).load(simg[i]).error(R.drawable.ic_launcher).resize(400, 400).into(timage[i]);

            }
        } catch (Exception e) {
            //Toast.makeText(HomeActivity.this, "Failed to connect to internet Try again !", Toast.LENGTH_SHORT).show();

        }

    }
}

public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ViewHolder> {
    private List<Item> itemList;
    private Context context;
    private int lastPosition = -1;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.home_recycler_item, parent, false);

        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Item item = itemList.get(position);
        holder.tvName.setText(item.getName());
        if(Integer.valueOf(item.getAmount()) == 0)
        holder.tvOutofstack.setVisibility(View.VISIBLE);
        else holder.tvOutofstack.setVisibility(View.INVISIBLE);

        holder.tvPrice.setText(item.getPrice());
        Picasso.with(context).load(item.getImage()).into(holder.ivImage);
        setAnimation(holder.cardView, position);

    }

    @Override
    public int getItemCount() {
        return itemList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        public TextView tvName,tvOutofstack;
        public TextView tvPrice;
        public ImageView ivImage;

        public CardView cardView;



        public ViewHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvOutofstack = (TextView) itemView.findViewById(R.id.item_adapter_tv);
            tvPrice = (TextView) itemView.findViewById(R.id.tv_price);
            ivImage = (ImageView) itemView.findViewById(R.id.iv_image);
            cardView = (CardView) itemView.findViewById(R.id.card_view);
        }
    }

    public ItemAdapter(Context context, List<Item> itemList) {
        this.itemList = itemList;
        this.context = context;
    }

    private void setAnimation(View viewToAnimate, int position)
    {
        // If the bound view wasn't previously displayed on screen, it's animated
        if (position > lastPosition)
        {
            Animation animation = AnimationUtils.loadAnimation(context,  android.R.anim.slide_in_left);
            viewToAnimate.startAnimation(animation);
            lastPosition = position;
        }
    }
}

Some error shown(Log): 显示了一些错误(日志):

java.lang.InternalError: Thread starting during runtime shutdown 07-13 09:01:29.721 32089-1640/? java.lang.InternalError:线程在运行时关闭期间启动07-13 09:01:29.721 32089-1640 /? W/System.err: at java.lang.Thread.nativeCreate(Native Method) ----------and ---------- GC_FOR_ALLOC freed 1057K, 20% free 115415K/143088K, paused 295ms, total 295ms 07-13 11:57:15.692 11792-12003/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 116.585MB for 4000012-byte allocation 07-13 11:57:15.936 11792-12001/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed <1K, 17% free 119321K/143088K, paused 245ms, total 245ms 07-13 11:57:15.960 11792-12017/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 41K, 17% free 119389K/143088K, paused 21ms, total 21ms 07-13 11:57:15.960 11792-12017/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 120.466MB for 4000012-byte allocation 07-13 11:57:15.992 11792-12003/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 8K, 14% free 123287K/143088K, paused 29ms, total 29ms 07-13 11:57:15.992 11792-11792/com.dealmaar.customer I/Choreographer: Skipped 34 frames! W / System.err:java.lang.Thread.nativeCreate(Native Method)----------和---------- GC_FOR_ALLOC释放了1057K,20%释放了115415K / 143088K,暂停295毫秒,总计295毫秒07-13 11:57:15.692 11792-12003 / com.dealmaar.customer I / dalvikvm-heap:将堆(frag情况)增加到116.585MB以用于4000012字节分配07-13 11:57:15.936 11792-12001 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC已释放<1K,17%释放119321K / 143088K,已暂停245ms,总计245ms 07-13 11:57:15.960 11792-12017 / com.dealmaar.customer D / dalvikvm :GC_FOR_ALLOC释放41K,释放17%119389K / 143088K,暂停21ms,总计21ms 07-13 11:57:15.960 11792-12017 / com.dealmaar.customer I / dalvikvm-heap:将堆(frag case)增加到120.466MB 4000012字节分配07-13 11:57:15.992 11792-12003 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了8K,14%释放了123287K / 143088K,已暂停29ms,总计29ms 07-13 11:57:15.992 11792 -11792 / com.dealmaar.customer I / Choreographer:跳过了34帧! The application may be doing too much work on its main thread. 该应用程序可能在其主线程上做太多工作。 07-13 11:57:16.036 11792-12001/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 8172K, 20% free 115531K/143088K, paused 23ms, total 23ms 07-13 11:57:16.036 11792-12001/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 116.699MB for 4000012-byte allocation 07-13 11:57:16.068 11792-12003/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 6K, 17% free 119431K/143088K, paused 29ms, total 29ms 07-13 11:57:16.096 11792-12017/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 119K, 17% free 119613K/143088K, paused 19ms, total 19ms 07-13 11:57:16.096 11792-12017/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 120.685MB for 4000012-byte allocation 07-13 11:57:16.124 11792-12001/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed <1K, 14% free 123519K/143088K, paused 28ms, total 28ms 07-13 11:57:16.136 11792-11792/com.dealmaar.customer V/...: Last Item Wow ! 07-13 11:57:16.036 11792-12001 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了8172K,释放了20%的115531K / 143088K,暂停了23ms,总计23ms 07-13 11:57:16.036 11792-12001 / com .dealmaar.customer I / dalvikvm-heap:将堆(frag case)增加到116.699MB以分配4000012字节的分配07-13 11:57:16.068 11792-12003 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC已释放6K,17空闲百分比119431K / 143088K,已暂停29ms,总计29ms 07-13 11:57:16.096 11792-12017 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC已释放119K,17%空闲119613K / 143088K,已暂停19ms,总计19ms 07- 13 11:57:16.096 11792-12017 / com.dealmaar.customer I / dalvikvm-heap:将堆(frag case)增长到120.685MB,以实现4000012字节分配07-13 11:57:16.124 11792-12001 / com.dealmaar .customer D / dalvikvm:GC_FOR_ALLOC释放<1K,释放14%123519K / 143088K,暂停28ms,总计28ms 07-13 11:57:16.136 11792-11792 / com.dealmaar.customer V / ...:最后一项哇! 07-13 11:57:16.172 11792-12002/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 4252K, 14% free 119709K/139172K, paused 31ms, total 32ms 07-13 11:57:16.180 11792-12002/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 120.779MB for 4000012-byte allocation 07-13 11:57:16.456 11792-12003/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 5K, 12% free 123609K/139172K, paused 263ms, total 263ms 07-13 11:57:16.680 11792-12003/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 3730K, 14% free 120100K/139172K, paused 170ms, total 170ms 07-13 11:57:16.680 11792-12003/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 121.161MB for 4000012-byte allocation 07-13 11:57:16.712 11792-12002/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 4K, 11% free 124002K/139172K, paused 32ms, total 32ms 07-13 11:57:16.716 11792-11792/com.dealmaar.customer I/Choreographer: Skipped 39 frames! 07-13 11:57:16.172 11792-12002 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了4252K,释放了14%119709K / 139172K,暂停了31ms,总计32ms 07-13 11:57:16.180 11792-12002 / com .dealmaar.customer I / dalvikvm-heap:将堆(frag case)增加到120.779MB以分配4000012字节分配07-13 11:57:16.456 11792-12003 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC已释放5K,12 %免费123609K / 139172K,暂停263ms,总计263ms 07-13 11:57:16.680 11792-12003 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC已释放3730K,14%免费120100K / 139172K,暂停170ms,总170ms 07- 13 11:57:16.680 11792-12003 / com.dealmaar.customer I / dalvikvm-heap:将堆(frag情况)增加到121.161MB以实现4000012字节分配07-13 11:57:16.712 11792-12002 / com.dealmaar .customer D / dalvikvm:GC_FOR_ALLOC释放了4K,11%释放了124002K / 139172K,暂停了32ms,总计32ms 07-13 11:57:16.716 11792-11792 / com.dealmaar.customer I / Choreographer:跳过了39帧! The application may be doing too much work on its main thread. 该应用程序可能在其主线程上做太多工作。 07-13 11:57:16.724 11792-11792/com.dealmaar.customer V/...: Last Item Wow ! 07-13 11:57:16.724 11792-11792 / com.dealmaar.customer V / ...:Last Item哇! 07-13 11:57:17.032 11792-12001/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 269K, 11% free 124134K/139172K, paused 257ms, total 257ms 07-13 11:57:17.068 11792-12001/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 125.100MB for 4000012-byte allocation 07-13 11:57:17.104 11792-11818/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 44K, 11% free 127996K/143080K, paused 36ms, total 36ms 07-13 11:57:17.292 11792-12002/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 75K, 11% free 128064K/143080K, paused 179ms, total 179ms 07-13 11:57:17.292 11792-12002/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 128.938MB for 4000012-byte allocation 07-13 11:57:17.324 11792-12003/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 1K, 11% free 131969K/146988K, paused 31ms, total 31ms 07-13 11:57:17.348 11792-12003/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed <1K, 11% free 131969K/146988K, paused 22ms, total 22ms 07-13 11:57:17.352 11792-12003/com. 07-13 11:57:17.032 11792-12001 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放269K,释放11%释放124134K / 139172K,暂停257ms,总计257ms 07-13 11:57:17.068 11792-12001 / com .dealmaar.customer I / dalvikvm-heap:将堆(frag case)增加到125.100MB以分配4000012字节的分配07-13 11:57:17.104 11792-11818 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC已释放44K,11空闲百分比127996K / 143080K,暂停36ms,总计36ms 07-13 11:57:17.292 11792-12002 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放75K,11%免费128064K / 143080K,暂停179ms,总计179ms 07- 13 11:57:17.292 11792-12002 / com.dealmaar.customer I / dalvikvm-heap:将堆(frag情况)增加到128.938MB,以实现4000012字节分配07-13 11:57:17.324 11792-12003 / com.dealmaar .customer D / dalvikvm:已释放1K的GC_FOR_ALLOC,释放了11%的131969K / 146988K,已暂停31ms,总计31ms 07-13 11:57:17.348 11792-12003 / com.dealmaar.customer D / dalvikvm:已释放的GC_FOR_ALLOC <1K,11%免费131969K / 146988K,暂停22ms,总计22ms 07-13 11:57:17.352 11792-12003 / com。 dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 132.752MB for 4000012-byte allocation 07-13 11:57:17.384 11792-12001/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 0K, 10% free 135876K/150896K, paused 32ms, total 32ms 07-13 11:57:17.384 11792-11792/com.dealmaar.customer I/Choreographer: Skipped 33 frames! dealmaar.customer I / dalvikvm-heap:将堆(frag case)增加到132.752MB以分配4000012字节分配07-13 11:57:17.384 11792-12001 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了0K,10%免费135876K / 150896K,暂停32毫秒,总计32毫秒07-13 11:57:17.384 11792-11792 / com.dealmaar.customer I / Choreographer:已跳过33帧! The application may be doing too much work on its main thread. 该应用程序可能在其主线程上做太多工作。 07-13 11:57:17.384 11792-11792/com.dealmaar.customer V/...: Last Item Wow ! 07-13 11:57:17.384 11792-11792 / com.dealmaar.customer V / ...:Last Item哇! 07-13 11:57:17.420 11792-12017/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 133K, 10% free 135855K/150896K, paused 26ms, total 29ms 07-13 11:57:17.460 11792-12017/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 136.546MB for 4000012-byte allocation 07-13 11:57:17.736 11792-12003/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 5K, 10% free 139756K/154804K, paused 275ms, total 275ms 07-13 11:57:17.980 11792-12002/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 16073K, 20% free 124155K/154804K, paused 168ms, total 168ms 07-13 11:57:17.980 11792-12002/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 125.121MB for 4000012-byte allocation 07-13 11:57:18.012 11792-12001/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 48K, 18% free 128012K/154804K, paused 30ms, total 30ms 07-13 11:57:18.032 11792-12001/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 32K, 18% free 128044K/154804K, paused 18ms, total 18ms 07-13 11:57:18.032 11792-12001/c 07-13 11:57:17.420 11792-12017 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了133K,10%释放了135855K / 150896K,暂停了26ms,总计29ms 07-13 11:57:17.460 11792-12017 / com .dealmaar.customer I / dalvikvm-heap:将堆(frag case)增加到136.546MB以分配4000012字节的分配07-13 11:57:17.736 11792-12003 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC已释放5K,10空闲百分比139756K / 154804K,暂停275ms,总计275ms 07-13 11:57:17.980 11792-12002 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了16073K,20%空闲124155K / 154804K,暂停168ms,总计168ms 07- 13 11:57:17.980 11792-12002 / com.dealmaar.customer I / dalvikvm-heap:将堆(frag情况)增加到125.121MB以实现4000012字节分配07-13 11:57:18.012 11792-12001 / com.dealmaar .customer D / dalvikvm:释放了48K的GC_FOR_ALLOC,释放了18%的128012K / 154804K,暂停了30ms,总计30ms 07-13 11:57:18.032 11792-12001 / com.dealmaar.customer D / dalvikvm:释放了GC_FOR_ALLOC的32K,释放了18% 128044K / 154804K,暂停18ms,总计18ms 07-13 11:57:18.032 11792-12001 / c om.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 128.918MB for 4000012-byte allocation 07-13 11:57:18.064 11792-12017/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 0K, 15% free 131950K/154804K, paused 30ms, total 30ms 07-13 11:57:18.084 11792-12017/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 32K, 15% free 131982K/154804K, paused 19ms, total 19ms 07-13 11:57:18.084 11792-12017/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 132.765MB for 4000012-byte allocation 07-13 11:57:18.104 11792-11818/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 0K, 13% free 135889K/154804K, paused 20ms, total 20ms 07-13 11:57:18.108 11792-11792/com.dealmaar.customer I/Choreographer: Skipped 42 frames! om.dealmaar.customer I / dalvikvm-heap:将堆(片段大小写)增加到128.918MB,以分配4000012字节的分配07-13 11:57:18.064 11792-12017 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了0K, 15%空闲131950K / 154804K,暂停30ms,总计30ms 07-13 11:57:18.084 11792-12017 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了32K,15%免费131982K / 154804K,暂停19ms,总计19ms 07 -13 11:57:18.084 11792-12017 / com.dealmaar.customer I / dalvikvm-heap:将堆(frag情况)增加到132.765MB,以便4000012字节分配07-13 11:57:18.104 11792-11818 / com。 dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放了0K,释放了13%135889K / 154804K,已暂停20ms,总计20ms 07-13 11:57:18.108 11792-11792 / com.dealmaar.customer I / Choreographer:跳过了42帧! The application may be doing too much work on its main thread. 该应用程序可能在其主线程上做太多工作。 07-13 11:57:18.136 11792-12003/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 125K, 13% free 135840K/154804K, paused 26ms, total 27ms 07-13 11:57:18.140 11792-12003/com.dealmaar.customer I/dalvikvm-heap: Grow heap (frag case) to 136.532MB for 4000012-byte allocation 07-13 11:57:18.168 11792-11999/com.dealmaar.customer D/dalvikvm: GC_FOR_ALLOC freed 2K, 10% free 139744K/154804K, paused 29ms, total 29ms 07-13 11:57:19.216 11792-11792/com.dealmaar.customer I/Choreographer: Skipped 32 frames! 07-13 11:57:18.136 11792-12003 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC释放125K,释放13%135840K / 154804K,暂停26ms,总计27ms 07-13 11:57:18.140 11792-12003 / com .dealmaar.customer I / dalvikvm-heap:将堆(frag case)增加到136.532MB以分配4000012字节分配07-13 11:57:18.168 11792-11999 / com.dealmaar.customer D / dalvikvm:GC_FOR_ALLOC已释放2K,10空闲百分比139744K / 154804K,已暂停29毫秒,总计29毫秒07-13 11:57:19.216 11792-11792 / com.dealmaar.customer I / Choreographer:已跳过32帧! The application may be doing too much work on its main thread. 该应用程序可能在其主线程上做太多工作。 07-13 11:57:19.800 11792-11792/com.dealmaar.customer I/Choreographer: Skipped 34 frames! 07-13 11:57:19.800 11792-11792 / com.dealmaar.customer I / Choreographer:跳过了34帧! The application may be doing too much work on its main thread. 该应用程序可能在其主线程上做太多工作。

You are doing too much work in the main thread. 您在主线程中做的工作太多。 System is way passed it's limit and to execute your process it takes a significant amount of resources and it freezes the main UI thread leads to ANR error. 系统已超出极限,要执行您的过程,它会占用大量资源,并且冻结主UI线程会导致ANR错误。 I recommend you to do all the API calls and JSON parsing in the in the background thread by using AsyncTask . 我建议您使用AsyncTask在后台线程中进行所有API调用和JSON解析。

You have Out Of Memory Exception. 您有内存不足异常。 In some devices, when you pass the max heap, it won't show any log and the JVM just terminate your application. 在某些设备中,当您传递最大堆时,它将不显示任何日志,并且JVM仅终止您的应用程序。 When you scroll slowly, you let the JVM to complete its garbage collection process, But when you scroll fast, it doesn't have enough time to complete its task and you will pass the max heap. 缓慢滚动时,让JVM完成其垃圾回收过程,但是快速滚动时,它没有足够的时间来完成其任务,因此您将传递max堆。 I see you hold a reference to a list of views and ImageViews. 我看到您持有对视图和ImageViews列表的引用。

try {
        for (int i = 0; i < Sports.size(); ++i) {
            trendinglinear[i].setVisibility(View.VISIBLE);
            tname[i].setText(Sports.get(i).getProduct_name());
            tprice[i].setText(Sports.get(i).getProduct_price());
            ((View) tname[i].getParent()).setTag(Sports.get(i).getProduct_id());
            String[] simg = new String[25];
            simg[i] = Sports.get(i).getProduct_image();
            //Log.e("image", simg[i]);
            Picasso.with(getApplicationContext()).load(simg[i]).error(R.drawable.ic_launcher).resize(400, 400).into(timage[i]);

        }
    } catch (Exception e) {
        //Toast.makeText(HomeActivity.this, "Failed to connect to internet Try again !", Toast.LENGTH_SHORT).show();

    }

It may be one of the reasons that why your heap is reaching the max size. 这可能是您的堆达到最大大小的原因之一。

App is being crashed for memory management failure , here every item is assigned animation , and applied animation is not cleared.I have solved your problem spending 1 day, it's worked for me. 应用程式因记忆体管理失败而当机,这里为每个项目指派了动画,并且未清除应用的动画。我花了1天的时间解决了您的问题,对我来说很有效。

@Override public void onViewDetachedFromWindow(ViewHolder holder) { 
super.onViewDetachedFromWindow(holder);
 ((ViewHolder)holder).clearAnimation();
 } 

In my ViewHolder added method: 在我的ViewHolder中添加的方法:

public void clearAnimation() { 
itemView.clearAnimation(); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM