我想做一個登錄和註冊應用程序,其中註冊詳細信息存儲在android studio的數據庫中。當我運行我的程序時,你能否幫助我,下一頁不出現(顯示的代碼爲一個頁面,不會從主菜單顯示,這是註冊活動)。如果你也知道如何讓一個SQL數據庫的登錄和註冊在Android工作室將不勝感激。由於當按鈕被點擊時,爲什麼我的程序崩潰?
主要活動:
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>
你的清單也是有用的。它在我看來你錯過了一些東西。 –
@LaurIvan添加清單 – 09Emi