单击按钮时应用程序关闭

时间:2017-12-17 07:19:10

标签: java android

我已经在android项目中编写了这个代码来打开一个新视图但是无论何时单击该按钮,应用程序都会停止工作但在调试器控制台上不会返回任何错误。除了说应用程序关闭的日志

这是我的代码

public class LoginActivity extends Activity{
    private Button btnLinkToRegister;
    btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);  

     // Link to Register Screen
    btnLinkToRegister.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(),
                    RegisterActivity.class);
            startActivity(i);
            finish();
        }
    });
}

我已删除其他代码,以便轻松识别问题

这是log cat

    12-17 10:16:08.525 4039-4039/? I/zygote: Not late-enabling -Xcheck:jni (already on)
    12-17 10:16:08.541 4039-4039/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
    12-17 10:16:08.726 4039-4039/com.otemainc.smartmenu I/InstantRun: starting instant run server: is main process
    12-17 10:16:08.878 4039-4039/com.otemainc.smartmenu I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
   12-17 10:16:08.952 4039-4062/com.otemainc.smartmenu D/OpenGLRenderer: HWUI GL Pipeline
   12-17 10:16:09.015 4039-4062/com.otemainc.smartmenu I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
   12-17 10:16:09.015 4039-4062/com.otemainc.smartmenu I/OpenGLRenderer: Initialized EGL, version 1.4
    12-17 10:16:09.015 4039-4062/com.otemainc.smartmenu D/OpenGLRenderer: Swap behavior 1
    12-17 10:16:09.019 4039-4062/com.otemainc.smartmenu D/EGL_emulation: eglCreateContext: 0x8a6bf440: maj 2 min 0 rcv 2
    12-17 10:16:09.029 4039-4062/com.otemainc.smartmenu D/EGL_emulation: eglMakeCurrent: 0x8a6bf440: ver 2 0 (tinfo 0xa53f3cc0)
    12-17 10:16:09.053 4039-4062/com.otemainc.smartmenu D/EGL_emulation: eglMakeCurrent: 0x8a6bf440: ver 2 0 (tinfo 0xa53f3cc0)
    12-17 10:16:09.398 4039-4039/com.otemainc.smartmenu I/AssistStructure: Flattened final assist data: 2788 bytes, containing 1 windows, 9 views
    12-17 10:16:10.708 4039-4044/com.otemainc.smartmenu I/zygote: Do partial code cache collection, code=28KB, data=26KB
    12-17 10:16:10.709 4039-4044/com.otemainc.smartmenu I/zygote: After code cache collection, code=28KB, data=26KB
    12-17 10:16:10.709 4039-4044/com.otemainc.smartmenu I/zygote: Increasing code cache capacity to 128KB
    12-17 10:16:38.461 4039-4044/com.otemainc.smartmenu I/zygote: Do partial code cache collection, code=48KB, data=49KB
    12-17 10:16:38.461 4039-4044/com.otemainc.smartmenu I/zygote: After code cache collection, code=48KB, data=49KB
    12-17 10:16:38.461 4039-4044/com.otemainc.smartmenu I/zygote: Increasing code cache capacity to 256KB
    12-17 10:18:00.261 4039-4044/com.otemainc.smartmenu I/zygote: Do full code cache collection, code=121KB, data=99KB
    12-17 10:18:00.262 4039-4044/com.otemainc.smartmenu I/zygote: After code cache collection, code=97KB, data=69KB
    12-17 10:20:06.115 4039-4044/com.otemainc.smartmenu I/zygote: Do partial code cache collection, code=121KB, data=85KB
    12-17 10:20:06.115 4039-4044/com.otemainc.smartmenu I/zygote: After code cache collection, code=121KB, data=85KB
    12-17 10:20:06.115 4039-4044/com.otemainc.smartmenu I/zygote: Increasing code cache capacity to 512KB

1 个答案:

答案 0 :(得分:2)

尝试在onClick方法中使用它:

__clrcall

还在Maniffest文件中添加RegisterActivity。