0

MainActivity entire code : https://pastebin.com/G6RDxKan

I am making coin market application.

Threads were worked well before, but when I changed some codes to change app design, thread exception occured.

I didn't change any thread code, so threads won't have problem.

My threads look like below.

@Override
    protected void onResume() {
        super.onResume();
        pref = getSharedPreferences("pref", MODE_PRIVATE);
        token = pref.getString("token", "");
        if (token.equals("")) {
            nv.getMenu().findItem(R.id.login).setVisible(true);
            nv.getMenu().findItem(R.id.dashboard).setVisible(false);
        } else {
            nv.getMenu().findItem(R.id.login).setVisible(false);
            nv.getMenu().findItem(R.id.dashboard).setVisible(true);
        }
        BithumbThread thread1 = new BithumbThread();
        UpbitThread thread2 = new UpbitThread();
        thread1.start();
        thread2.start();

        Log.d("/////////","OnResume End");
    }
class BithumbThread extends Thread {

        @Override
        public void run() {
            try {

                    Api_Client api = new Api_Client("" + bithumb_access,
                            "" + bithumb_secret);
                    HashMap<String, String> rgParams = new HashMap<String, String>();
                    rgParams.put("currency", "ALL");
                    .
                    .
                    .
                    String Asset = "Bithumb : " + balance;
                    tv_currentAsset.setText(Asset);


                }

                Log.d("/////////","Thread End");
            } catch (Exception e) {

                Log.d("/////////", "DataGetError");
            }
            try {
                Thread.sleep(1000);

            } catch (InterruptedException e) {
            }
        }
    }

    class UpbitThread extends Thread {

        @Override
        public void run() {
            try {




                String accessKey = (upbit_access);
                String secretKey = (upbit_secret);
                String serverUrl = ("https://api.upbit.com");


                Algorithm algorithm = Algorithm.HMAC256(secretKey);
                String jwtToken = JWT.create()
                        .withClaim("access_key", accessKey)
                        .withClaim("nonce", UUID.randomUUID().toString())
                        .sign(algorithm);

                .
                .
                .
                    String Asset2 = "Upbit : " + Double.toString(balance_total);
                    tv_currentAsset2.setText(Asset2);
                }



                Log.d("/////////","Thread End");
            } catch (Exception e) {

                Log.d("/////////", "DataGetError");
            }
            try {
                Thread.sleep(1000);

            } catch (InterruptedException e) {
            }
        }
    }

There's no null exception error when I put key, but there's thread exception and threads can't update coin information in recyclerview(main page of the app) though parsing data from json works well

I don't know which thing makes thread exception.

I've also tried debugging, but I can't find any errors.

I/Choreographer: Skipped 57 frames!  The application may be doing too much work on its main thread.

What I found is just this from the logcat.

Maybe some adapters makes problems.

How to fix not to occur thread exception and update recycler view?

JYHJYH
  • 11
  • 4

0 Answers0