DraggableTreeView not working in Fragment
Hardik051099 opened this issue · 1 comments
I am getting this NullPointerException error
2020-05-14 12:42:28.778 12251-12251/com.app.hardik.studypdf E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.hardik.studypdf, PID: 12251
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.addView(android.view.View)' on a null object reference
at com.allyants.draggabletreeview.DraggableTreeView.createTreeItem(DraggableTreeView.java:369)
at com.allyants.draggabletreeview.DraggableTreeView.inflateViews(DraggableTreeView.java:83)
at com.allyants.draggabletreeview.DraggableTreeView.inflateViews(DraggableTreeView.java:89)
at com.allyants.draggabletreeview.DraggableTreeView.notifyDataSetChanged(DraggableTreeView.java:77)
at com.allyants.draggabletreeview.DraggableTreeView.setAdapter(DraggableTreeView.java:70)
at com.app.hardik.studypdf.ListFragment.onCreateView(ListFragment.kt:72)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Rather simple to solved:
- In demo fragment, use this as the first node: TreeNode root = new TreeNode(MainActivity.mainActivity);
Or something similar to get the context from.