android.content.ActivityNotFoundException:找不到处理Intent的Activity {act = login_filter(has extras)}

时间:2016-04-22 14:49:27

标签: java android android-sqlite

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>

1 个答案:

答案 0 :(得分:1)

替换所有出现的:

Intent i  = new Intent("...");

(其中...login_filter等)

使用Intent构造函数将Java类作为第二个参数,例如:

Intent i = new Intent(this, Register.class);

这对你来说有点困难,因为你决定有多个名为Register的东西(一个Activity类和一个小部件)。

您需要Intent来标识您尝试启动的内容。开始您自己的私人活动的最简单和最安全的方法是使用Intent(Context, Class)构造函数。

例如,在this sample app中,我使用了这样一个&#34;显式Intent&#34;开始一项活动:

/***
  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));
  }
}