2016-04-22 9 views
0
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) 

Nun, ich versuche, dieses Projekt zu laufen, aber dieser Fehler erscheint. Ich bin mir nicht sicher, warum Intent nicht funktioniert.android.content.ActivityNotFoundException: Keine Aktivität gefunden Intent zu handhaben {act = login_filter (hat Extras)}

Das ist mein Haupt:

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

Das ist mein Register ist:

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 Manifest:

<?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> 
+0

ich die Antwort auf Ihre Frage nicht wissen, aber ich bemerkte, dass die Code-Teile von ' Toast.makeText (getBaseContext(), "Bitte warten ...", Toast.LENGTH_LONG) .show(); 'in Richtung'} while (CR.moveToNext()); 'ist genau dasselbe für alle drei if's. Warum nicht diesen Teil des Codes in eine separate Methode einfügen? –

Antwort

0

Ersetzen Sie alle Vorkommen von:

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

(wo ... ist login_filter, etc.)

mit Intent Konstrukteuren, die die Java-Klasse als zweiten Parameter übernehmen, wie zum Beispiel:

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

Dies wird für Dich etwas schwierig sein, da Sie beschlossen, habe mehr als eine Sache namens Register (eine Activity Klasse und ein Widget).

Sie möchten eine Intent, die identifiziert, was Sie versuchen, zu starten. Der einfachste und sicherste Weg, um private Aktivitäten zu starten, ist der Intent(Context, Class) Konstruktor.

Zum Beispiel in this sample app, verwende ich eine solche „explicit Intent“ eine Aktivität zu starten:

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

Bereits ausprobiert und mir eine Fehlermeldung "Contructor kann nicht aufgelöst werden" – Calitoz

+0

@Calitoz: Für diese Fälle, sehen Sie, wenn Sie innerhalb einer anonymen inneren Klasse sind (z. B. 'neue OnClickListener() ...'). Wenn ja, setzen Sie "this" mit der Aktivitätsklasse voran (z. B. "MainActivity.this"). – CommonsWare

Verwandte Themen