我似乎无法将HomeActivity连接到LogInActivity。该错误表示ActivityNotFound。找不到处理Intent的Activity

时间:2011-09-01 08:55:34

标签: android

这是我的LogInActivity

public class LogInActivity extends Activity implements OnClickListener {
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loginactivity);

Button launch = (Button)findViewById(R.id.login_button);
        launch.setOnClickListener(new OnClickListener()
        {
         public void onClick(View v) {
           EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
           EditText passwordEditText = (EditText) findViewById(R.id.txt_password);
           TextView loginTextView = (TextView)findViewById(R.id.tv_error);

           String sUserName = usernameEditText.getText().toString();
           String sPassword = passwordEditText.getText().toString();

            if(sUserName.equals("numlock") && sPassword.equals("numlock")){
                Intent i = new Intent();
                startActivity(i);
            }
             else {
                loginTextView.setText("Login failed. Username and/or password doesn't match.");
                 }
            }
        }); 
    }

    public void onClick(View v)
        {
            Intent intent = new Intent(LogInActivity.this, HomeActivity.class);
            startActivity(intent);
        }
}

这是我的HomeActivity

public class HomeActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.homeactivity);
    }
}

2 个答案:

答案 0 :(得分:0)

您需要在AndroidManifest.xml文件中定义新活动,如下所示:

<activity
  android:name=".HomeActivity"
  android:label="Home activity">
</activity>

答案 1 :(得分:0)

Intent i = new Intent();
startActivity(i);

您尚未设置要在此处启动的活动...

确保清单文件中有条目..