我的导航抽屉中片段中的按钮不起作用。应用程序崩溃

时间:2019-07-14 18:43:03

标签: android android-fragments nullpointerexception navigation-drawer

我的导航抽屉中片段中的按钮不起作用。该应用程序崩溃。

我认为与图书馆有关的问题 导入androidx.fragment.app.Fragment;

我的项目的github链接 https://github.com/prensmiskin/DoctorSix

当我单击片段中的按钮时,我希望它能正常工作。

2019-07-14 19:53:18.446 12619-12619/? E/alsix.doctorsi: Unknown bits set in runtime_flags: 0x8000
2019-07-14 19:53:19.136 12619-12682/com.medicalsix.doctorsix E/vndksupport: Could not load /vendor/lib/egl/libGLES_emulation.so from sphal namespace: dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found.
2019-07-14 19:53:19.136 12619-12682/com.medicalsix.doctorsix E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): unknown
2019-07-14 19:53:19.696 12619-12681/com.medicalsix.doctorsix E/EGL_emulation: tid 12681: eglQueryString(923): error 0x3008 (EGL_BAD_DISPLAY)
2019-07-14 19:53:22.100 12619-12619/com.medicalsix.doctorsix E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.medicalsix.doctorsix, PID: 12619
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
        at com.medicalsix.doctorsix.First.onCreateView(First.java:40)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7116)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)

您可以通过单击github链接来查看我的项目的详细信息。

1 个答案:

答案 0 :(得分:0)

您必须像下面那样更改代码库:

    View view = inflater.inflate(R.layout.fragment_first, container, false);
    button = view.findViewById(R.id.button);
    text = view.findViewById(R.id.text);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
    return view;