无法访问的代码

时间:2011-09-05 05:33:53

标签: unreachable-code

public void onClick(View v) {
    String uname=tv1.getText().toString();
    String pass=tv2.getText().toString();
    //String copmare=uname.concat(pass);

    Cursor cur = db.query("accountTable",    // Where are we looking?
        new String[]{ "colProject" },    // What do we want back?
        "colName = ? AND colPass = ?",   // What are we matching?
        new String[]{ uname, pass },     // What to put in the "holes"?
        null, null, null);               // Everything else default...

    if (cur != null) {
        cur.moveToNext();
    }
    return;

    Intent i = new Intent(FirstAssignmentActivity.this,success.class);
    i.putExtra("v1",   cur.getString(0));
    startActivity(i);

}

为什么我的代码无法访问?

2 个答案:

答案 0 :(得分:2)

你写return ;,所以控制将在那时退出函数而不到达函数的最后3行(Intent i等)

答案 1 :(得分:0)

您正从该方法返回。之后的代码都不会执行。

if (cur != null) {
    cur.moveToNext();
}
return;  // AFTER THIS NOTHING WILL EXECUTE