当我第二次按下按钮时,该应用程序停止工作

时间:2020-02-09 21:58:02

标签: java android android-studio authentication button

我正在开发一个由login-register app组成的应用程序。在我的登录活动中,我有2个按钮:LOGIN和REGISTER。Register按钮用于将您从登录活动重定向到register活动。该应用程序正常运行,直到我再次按下。该应用程序停止运行。

import sys

started = False
carstate = ""

while carstate != "exit":
    carstate = input()  # asking for input each iteration.

    if carstate == "start":
        if started == False:
            started = True  # we're setting it, not comparing it.
            print("Car has started... ready to go!")

        elif started == True:  # remember the elif
            print("Car has already started")

    elif carstate == "stop":
        if started == False:
            print("Car is already stopped!")

        elif started == True:
            started = False
            print("Car is stopped")

    if carstate == "help":
        print("Start - starts the car")
        print("Stop - stops the car")
        print("Exit - exits the game")

if carstate == "exit":
    sys.exit()

2 个答案:

答案 0 :(得分:0)

尝试从Login.This更改为getApplicationContext()

public void onClick (View v){
   Intent launchactivity = new Intent (getApplicationContext(),Register.class);
   startActivity (launchactivity);
});

答案 1 :(得分:0)

删除您的登录名。这并添加getApplicationContext()