问题登录/ regstration [英] Issues With login/regstration

查看:129
本文介绍了问题登录/ regstration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*更新*巡航能力仍,如果你看到任何错误,请让我知道,我想将我的logcat的,但我不能访问它由于错误问题,请.......我在遇到问题我的登录和注册机制。我可能做错事,但是当我试图测试出登录我的应用程序崩溃的消息......却突然停了下来。味精。另外,我的TextView那去我的注册类心不是响应。可有的请帮助我吗?

我知道有可能是一个很大的错误,但善待我是新来这个:) 如果有人大方,或只是无聊,想亲自帮我出的问题,请留下您的电子邮件

下面是code为我登录类:

  @覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    //设置默认的屏幕login.xml

    的setContentView(R.layout.login);

    TextView的registerScreen =(TextView中)findViewById(R.id.link_to_register);

    //听来注册新帐号链接
    registerScreen.setOnClickListener(新View.OnClickListener(){

        公共无效的onClick(视图v){
            //切换到注册屏

            意图I =新的意图(getApplicationContext(),SignUp.class);
            startActivity(ⅰ);




    //创建SQLite数据库的实例
    loginDataBaseAdapter =新LoginDataBaseAdapter(本);
    loginDataBaseAdapter = loginDataBaseAdapter.open();

    //获取按钮的参考
    btnSignIn =(按钮)findViewById(R.id.btnLogin);


    }
//方法登录到handleClick事件在按钮
公共无效签到(查看V){
    尝试{
    最后一个对话框对话框=新的对话框(LoginScreen.this);
    dialog.setContentView(R.layout.login);
    dialog.setTitle(登录);

    //获取视图中的引用
    最后的EditText loginUsername =(EditText上)对话
            .findViewById(R.id.liUsername);
    最后的EditText loginPassword =(EditText上)对话
            .findViewById(R.id.liPassword);

    按钮btnSignIn =(按钮)dialog.findViewById(R.id.btnLogin);
    }赶上(例外五){
           Log.e(标签,e.getMessage());
        }
    //设置在ClickListener
    btnSignIn.setOnClickListener(新View.OnClickListener(){


        公共无效的onClick(视图v){
            //获取用户名和密码

            字符串username = loginUsername.getText()的toString()。
            。字符串password = loginPassword.getText()的toString();

            //获取密码表单数据库中相应的用户名
            字符串storedPassword = loginDataBaseAdapter
                    .getSingleEntry(用户名);

            //检查存储的口令与密码一致通过​​进入
            // 用户
            如果(password.equals(storedPassword)){
                Toast.makeText(LoginScreen.this,
                        恭喜:登录成功,Toast.LENGTH_LONG)
                        。显示();
                dialog.dismiss();


            } 其他 {
                Toast.makeText(LoginScreen.this,
                        用户名或密码不匹配,
                        Toast.LENGTH_LONG).show();

    dialog.show();
            }
}

@覆盖
公共无效startActivity(意向意图){
    // TODO自动生成方法存根
    尝试{
    super.startActivity(意向);
    意图炫魅=新的意图(LoginScreen.this,MainPage.class);
    startActivity(炫魅);
    完();
    }赶上(例外五){
           Log.e(标签,e.getMessage());
        }


    }


@覆盖
保护无效的onDestroy(){
    尝试{
        super.onDestroy();
    //关闭数据库
    loginDataBaseAdapter.close();

    }赶上(例外五){
           Log.e(的onDestroy  - 错误,e.getMessage());
    }
 

我的注册类

  @覆盖
保护无效的onCreate(包savedInstanceState){


    super.onCreate(savedInstanceState);
    //设置查看到register.xml
    的setContentView(R.layout.signup);

    TextView的loginScreen =(TextView中)findViewById(R.id.link_to_login);
    //听着登录屏幕链接
    loginScreen.setOnClickListener(新View.OnClickListener(){

        公共无效的onClick(查看为arg0){
                            //截止登记画面
            //切换到登录屏幕/关闭登记画面
            完();

    //获取数据库接口的实例
    loginDataBaseAdapter =新LoginDataBaseAdapter(本);
    loginDataBaseAdapter = loginDataBaseAdapter.open();

    //获取意见的参考
    reg_fullname =(EditText上)findViewById(R.id.reg_fullname);
    reg_username =(EditText上)findViewById(R.id.reg_username);
    reg_email =(EditText上)findViewById(R.id.reg_email);
    reg_password =(EditText上)findViewById(R.id.reg_password);
    reg_confirmpassword =(EditText上)findViewById(R.id.reg_confirmpassword);

    btnRegister =(按钮)findViewById(R.id.btnRegister);

    btnRegister.setOnClickListener(新View.OnClickListener(){

        公共无效的onClick(视图v){
            // TODO自动生成方法存根

            。字符串全称= reg_fullname.getText()的toString();
            字符串username = reg_username.getText()的toString()。
            。字符串password = reg_password.getText()的toString();
            。字符串email = reg_email.getText()的toString();
            字符串confirmPassword = reg_confirmpassword.getText()
                    的ToString();

            //检查是否任何字段都是空
            如果(username.equals()|| password.equals()
                    || confirmPassword.equals()){
                Toast.makeText(getApplicationContext(),现场Vaccant
                        Toast.LENGTH_LONG).show();
                返回;
            }
            //检查,如果这两个密码相匹配
            如果(!password.equals(confirmPassword)){
                Toast.makeText(getApplicationContext(),
                        密码不匹配,Toast.LENGTH_LONG)
                        。显示();
                返回;
            } 其他 {
                //将数据保存到数据库
                loginDataBaseAdapter.insertEntry(用户名,密码);
                Toast.makeText(getApplicationContext(),
                        账户成功塑造了,Toast.LENGTH_LONG)
                        。显示();
            }

        }

@覆盖
保护无效的onDestroy(){
// TODO自动生成方法存根
    尝试{
        super.onDestroy();
    loginDataBaseAdapter.close();
    }赶上(例外五){
           Log.e(的onDestroy  - 错误,e.getMessage());
    }}
 

解决方案

要知道你的code错误,这是最好的办法,把所有的code块中的try-catch中的所有功能。。

 尝试{
   //你的code在这里
}赶上(例外五){
   Log.e(标签,e.getMessage());
}
 

在logcat中会以红色apears你的code中的错误,标签这是一个方法来区分的误差修改如下:

  @覆盖
保护无效的onDestroy(){
    尝试{
       super.onDestroy();
       loginDataBaseAdapter.close();
    }赶上(例外五){
       Log.e(的onDestroy  - 错误,e.getMessage());
    }

}
 

我希望这可以帮助...

*UPDATED*still haveing issues please if you see any errors please let me know, i would like to put my logcat in but i cant access it due to the errors .......I'm having issues with my login and registration mechanism. I'm probably doing something wrong, but when i try to test out the login my app crashes with the message "...has suddenly stopped." msg. Also, my textview that goes to my registration class isnt responding. Can some please help me?

I know there is probably a lot of errors, but be kind I'm new to this :) If anyone is generous or just bored and wanted to personally help me out with issues please leave your email

Below is the code for my login class:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setting default screen to login.xml

    setContentView(R.layout.login);

    TextView registerScreen = (TextView) findViewById(R.id.link_to_register);

    // Listening to register new account link
    registerScreen.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // Switching to Register screen

            Intent i = new Intent(getApplicationContext(), SignUp.class);
            startActivity(i);




    // create a instance of SQLite Database
    loginDataBaseAdapter = new LoginDataBaseAdapter(this);
    loginDataBaseAdapter = loginDataBaseAdapter.open();

    // Get The Reference Of Buttons
    btnSignIn = (Button) findViewById(R.id.btnLogin);


    }
// Methods to handleClick Event of Sign In Button
public void signIn(View V) {
    try{
    final Dialog dialog = new Dialog(LoginScreen.this);
    dialog.setContentView(R.layout.login);
    dialog.setTitle("Login");

    // get the References of views
    final EditText loginUsername = (EditText) dialog
            .findViewById(R.id.liUsername);
    final EditText loginPassword = (EditText) dialog
            .findViewById(R.id.liPassword);

    Button btnSignIn = (Button) dialog.findViewById(R.id.btnLogin);
    }catch(Exception e){
           Log.e("tag", e.getMessage());
        }
    // Set On ClickListener
    btnSignIn.setOnClickListener(new View.OnClickListener() {


        public void onClick(View v) {
            // get The User name and Password

            String username = loginUsername.getText().toString();
            String password = loginPassword.getText().toString();

            // fetch the Password form database for respective user name
            String storedPassword = loginDataBaseAdapter
                    .getSingleEntry(username);

            // check if the Stored password matches with Password entered by
            // user
            if (password.equals(storedPassword)) {
                Toast.makeText(LoginScreen.this,
                        "Congrats: Login Successful", Toast.LENGTH_LONG)
                        .show();
                dialog.dismiss();


            } else {
                Toast.makeText(LoginScreen.this,
                        "User Name or Password does not match",
                        Toast.LENGTH_LONG).show();

    dialog.show();
            }       
}

@Override
public void startActivity(Intent intent) {
    // TODO Auto-generated method stub
    try{
    super.startActivity(intent);
    Intent mainpage = new Intent(LoginScreen.this, MainPage.class);
    startActivity(mainpage);
    finish();
    }catch(Exception e){
           Log.e("tag", e.getMessage());
        }


    }


@Override
protected void onDestroy() {
    try{
        super.onDestroy();
    // Close The Database
    loginDataBaseAdapter.close();

    }catch(Exception e){
           Log.e("onDestroy - Error", e.getMessage());
    }   

MY registration class

@Override
protected void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    // Set View to register.xml
    setContentView(R.layout.signup);

    TextView loginScreen = (TextView) findViewById(R.id.link_to_login);
    // Listening to Login Screen link
    loginScreen.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
                            // Closing registration screen
            // Switching to Login Screen/closing register screen
            finish();

    // get Instance of Database Adapter
    loginDataBaseAdapter = new LoginDataBaseAdapter(this);
    loginDataBaseAdapter = loginDataBaseAdapter.open();

    // Get References of Views
    reg_fullname = (EditText) findViewById(R.id.reg_fullname);
    reg_username = (EditText) findViewById(R.id.reg_username);
    reg_email = (EditText) findViewById(R.id.reg_email);
    reg_password = (EditText) findViewById(R.id.reg_password);
    reg_confirmpassword = (EditText) findViewById(R.id.reg_confirmpassword);

    btnRegister = (Button) findViewById(R.id.btnRegister);

    btnRegister.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            String fullname = reg_fullname.getText().toString();
            String username = reg_username.getText().toString();
            String password = reg_password.getText().toString();
            String email = reg_email.getText().toString();
            String confirmPassword = reg_confirmpassword.getText()
                    .toString();

            // check if any of the fields are vacant
            if (username.equals("") || password.equals("")
                    || confirmPassword.equals("")) {
                Toast.makeText(getApplicationContext(), "Field Vaccant",
                        Toast.LENGTH_LONG).show();
                return;
            }
            // check if both password matches
            if (!password.equals(confirmPassword)) {
                Toast.makeText(getApplicationContext(),
                        "Password does not match", Toast.LENGTH_LONG)
                        .show();
                return;
            } else {
                // Save the Data in Database
                loginDataBaseAdapter.insertEntry(username, password);
                Toast.makeText(getApplicationContext(),
                        "Account Successfully Created ", Toast.LENGTH_LONG)
                        .show();
            }

        }

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
    try{
        super.onDestroy();
    loginDataBaseAdapter.close();
    }catch(Exception e){
           Log.e("onDestroy - Error", e.getMessage());
    }}

解决方案

The best way to know your code errors it's, put all your code in a block try-catch in all functions..

try{
   //your code here
}catch(Exception e){
   Log.e("tag", e.getMessage());
}

in Logcat will be apears in red color the errors of your code, "tag" it's a way to differentiate the erros like:

@Override
protected void onDestroy() {
    try{
       super.onDestroy();
       loginDataBaseAdapter.close();
    }catch(Exception e){
       Log.e("onDestroy - Error", e.getMessage());
    }

} 

I hope this helps...

这篇关于问题登录/ regstration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆