0

I am trying to integrate quickblox chat into an existing app that has been working well and already in the play store.

I am trying to implement this using the sample-chat code https://github.com/QuickBlox/quickblox-android-sdk/tree/master/sample-chat.

the original app API targetSdkVersion was 27 , I had to change it 28 as I got an error that necessitate the change and also migrate the app to androidX.

so in the code block below, the loadUsersFromQb() loads users with a tag "SampleTag" from the server. If a chat dialog exists the dialog is updated with the loaded users otherwise a ListView of the users is suppose to be presented where users can then be selected to be added to a chat group.

The code

 private void loadUsersFromQb() {
        List<String> tags = new ArrayList<>();
        try {
            tags.add("SampleTag");
        }catch (Exception e)
        {
           // Toaster.shortToast(e.getMessage());
        }

        progressBar.setVisibility(View.VISIBLE);
        QBUsers.getUsersByTags(tags, null).performAsync(new QBEntityCallback<ArrayList<QBUser>>() {
            @Override
            public void onSuccess(ArrayList<QBUser> usersByTags, Bundle params) {
                users = usersByTags;
                Toast.makeText(SelectUsersActivity.this, users.toString(), Toast.LENGTH_SHORT).show();



                if (qbChatDialog != null) {
                    // update occupants list form server
                    getDialog();


                } else {
                    updateUsersAdapter();

                }
            }

            @Override
            public void onError(QBResponseException e) {
                Toast.makeText(SelectUsersActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                                     showErrorSnackbar(R.string.select_users_get_users_error, e,
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    loadUsersFromQb();
                                }
                            });
                    progressBar.setVisibility(View.GONE);

            }
        });
    }

however,

updateUsersAdapter() 

results in

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources com.gill.XXX.CoreApp.getResources()' on a null object reference

the updateUsersAdapter() block looks like this

private void updateUsersAdapter() {
        usersAdapter = new CheckboxUsersAdapter(this, users);
        if (qbChatDialog != null) {
            usersAdapter.addSelectedUsers(qbChatDialog.getOccupants());
        }
        usersListView.setAdapter(usersAdapter);
        progressBar.setVisibility(View.GONE);
    }

the usersListView was instantiated from the class fields like this

private ListView usersListView;

where ListView is an android API 28 widget.

The full Logcat of the exception is

2019-04-04 09:52:07.728 1200-1200/com.gill.XXX:error_activity E/CustomActivityOnCrash: The previous app process crashed. This is the stack trace of the crash:
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources com.gill.XXX.CoreApp.getResources()' on a null object reference
        at com.gill.XXX.utils.UiUtils.getCircleColor(UiUtils.java:67)
        at com.gill.XXX.utils.UiUtils.getColorCircleDrawable(UiUtils.java:40)
        at com.gill.XXX.adapter.UsersAdapter.getView(UsersAdapter.java:74)
        at com.gill.XXX.adapter.CheckboxUsersAdapter.getView(CheckboxUsersAdapter.java:41)
        at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
        at android.widget.AbsListView.obtainView(AbsListView.java:2365)
        at android.widget.ListView.makeAndAddView(ListView.java:2052)
        at android.widget.ListView.fillDown(ListView.java:786)
        at android.widget.ListView.fillFromTop(ListView.java:847)
        at android.widget.ListView.layoutChildren(ListView.java:1826)
        at android.widget.AbsListView.onLayout(AbsListView.java:2164)
        at android.view.View.layout(View.java:20321)
        at android.view.ViewGroup.layout(ViewGroup.java:6153)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
        at android.view.View.layout(View.java:20321)
        at android.view.ViewGroup.layout(ViewGroup.java:6153)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20321)
        at android.view.ViewGroup.layout(ViewGroup.java:6153)
        at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)
        at android.view.View.layout(View.java:20321)
        at android.view.ViewGroup.layout(ViewGroup.java:6153)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20321)
        at android.view.ViewGroup.layout(ViewGroup.java:6153)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
        at android.view.View.layout(View.java:20321)
        at android.view.ViewGroup.layout(ViewGroup.java:6153)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:763)
        at android.view.View.layout(View.java:20321)
        at android.view.ViewGroup.layout(ViewGroup.java:6153)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2609)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2314)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1450)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7023)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:924)
        at android.view.Choreographer.doCallbacks(Choreographer.java:732)
        at android.view.Choreographer.doFrame(Choreographer.java:664)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:910)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)

The app crash on this method call. I have done a lot of search here on stackoverflow for similar question but I couldn't solve the problem still.

There is equally a suggestion somewhere https://issuetracker.google.com/issues/120750246 that might be because I am testing the app on a device with API level less than 28. as ClassNotFoundException also show up in the Logcat.

I have been on this for days, any help will be appreciated.

kplus
  • 694
  • 8
  • 31
  • @nilesh-rathod I doubt if you read my question properly before marking this a duplicate. – kplus Apr 04 '19 at 12:33
  • It turns out that I forgot to implement the global glass used in the sample chat code in my own global class used in the application manifest – kplus Apr 04 '19 at 14:16

0 Answers0