Unable to understand this exception : <p>While calling notifydatasetchanged method from async task class in doinbackground method it is showing exception but when calling notifydatasetchanged method in onpostexecute it is working fine.</p>

<p>Code:</p>

<pre><code> protected String doInBackground(Void... voids) {


        String results = "";
        if (session != null) {

            Folder root = session.getRootFolder();
            ItemIterable&lt;CmisObject&gt; children = root.getChildren();

            int count = 0;
            map_id = new HashMap();
            map_name = new HashMap();
            for (CmisObject o : children) {
                Information current = new Information();
                current.iconId = icons;
                current.title = o.getName();
                current.folderId = o.getId();
                current.date="Modified: "+o.getLastModificationDate().get(o.getLastModificationDate().DATE)
                        +" "+returntext(+o.getLastModificationDate().get(o.getLastModificationDate().MONTH))+
                        " "+o.getLastModificationDate().get(o.getLastModificationDate().YEAR);
                map_id.put(count, current.folderId);
                map_name.put(count, current.title);
                count++;
                data_main.add(current);
                FilesFragment.adapter.notifyDataSetChanged();
            }

        }
        return results;
    }

    @Override
    protected void onPostExecute(String s) {

        pDialog.dismiss();
        FilesFragment.adapter.notifyDataSetChanged();

    }
</code></pre>

<p>Inside For loop calling                   FilesFragment.adapter.notifyDataSetChanged() and in recycler view adding data from list data_main.So what i was thing that if one data comes in my list i will call notifyDatasetchanged and further like this process will be repeated.</p>

<p>Error:</p>

<pre><code>04-02 16:43:14.001 20776-20804/reva.irving E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                                                         Process: reva.irving, PID: 20776
                                                         java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                             at android.os.AsyncTask$3.done(AsyncTask.java:325)
                                                             at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                             at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                             at java.lang.Thread.run(Thread.java:760)
                                                          Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
                                                             at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6958)
                                                             at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1085)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.support.constraint.ConstraintLayout.requestLayout(ConstraintLayout.java:1959)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.view.View.requestLayout(View.java:19807)
                                                             at android.support.v7.widget.RecyclerView.requestLayout(RecyclerView.java:3970)
                                                             at android.support.v7.widget.RecyclerView$RecyclerViewDataObserver.onChanged(RecyclerView.java:5060)
                                                             at android.support.v7.widget.RecyclerView$AdapterDataObservable.notifyChanged(RecyclerView.java:11540)
                                                             at android.support.v7.widget.RecyclerView$Adapter.notifyDataSetChanged(RecyclerView.java:6762)
                                                             at reva.irving.MainActivity$GetCabinets.doInBackground(MainActivity.java:158)
                                                             at reva.irving.MainActivity$GetCabinets.doInBackground(MainActivity.java:106)
                                                             at android.os.AsyncTask$2.call(AsyncTask.java:305)
                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                             at java.lang.Thread.run(Thread.java:760) 
</code></pre>
