-1

I am trying to make a login and register app where the register details are stored on a database within android studio. Can you please help me as when i run my program the next page does not appear (shown code for one page that won't appear from main menu which is the register activity). If you also know how to make a sql database for a login and register in android studio would be much appreciated. Thanks

Main Activity:

package com.example.emily.loginapp;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    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.Register);
        Delete = (Button) findViewById(R.id.Delete);
        Update = (Button) findViewById(R.id.Update);
        Login.setOnClickListener(new View.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 View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent("register_filter");
                startActivity(i);
            }
        });
        Update.setOnClickListener(new View.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 View.OnClickListener() {
            @Override
            public void onClick(View v) {
        status= 3;
                Bundle b = new Bundle();
                b.putInt("status", status);
                Intent i = new Intent("login_filter");
                i.putExtras(b);
                startActivity(i);

            }
        });
    }
}

Register:

package com.example.emily.loginapp;                                                                                  

import android.content.Context;                                                                                      
import android.support.v7.app.AppCompatActivity;                                                                     
import android.view.View;                                                                                            
import android.os.Bundle;                                                                                            
import android.widget.EditText;                                                                                      
import android.widget.Button;                                                                                        
import android.widget.Toast;                                                                                         


public class RegisterActivity extends AppCompatActivity {                                                            

     EditText USER_NAME, USER_PASS, CON_PASS;                                                                        
    String user_name, user_pass,con_pass;                                                                            
Button REG;                                                                                                          
    Context ctx = this;                                                                                              

    @Override                                                                                                        
    protected void onCreate(Bundle savedInstanceState) {                                                             
        super.onCreate(savedInstanceState);                                                                          
        setContentView(R.layout.content_register);                                                                   

    USER_NAME = (EditText) findViewById(R.id.reg_user);                                                              
        USER_PASS = (EditText)findViewById(R.id.reg_pass);                                                           
        CON_PASS = (EditText) findViewById(R.id.con_pass);                                                           
REG = (Button) findViewById(R.id.user_reg);                                                                          
        REG.setOnClickListener(new View.OnClickListener() {                                                          
            @Override                                                                                                
            public void onClick(View v) {                                                                            
                user_name = USER_NAME.getText().toString();                                                          
                user_pass = USER_PASS.getText().toString();                                                          
                con_pass = CON_PASS.getText().toString();                                                            

                if (!(user_pass.equals(con_pass))){                                                                  
                    Toast.makeText(getBaseContext(),"Passwords are not matching", Toast.LENGTH_LONG).show();;        
                USER_NAME.setText("");                                                                               
                    USER_PASS.setText("");                                                                           
                    CON_PASS.setText("");                                                                            
                }else{                                                                                               
                    DatabaseOperations DB = new DatabaseOperations(ctx);                                             
                    DB.putInformation(DB, user_name, user_pass);                                                     
                    Toast.makeText(getBaseContext(),"Registration success", Toast.LENGTH_LONG).show();               
                    finish();                                                                                        

                }                                                                                                    
            }                                                                                                        
        });                                                                                                          

    }                                                                                                                

} 

LOGCAT:
03-09 22:33:25.504 2672-2672/com.example.emily.loginapp D/AndroidRuntime: Shutting down VM
03-09 22:33:25.537 2672-2672/com.example.emily.loginapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.emily.loginapp, PID: 2672
    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=register_filter }
      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:784)
      at android.app.Activity.startActivity(Activity.java:4200)
      at android.app.Activity.startActivity(Activity.java:4168)
      at com.example.emily.loginapp.MainActivity$2.onClick(MainActivity.java:43)
      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)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-09 22:33:36.952 2672-2679/com.example.emily.loginapp W/art: Suspending all threads took: 29.841ms

manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.emily.loginapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DeleteActivity"
            android:label="@string/title_activity_delete"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".RegisterActivity"
            android:label="@string/title_activity_register"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".UpdateActivity"
            android:label="@string/title_activity_update"
            android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>

</manifest>
09Emi
  • 25
  • 2
  • 8

4 Answers4

0

You need to create your intent using a class extending Activity. For example like this:

Intent i = new Intent(this, SomeActivity.class);
startActivity(i);

where this is current Context and SomeActivity is the activity you want to start.

Take a look at the docs:

http://developer.android.com/training/basics/firstapp/starting-activity.html

jdabrowski
  • 1,805
  • 14
  • 21
0

You are using using an intent flag(register_filter) which is not available on the device thats why it is crashing the application...!

The constructor of the Intent class should be call with the context of the activity/app and the activity on which you have to move(If you are not using an activity which is not available on the device)...!

You should use the below code to access the RegisterActivity,

Intent i = new Intent(MainActivity.this, RegistrationActivity.class);
startActivity(i);
Arsal Imam
  • 2,882
  • 2
  • 24
  • 35
0

To call a new Activity from the current Activity you need to to pass the context of the current activity and the "NewClass" which you want to open as parameters.

For Eg :

    Intent i = new Intent(CurrentClassName.this, TheClassToBeOpened.class);
    startActivity(i);
AmeyaG
  • 176
  • 1
  • 1
  • 10
0

IMHO using actions is overkill for what you want to achieve. You should just ude something like:

Intent i = new Intent(getContext(), RegistrationActivity.class);
startActivity(i);

(you can use this instead getContext() too).

If you do really want to use actions, then you must define the intent filter register_filter in your activity. Something along the lines:

<activity
    android:name=".LoginActivity"
    android:label="@string/title_activity_login"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
        <action android:name="login_filter" />
    </intent-filter> 
</activity>

should do the trick.

For reference, please have a look at the documentation and this question.

Community
  • 1
  • 1
Laur Ivan
  • 4,117
  • 3
  • 38
  • 62
  • 1
    You can't use this as it's used within an onClick(). You could use MainActivity.this instead. – jobbert May 23 '16 at 09:16