今天寫登錄註冊頁面,點擊登錄頁面的“註冊”按鈕後軟體突然崩潰,直接閃退,因為是新手,只能去網上搜。雖然網上解決方法眾多,但也沒找到可行的。想起來可以看Logcat,馬上重新運行應用,查看崩潰時的日誌,發現日誌比較多,還都不認識,只好又複製日誌上網搜索,無果。突發奇想,把註冊頁面有關Toolbar的內 ...
今天寫登錄註冊頁面,點擊登錄頁面的“註冊”按鈕後軟體突然崩潰,直接閃退,因為是新手,只能去網上搜。雖然網上解決方法眾多,但也沒找到可行的。想起來可以看Logcat,馬上重新運行應用,查看崩潰時的日誌,發現日誌比較多,還都不認識,只好又複製日誌上網搜索,無果。突發奇想,把註冊頁面有關Toolbar的內容刪掉,重新運行應用,竟然成功從登錄頁面切換到註冊頁面。可能是註冊頁面的Toolbar和登錄頁面衝突了,具體原因未明,只能先不用這個Toolbar了。
Logcat
11-17 08:36:20.241 2389-2389/? E/libprocessgroup: failed to make and chown /acct/uid_10066: Read-only file system
11-17 08:36:20.241 2389-2389/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
11-17 08:36:20.241 2389-2389/? I/art: Late-enabling -Xcheck:jni
11-17 08:36:20.346 2389-2389/com.example.zz.ebuy W/System: ClassLoader referenced unknown path: /data/app/com.example.zz.ebuy-1/lib/x86
11-17 08:36:20.375 2389-2389/com.example.zz.ebuy W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-17 08:36:20.454 2389-2402/com.example.zz.ebuy D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ 11-17 08:36:20.494 2389: 2389 D/ ]
HostConnection::get() New Host Connection established 0xed656860, tid 2389
11-17 08:36:21.046 2389-2402/com.example.zz.ebuy D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
11-17 08:36:21.047 2389-2402/com.example.zz.ebuy D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
11-17 08:36:21.066 2389-2402/com.example.zz.ebuy D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
[ 11-17 08:36:21.089 2389: 2402 D/ ]
HostConnection::get() New Host Connection established 0xeea12890, tid 2402
11-17 08:36:21.142 2389-2402/com.example.zz.ebuy I/OpenGLRenderer: Initialized EGL, version 1.4
11-17 08:36:21.384 2389-2402/com.example.zz.ebuy W/EGL_emulation: eglSurfaceAttrib not implemented
11-17 08:36:21.384 2389-2402/com.example.zz.ebuy W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xeea13560, error=EGL_SUCCESS
11-17 08:36:24.441 2389-2389/com.example.zz.ebuy D/AndroidRuntime: Shutting down VM
11-17 08:36:24.442 2389-2389/com.example.zz.ebuy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.zz.ebuy, PID: 2389
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.zz.ebuy/com.example.zz.ebuy.SignUp}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.Toolbar.setLogo(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.Toolbar.setLogo(int)' on a null object reference
at com.example.zz.ebuy.SignUp.onCreate(SignUp.java:33)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-17 08:36:28.615 2389-2389/com.example.zz.ebuy I/Process: Sending signal. PID: 2389 SIG: 9
Toolbar代碼
1 Toolbar toolbar = findViewById(R.id.toolbar); 2 setSupportActionBar(toolbar); 3 toolbar.setLogo(R.drawable.ebuy); 4 toolbar.setTitle("eBuy");