java无法为安卓执行方法:on提醒我
当我点击注册网站上的注册按钮时,我感到很不幸
最重要的
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="com.example.champ.remindme">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission 安卓:name="安卓.permission.GET_ACCOUNTS" />
<uses-permission 安卓:name="安卓.permission.READ_PROFILE" />
<uses-permission 安卓:name="安卓.permission.READ_CONTACTS" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission 安卓:name="安卓.permission.ACCESS_FINE_LOCATION" />
<application
安卓:allowBackup="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity 安卓:name=".Login">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <activity 安卓:name=".Login" /> -->
<activity 安卓:name=".Menu" />
<activity 安卓:name=".AddReminder" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
安卓:name="com.google.安卓.geo.API_KEY"
安卓:value="@string/google_maps_key" />
<activity
安卓:name=".AddEventPlace"
安卓:label="@string/title_activity_add_event_place" />
<activity 安卓:name=".SignUp"></activity>
</application>
</manifest>
XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission 安卓:name="安卓.permission.GET_ACCOUNTS" />
<uses-permission 安卓:name="安卓.permission.READ_PROFILE" />
<uses-permission 安卓:name="安卓.permission.READ_CONTACTS" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission 安卓:name="安卓.permission.ACCESS_FINE_LOCATION" />
<application
安卓:allowBackup="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity 安卓:name=".Login">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <activity 安卓:name=".Login" /> -->
<activity 安卓:name=".Menu" />
<activity 安卓:name=".AddReminder" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
安卓:name="com.google.安卓.geo.API_KEY"
安卓:value="@string/google_maps_key" />
<activity
安卓:name=".AddEventPlace"
安卓:label="@string/title_activity_add_event_place" />
<activity 安卓:name=".SignUp"></activity>
</application>
</manifest>
爪哇
package com.example.champ.remindme;
import 安卓.app.AlertDialog;
import 安卓.content.Context;
import 安卓.database.sqlite.SQLiteDatabase;
import 安卓.os.Bundle;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.view.View;
import 安卓.widget.Button;
import 安卓.widget.EditText;
public class SignUp extends AppCompatActivity {
EditText editUsername,editPassword,editEmail,editMobileNumber;
Button btnSignUpButton;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
editUsername = (EditText)findViewById(R.id.editUsername);
editPassword = (EditText)findViewById(R.id.editPassword);
editEmail = (EditText)findViewById(R.id.editEmail);
editMobileNumber = (EditText)findViewById(R.id.editMobileNumber);
btnSignUpButton = (Button)findViewById(R.id.btnSiginUpButton);
db=openOrCreateDatabase("RemindMe", Context.MODE_PRIVATE, null);
db.execSQL("create table IF NOT EXISTS User (Username TEXT PRIMARY KEY," +
"Password TEXT," +
"Email TEXT," +
"MobileNumber Integer )");
}
public void AddUser(View v){
if(editUsername.length()==0||
editPassword.length()==0||
editEmail.length()==0||
editMobileNumber.length()==0)
{
showMessage("Error", "Please enter all values");
return;
}
db.execSQL("INSERT INTO User VALUES('"+editUsername+"'," +
"'"+editPassword+ "'," +
"'"+editEmail+"',"+
"'"+editEmail+"',"+
"');");
showMessage("Success", "Record added");
}
public void showMessage(String title,String message)
{
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:paddingBottom="@dimen/activity_vertical_margin"
安卓:paddingLeft="@dimen/activity_horizontal_margin"
安卓:paddingRight="@dimen/activity_horizontal_margin"
安卓:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SignUp"
安卓:background="@drawable/back">
<ImageView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:id="@+id/imageView5"
安卓:src="@drawable/remind_me_logo"
安卓:layout_alignParentTop="true"
安卓:layout_centerHorizontal="true" />
<EditText
安卓:id="@+id/editUsername"
安卓:layout_width="265dp"
安卓:layout_height="wrap_content"
安卓:padding="15dip"
安卓:background="@drawable/username_rounded_edited_text"
安卓:inputType="text"
安卓:hint="Username"
安卓:textAlignment="center"
安卓:layout_below="@+id/imageView5"
安卓:layout_centerHorizontal="true"
安卓:layout_marginTop="38dp" />
<EditText
安卓:id="@+id/editPassword"
安卓:layout_width="265dp"
安卓:layout_height="wrap_content"
安卓:padding="15dip"
安卓:background="@drawable/input_felid"
安卓:inputType="textVisiblePassword"
安卓:hint="Password"
安卓:textAlignment="center"
安卓:layout_below="@+id/editUsername"
安卓:layout_alignLeft="@+id/editUsername"
安卓:layout_alignStart="@+id/editUsername" />
<EditText
安卓:id="@+id/editConfrimPassword"
安卓:layout_width="265dp"
安卓:layout_height="wrap_content"
安卓:padding="15dip"
安卓:background="@drawable/input_felid"
安卓:inputType="textVisiblePassword"
安卓:hint="Confrim Password"
安卓:textAlignment="center"
安卓:layout_below="@+id/editPassword"
安卓:layout_alignLeft="@+id/editPassword"
安卓:layout_alignStart="@+id/editPassword" />
<EditText
安卓:id="@+id/editEmail"
安卓:layout_width="265dp"
安卓:layout_height="wrap_content"
安卓:padding="15dip"
安卓:background="@drawable/input_felid"
安卓:inputType="textWebEmailAddress"
安卓:hint="Email"
安卓:textAlignment="center"
安卓:layout_below="@+id/editConfrimPassword"
安卓:layout_centerHorizontal="true" />
<EditText
安卓:id="@+id/editMobileNumber"
安卓:layout_width="265dp"
安卓:layout_height="wrap_content"
安卓:padding="15dip"
安卓:background="@drawable/pass_rounded_edited_text"
安卓:inputType="number"
安卓:hint="Contact Number"
安卓:textAlignment="center"
安卓:layout_below="@+id/editEmail"
安卓:layout_centerHorizontal="true" />
<CheckBox
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="I agree the terms and condiations"
安卓:id="@+id/checkBox"
style="@style/ButtonText"
安卓:textSize="18dp"
安卓:checked="false"
安卓:layout_below="@+id/editMobileNumber"
安卓:layout_alignLeft="@+id/btnSiginUpButton"
安卓:layout_alignStart="@+id/btnSiginUpButton" />
<Button
安卓:id="@+id/btnSiginUpButton"
安卓:background="@drawable/blue_botton"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="@string/signUp"
style="@style/ButtonText"
安卓:onClick="AddUser"
安卓:layout_below="@+id/checkBox"
安卓:layout_alignLeft="@+id/editMobileNumber"
安卓:layout_alignStart="@+id/editMobileNumber"
安卓:layout_alignRight="@+id/editMobileNumber"
安卓:layout_alignEnd="@+id/editMobileNumber" />
</RelativeLayout>
错误
05-21 21:31:39.665 1359-1359/com.example.champ.remindme E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.champ.remindme, PID: 1359 java.lang.IllegalStateException: Could not execute method for 安卓:onClick at 安卓.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:289) at 安卓.view.View.performClick(View.java:4780) at 安卓.view.View$PerformClick.run(View.java:19866) at 安卓.os.Handler.handleCallback(Handler.java:739) at 安卓.os.Handler.dispatchMessage(Handler.java:95) at 安卓.os.Looper.loop(Looper.java:135) at 安卓.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at 安卓.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) at 安卓.view.View.performClick(View.java:4780) at 安卓.view.View$PerformClick.run(View.java:19866) at 安卓.os.Handler.handleCallback(Handler.java:739) at 安卓.os.Handler.dispatchMessage(Handler.java:95) at 安卓.os.Looper.loop(Looper.java:135) at 安卓.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: 安卓.database.sqlite.SQLiteException: unrecognized token: "');" (code 1): , while compiling: INSERT INTO User VALUES('安卓.support.v7.widget.AppCompatEditText{383b472a VFED..CL ........ 192,541-888,682 #7f0d00a6 app:id/editUsername}','安卓.support.v7.widget.AppCompatEditText{3568491b VFED..CL ........ 192,682-888,823 #7f0d00a7 app:id/editPassword}','安卓.support.v7.widget.AppCompatEditText{298f8ab8 VFED..CL ........ 192,964-888,1105 #7f0d00a9 app:id/editEmail}','安卓.support.v7.widget.AppCompatEditText{298f8ab8 VFED..CL ........ 192,964-888,1105 #7f0d00a9 app:id/editEmail}','); at 安卓.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at 安卓.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) at 安卓.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) at 安卓.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at 安卓.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) at 安卓.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31) at 安卓.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674) at 安卓.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605) at com.example.champ.remindme.SignUp.AddUser(SignUp.java:41) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at 安卓.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) at 安卓.view.View.performClick(View.java:4780) at 安卓.view.View$PerformClick.run(View.java:19866) at 安卓.os.Handler.handleCallback(Handler.java:739) at 安卓.os.Handler.dispatchMessage(Handler.java:95) at 安卓.os.Looper.loop(Looper.java:135) at 安卓.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:698)
# 1 楼答案
你的
editUsername
,editPassword
不是你试图插入的Strings
,它的EditText
显然是引用了一个分配指针,比如'android.support.v7.widget.AppCompatEditText{383b472a VFED..CL ........ 192,541-888,682 #7f0d00a6
您必须插入
String
而不是EditText
本身,因此将editUsername
更改为editUsername.getText().toString()
,就像在editPassword
中一样,并根据需要进行休息更新:
你的语法也不正确试着这样替换
或者更好地使用参数化查询,而不是像this这样的原始查询