[英]android.content.ActivityNotFoundException: No Activity found to handle Intent { act=activity2.application1 (has extras) }
[英]android.content.ActivityNotFoundException: No Activity found to handle Intent { act=login_filter (has extras) }
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=login_filter (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:843)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at com.example.carlos.assigmentcarlos.MainActivity$1.onClick(MainActivity.java:32)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
好吧,我正在尝试运行此项目,但是出现此错误。 我不确定为什么Intent无法正常工作。
这是我的主:
package com.example.carlos.assigmentcarlos;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
Button Login, Register, Delete, Update;
int status = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Login = (Button) findViewById(R.id.Login);
Register = (Button) findViewById(R.id.Reg);
Delete = (Button) findViewById(R.id.Delete);
Update = (Button) findViewById(R.id.Update);
Login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
status = 1;
Bundle b = new Bundle();
b.putInt("status", status);
Intent i = new Intent("login_filter");
i.putExtras(b);
startActivity(i);
}
});
Register.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent("register_filter");
startActivity(i);
}
});
Update.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
status = 2;
Bundle b = new Bundle();
b.putInt("status", status);
Intent i = new Intent("login_filter");
i.putExtras(b);
startActivity(i);
}
});
Delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
status = 3;
Bundle b = new Bundle();
b.putInt("status", status);
Intent i = new Intent("login_filter");
i.putExtras(b);
startActivity(i);
}
});
}
}
这是我的寄存器:
package com.example.carlos.assigmentcarlos;
/**
* Created by Carlos on 22/04/2016.
*/
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Register extends Activity {
Button Login;
EditText USERNAME,USERPASS;
String username,userpass;
Context CTX = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login_layout);
Login = (Button) findViewById(R.id.b_login);
USERNAME = (EditText) findViewById(R.id.user_name);
USERPASS = (EditText) findViewById(R.id.user_pass);
Login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Bundle b = getIntent().getExtras();
int status = b.getInt("status");
if(status == 1)
{
Toast.makeText(getBaseContext(), "Please wait...", Toast.LENGTH_LONG).show();
username = USERNAME.getText().toString();
userpass = USERPASS.getText().toString();
DatabaseOperations DOP = new DatabaseOperations(CTX);
Cursor CR = DOP.getInformation(DOP);
CR.moveToFirst();
boolean loginstatus = false;
String NAME = "";
do
{
if(username.equals(CR.getString(0))&& (userpass.equals(CR.getString(1))))
{
loginstatus = true;
NAME = CR.getString(0);
}
} while(CR.moveToNext());
if(loginstatus)
{
Toast.makeText(getBaseContext(), "Login Success----\n Welcome "+NAME, Toast.LENGTH_LONG).show();
finish();
}
else
{
Toast.makeText(getBaseContext(), "Login Failed---- ", Toast.LENGTH_LONG).show();
finish();
}
}
else if(status == 2)
{
Toast.makeText(getBaseContext(), "Please wait...", Toast.LENGTH_LONG).show();
username = USERNAME.getText().toString();
userpass = USERPASS.getText().toString();
DatabaseOperations DOP = new DatabaseOperations(CTX);
Cursor CR = DOP.getInformation(DOP);
CR.moveToFirst();
boolean loginstatus = false;
String NAME = "";
do
{
if(username.equals(CR.getString(0))&& (userpass.equals(CR.getString(1))))
{
loginstatus = true;
NAME = CR.getString(0);
}
} while(CR.moveToNext());
if(loginstatus)
{
Toast.makeText(getBaseContext(), "Login Success----\n Welcome "+NAME, Toast.LENGTH_LONG).show();
Intent i = new Intent("update_filter");
Bundle BN = new Bundle();
BN.putString("user_name",NAME );
BN.putString("user_pass",userpass );
i.putExtras(BN);
startActivity(i);
finish();
}
else
{
Toast.makeText(getBaseContext(), "Login Failed---- ", Toast.LENGTH_LONG).show();
finish();
}
}
else if(status == 3)
{
Toast.makeText(getBaseContext(), "Please wait...", Toast.LENGTH_LONG).show();
username = USERNAME.getText().toString();
userpass = USERPASS.getText().toString();
DatabaseOperations DOP = new DatabaseOperations(CTX);
Cursor CR = DOP.getInformation(DOP);
CR.moveToFirst();
boolean loginstatus = false;
String NAME = "";
do
{
if(username.equals(CR.getString(0))&& (userpass.equals(CR.getString(1))))
{
loginstatus = true;
NAME = CR.getString(0);
}
} while(CR.moveToNext());
if(loginstatus)
{
Toast.makeText(getBaseContext(), "Login Success----\n Welcome "+NAME, Toast.LENGTH_LONG).show();
Intent i = new Intent("delete_filter");
Bundle B = new Bundle();
B.putString("user_name",NAME );
i.putExtras(B);
startActivity(i);
finish();
}
else
{
Toast.makeText(getBaseContext(), "Login Failed---- ", Toast.LENGTH_LONG).show();
finish();
}
Intent i = new Intent("delete_filter");
startActivity(i);
}
}
});
}
}
Android清单:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:layout_alignParentBottom="true"
android:layout_alignParentCenter="true" />
</LinearLayout>
替换所有出现的情况:
Intent i = new Intent("...");
(其中...
是login_filter
等)
使用将Java类作为第二个参数的Intent
构造函数,例如:
Intent i = new Intent(this, Register.class);
这对您来说有些困难,因为您决定拥有一个以上的名为Register
东西(一个Activity
类和一个小部件)。
您需要一个Intent
来标识您要启动的内容。 要启动自己的私人活动,最简单,最安全的方法是使用Intent(Context, Class)
构造函数。
例如,在此示例应用程序中 ,我使用了这样的“明确Intent
”来启动活动:
/***
Copyright (c) 2012 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
https://commonsware.com/Android
*/
package com.commonsware.android.exint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class ExplicitIntentsDemoActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void showOther(View v) {
startActivity(new Intent(this, OtherActivity.class));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.