我正在尝试登录并注册应用程序,其中寄存器详细信息存储在android studio中的数据库中。你可以帮助我,因为当我运行我的程序时,下一页不会出现(显示一个页面的代码,它不会出现在主菜单中,这是注册活动)。如果你也知道如何为登录做一个sql数据库并在android studio中注册将非常感激。感谢
主要活动:
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);
}
});
}
}
寄存器:
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
清单:
<?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>
答案 0 :(得分:0)
您需要使用intent
扩展class
来创建Activity
。
例如:
Intent i = new Intent(this, SomeActivity.class);
startActivity(i);
其中this
是当前Context
,而SomeActivity
是您要开始的活动。
看看文档:
http://developer.android.com/training/basics/firstapp/starting-activity.html
答案 1 :(得分:0)
您正在使用设备上没有的意图标记( register_filter ),这就是崩溃应用程序的原因......!
应该使用上下文调用Intent类的构造函数 活动/应用程序和您必须移动的活动(如果您是 不使用设备上没有的活动)......!
您应该使用以下代码访问RegisterActivity,
Intent i = new Intent(MainActivity.this, RegistrationActivity.class);
startActivity(i);
答案 2 :(得分:0)
要从当前活动中调用新活动,您需要传递当前活动的上下文和&#34; NewClass&#34;你想打开它作为参数。
例如:
Intent i = new Intent(CurrentClassName.this, TheClassToBeOpened.class);
startActivity(i);
答案 3 :(得分:0)
恕我直言,使用行动对你想要达到的目标来说是过度的。你应该只是这样的东西:
Intent i = new Intent(getContext(), RegistrationActivity.class);
startActivity(i);
(您也可以使用this
代替getContext()
。)
如果您确实确实想要使用actions,那么您必须在活动中定义意图过滤器register_filter
。一些事情:
<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>
应该这样做。
如需参考,请查看documentation和this question。