无法登录我的android登录活动?

无法登录我的android登录活动?,android,Android,我使用的是android SQLite数据库,我在第一个活动中登录,然后进入另一个活动,但当我输入用户名和密码时,它显示我的密码和用户名不正确,并且没有登录到我的其他活动。我的用户名和密码以users.xml文件名保存在资产文件夹中。这是密码 public class LoginActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) {

我使用的是android SQLite数据库,我在第一个活动中登录,然后进入另一个活动,但当我输入用户名和密码时,它显示我的密码和用户名不正确,并且没有登录到我的其他活动。我的用户名和密码以users.xml文件名保存在资产文件夹中。这是密码

    public class LoginActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.login, menu);
        return true;
    }

    public void Login(View view) {
        Intent intent = new Intent(this, MainActivity.class);
        XMLParser xmlparser = new XMLParser();
        InputStream in;
        User user;

        EditText userText = (EditText) findViewById(R.id.username_field);
        String username = userText.getText().toString();

        EditText passText = (EditText) findViewById(R.id.password_field);
        String password = passText.getText().toString();

        if (username.matches("\\w{1,16}") && password.matches(".{1,16}")) {
            try {
                if (login(username, password)) {
                    in = getResources().getAssets().open("Users.xml");
                    XmlPullParser parser = Xml.newPullParser();
                    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,
                            false);
                    parser.setInput(in, null);
                    parser.nextTag();

                    user = xmlparser.getUsers(parser).get(username);

                    if (user.getRole().equals("Nurse")) {
                        intent.putExtra("userKey", new Nurse(user.getName(),
                                user.getUsername(), user.getPassword(), this));
                    } else if (user.getRole().equals("Physician")) {
                        intent.putExtra(
                                "userKey",
                                new Physician(user.getName(), user
                                        .getUsername(), user.getPassword(),
                                        this));
                    }
                    startActivity(intent);
                } else {
                    String messgage = "Username or password are incorrect";
                    Toast.makeText(getApplicationContext(), messgage,
                            Toast.LENGTH_SHORT).show();
                }

            } catch (NoUserFoundException e) {
                String messgage = "Username or password are incorrect";
                Toast.makeText(getApplicationContext(), messgage,
                        Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            String message = "Please enter a valid username or password";
            Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT)
                    .show();
        }
    }

    public boolean login(String username, String password)
            throws NoUserFoundException {
        boolean check = false;
        FileInputStream in = null;
        File file = new File(getApplicationContext().getFilesDir(), "Users.xml");

        try {
            in = new FileInputStream(file.getPath());
            String pass = new XMLParser().getPass(in, username);
            if (pass.equals(password))
                check = true;
        } catch (NoUserFoundException e) {
            throw new NoUserFoundException();
        } catch (IOException e) {

            e.printStackTrace();
        }
        return check;

    }

}
下面是users.xml

 <?xml version="1.0" encoding="UTF-8"?>
<users>
    <user>
        <username>JohnS</userName>
        <password>123</password>
        <name>
            <fName>John</fName>
            <lName>Smith</lName>
        </name>
        <role>Nurse</role>
    </user>
    <user>
        <userName>Matt</userName>
        <password>456</password>
        <name>
            <fName>Matt</fName>
            <lName>Smith</lName>
        </name>
        <role>Physician</role>
    </user>
</users>

字符串pass的值是多少?在该行之后有一个日志用户名和密码不正确否我的意思是如果pass.equalspassword决定是否登录,那么pass的值是多少?…SQLite数据库!=xml文件对不起,我不明白你的问题,我从GITHUB.COM上得到了这段代码,我不知道如何处理这个案例。。只想输入登录名和密码,然后进入我的其他活动