有创建一个Android登录页面与意图和放大器的麻烦;活动放大器、创建一个、意图、麻烦

2023-09-12 06:06:14 作者:抢了我辣条还想跑

我想创建为Android通用的登录界面。我想程序来检查用户名和密码(目前很难codeD)上市。如果该帐户已列出,你会被带到一个被称为新的屏幕 menuTest 。我有基本的登录工作(不活动或意图)。但是,当我尝试添加的意图,我得到一个错误。我该如何解决这个问题?下面是我的示例code。

下面是包含大跌的logcat(修改:链接是死的)的截图几个环节。

http://i.stack.imgur.com/ve7OL.png

http://i.stack.imgur.com/KLeQa.png

感谢。

 进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.TextView;

公共类登录扩展活动{
    //声明我们的观点,所以我们以后可以访问它们
    私人的EditText etUsername;
    私人的EditText etPassword;
    私人按钮btnLogin;
    私人按钮btnCancel;
    私人TextView的lblResult;

/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);

    //设置活动布局
    的setContentView(R.layout.login);

    //获取的EditText和Button参考
    etUsername =(EditText上)findViewById(R.id.username);
    etPassword =(EditText上)findViewById(R.id.password);
    btnLogin =(按钮)findViewById(R.id.login_enter);
    btnCancel =(按钮)findViewById(R.id.login_cancel);
    lblResult =(TextView中)findViewById(R.id.result);

    //设置点击监听器
    btnLogin.setOnClickListener(新OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            //检查登录
            字符串username = etUsername.getText()的toString()。
            。字符串password = etPassword.getText()的toString();

            如果(username.equalsIgnoreCase(用户)及&安培; password.equals(132465)){
                //lblResult.setText("Login成功);
                意图loginIntent =新的意图(这一点,menuTest.class);
                startActivity(loginIntent);
            }

            其他 {
                lblResult.setText(登录失败);
            }
        }
    });


    btnCancel.setOnClickListener(新OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            //关闭应用程序
            完();
        }
    });
}
}
 

解决方案

请尝试更改意图loginIntent =新的意图(这一点,menuTest.class); 意图loginIntent =新的意图(Login.this,menuTest.class);

I'm trying to create a generic login screen for Android. I'd like the program to check if the username and password (currently hardcoded) is listed. If the account is listed, you will be taken to a new screen called menuTest. I have the basic login working (without activity or intents). But when I try to add the intents, I get an error. How can I fix this? Below is my sample code.

记录学习Android基础的心得03 活动activity和意图intent

Below are a few links containing screenshots of crash and logcat (edit: links are dead).

http://i.stack.imgur.com/ve7OL.png

http://i.stack.imgur.com/KLeQa.png

Thanks.

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Login extends Activity {
    // Declare our Views, so we can access them later
    private EditText etUsername;
    private EditText etPassword;
    private Button btnLogin;
    private Button btnCancel;
    private TextView lblResult;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set Activity Layout
    setContentView(R.layout.login);

    // Get the EditText and Button References
    etUsername = (EditText)findViewById(R.id.username);
    etPassword = (EditText)findViewById(R.id.password);
    btnLogin = (Button)findViewById(R.id.login_enter);
    btnCancel = (Button)findViewById(R.id.login_cancel);
    lblResult = (TextView)findViewById(R.id.result);

    // Set Click Listener
    btnLogin.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Check Login
            String username = etUsername.getText().toString();
            String password = etPassword.getText().toString();

            if(username.equalsIgnoreCase("USER") && password.equals("132465")){
                //lblResult.setText("Login successful");
                Intent loginIntent = new Intent(this, menuTest.class);
                startActivity(loginIntent);
            }

            else {
                lblResult.setText("Login Failed");
            }
        }
    });


    btnCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Close the application
            finish();
        }
    });
}
}

解决方案

try changing Intent loginIntent = new Intent(this, menuTest.class); to Intent loginIntent = new Intent(Login.this, menuTest.class);

 
精彩推荐
图片推荐