当前位置: 首页 > 知识库问答 >
问题:

无法执行Android的方法:在提醒我

艾望
2023-03-14
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.champ.remindme">

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.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 android:name="android.permission.ACCESS_FINE_LOCATION" />

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- <activity android:name=".Login" /> -->
    <activity android:name=".Menu" />
    <activity android: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
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".AddEventPlace"
        android:label="@string/title_activity_add_event_place" />
    <activity android:name=".SignUp"></activity>
</application>

</manifest>
<?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 android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.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 android:name="android.permission.ACCESS_FINE_LOCATION" />

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- <activity android:name=".Login" /> -->
    <activity android:name=".Menu" />
    <activity android: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
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".AddEventPlace"
        android:label="@string/title_activity_add_event_place" />
    <activity android:name=".SignUp"></activity>
</application>

</manifest>
package com.example.champ.remindme;
import android.app.AlertDialog;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.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:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SignUp"
android:background="@drawable/back">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView5"
    android:src="@drawable/remind_me_logo"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<EditText
    android:id="@+id/editUsername"
    android:layout_width="265dp"
    android:layout_height="wrap_content"
    android:padding="15dip"
    android:background="@drawable/username_rounded_edited_text"
    android:inputType="text"
    android:hint="Username"
    android:textAlignment="center"
    android:layout_below="@+id/imageView5"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="38dp" />
<EditText
    android:id="@+id/editPassword"
    android:layout_width="265dp"
    android:layout_height="wrap_content"
    android:padding="15dip"
    android:background="@drawable/input_felid"
    android:inputType="textVisiblePassword"
    android:hint="Password"
    android:textAlignment="center"
    android:layout_below="@+id/editUsername"
    android:layout_alignLeft="@+id/editUsername"
    android:layout_alignStart="@+id/editUsername" />
<EditText
    android:id="@+id/editConfrimPassword"
    android:layout_width="265dp"
    android:layout_height="wrap_content"
    android:padding="15dip"
    android:background="@drawable/input_felid"
    android:inputType="textVisiblePassword"
    android:hint="Confrim Password"
    android:textAlignment="center"
    android:layout_below="@+id/editPassword"
    android:layout_alignLeft="@+id/editPassword"
    android:layout_alignStart="@+id/editPassword" />
<EditText
    android:id="@+id/editEmail"
    android:layout_width="265dp"
    android:layout_height="wrap_content"
    android:padding="15dip"
    android:background="@drawable/input_felid"
    android:inputType="textWebEmailAddress"
    android:hint="Email"
    android:textAlignment="center"
    android:layout_below="@+id/editConfrimPassword"
    android:layout_centerHorizontal="true" />
<EditText
    android:id="@+id/editMobileNumber"
    android:layout_width="265dp"
    android:layout_height="wrap_content"
    android:padding="15dip"
    android:background="@drawable/pass_rounded_edited_text"
    android:inputType="number"
    android:hint="Contact Number"
    android:textAlignment="center"
    android:layout_below="@+id/editEmail"
    android:layout_centerHorizontal="true" />

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I agree the terms and condiations"
    android:id="@+id/checkBox"
    style="@style/ButtonText"
    android:textSize="18dp"
    android:checked="false"
    android:layout_below="@+id/editMobileNumber"
    android:layout_alignLeft="@+id/btnSiginUpButton"
    android:layout_alignStart="@+id/btnSiginUpButton" />
<Button
    android:id="@+id/btnSiginUpButton"
    android:background="@drawable/blue_botton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/signUp"
    style="@style/ButtonText"
    android:onClick="AddUser"
    android:layout_below="@+id/checkBox"
    android:layout_alignLeft="@+id/editMobileNumber"
    android:layout_alignStart="@+id/editMobileNumber"
    android:layout_alignRight="@+id/editMobileNumber"
    android:layout_alignEnd="@+id/editMobileNumber" />
   </RelativeLayout>

误差

05-21 21:31:39.665 135 9-1359/com.example.champ.remodme e/androidruntime:致命异常:main process:com.example.champ.remodme,pid:1359 java.lang.illegalstateException:无法执行Android方法:onclick at android.support.v7.app.appcompatviewwinflater$declaredonclicklistener.onclick(appcompatviewwinflater:289)at android.view.view.view.performclick android.os.handler.dispatchMessage(handler.java:95)在Android.os.looper.loop(looper.java:135)在Android.app.activitythread.main(activitythread.java:5254)在java.lang.reflect.method.invoke(原生方法)在java.lang.reflect.method.invoke(method.java:372)在com.android.internal.os.zygoteinit$methodandargscaller.run位于java.lang.reflect.method.invoke(本机Me)的InvocationTargetExceptionthod)在java.lang.reflect.Method.invoke(Method.java:372)在Android.support.v7.app.appcompatviewwinflater$declaredonclicklistener.onclick(appcompatviewwinflater$declaredonclicklistener.onclick(appcompatviewwinflater.java:284)在Android.view.view.performclick(view.java:4780)在Android.view.view.view.performclick ActivityThread.main(ActivityThread.java:5254) 在java.lang.reflect.Method.invoke(本机方法) 在java.lang.reflect.Method.invoke(Method.java:372) 在com.android.internal.os.zygoteinit$methodandArgsCaller.run(zygoteinit.java:903) 在com.android.internal.os.zygoteinit.main(zygoteinit.java:698) 在get.appcompatedittext{383b472a vfed..cl........192,541-888,682#7F0D00A6 app:id/editusername}“,”Android.support.v7.widget.appcompatedittext{3568491b vfed.cl.....................192,682-888,823#7f0d00a7 app:id/editpassword}‘,'android.support.v7.widget.appcompatedittext{298f8ab8 vfed..cl.........192,964-888,110 5#7f0d00a9 app:id/editemail}“,”Android.support.v7.widget.appcompatedittext{298f8ab8 vfed.cl..................192,964-888,110 5#7F0D00A9 app:id/editemail}‘,');在Android.database.sqlite.sqlite.sqlite.sqliteConnection.acquirePreparedStatement(本机方法)在Android.database.sqlite.sqliteConnection.acquirePreparedStatement(SqliteConnection.java:889)在sqlite.sqlitestatement.(sqlitestatement.java:31)在Android.database.sqlite.sqlite.sqlitedatabase.executesQL(sqlitedatabase.java:1674)在Android.database.sqlite.sqlitedatabase.execsql(sqlitedatabase.java:1605)在com.example.champ.remindme.signup.adduser(Signup.java:41)在java.lang.reflect.Method.invoke() 在Android.View.View.performClick(查看.java:4780) 在Android.view.view$performclick.run(view.java:19866) 在Android.os.handler.handleCallback(handler.java:739) 在Android.os.handler.dispatchMessage(handler.java:95) 在Android.os.handler.dispatchMessage(handler.java:135) 在Android.app.activityThread.loop(looper.java:5254) 在java.lang.reflect.Method.invoke(原生andargsCaller.run(zygoteinit.java:903) 在com.android.internal.os.zygoteinit.main(zygoteinit.java:698) 

共有1个答案

赵景曜
2023-03-14

您的editusernameeditpassword不是您试图插入的字符串,它的edittext显然引用了像'android.support.v7.widget.appcompatedittext这样的分配指针{383b472a vfed...cl............192,541-888,682#7F0D00A6

您必须插入string而不是edittext本身,因此将editusername.gettext().tostring()更改为editusername.gettext(),与editpassword和rest中的内容相同。

更新:

您的语法也不正确,尝试像这样替换,

db.execSQL("INSERT INTO User VALUES('"+editUsernameText+"'," + "'"+editPasswordText+ "'," + "'"+editEmailText+"',"+ "'"+editEmailText+"');");

或者更好地使用参数化查询,而不是像这样的原始查询。

 类似资料:
  • 问题内容: 您好,我是学习android的新手,我正尝试在学习Android时制作一个半有用的应用程序(对我自己),基本上我是在第一时间接受有用的Java代码(ping X,端口扫描)并添加将它们添加到我的应用中,我无法弄清楚 为什么 会发生此错误,我确实认为这与代码的第77行有关,但是我想了解为什么它无法正常工作,因此下次我可以更好地帮助自己。很抱歉出现罗word的问题,我不知道什么时候闭嘴。

  • 我是一个相当新的Android程序员,在完成了几个教程后,我开始扩展我完成的BMI计算器教程。在此过程中,我需要删除并重新安装Eclipse。我还不得不切换工作区。由于我的错误,我只能保留应用程序的。java文件。我重新创建了。xml和清单,直到现在,当我尝试单击calculate按钮时,才得到了IllegalStateException。在切换和重新创建之前,一切都很好。我正在使用Nexus G

  • 本文向大家介绍python执行get提交的方法,包括了python执行get提交的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了python执行get提交的方法。分享给大家供大家参考。具体如下: 希望本文所述对大家的Python程序设计有所帮助。

  • 问题内容: 我正在尝试制作一个订购咖啡的应用程序。(我真的很陌生。) 我的应用程序运行良好,直到出现两个错误。现在,它可以在设备中运行,但是当您尝试触摸按钮时,它将停止。 代码是: XML代码: 终端中的第一个错误: 和主要错误: 问题答案: 改变这条线 对此: 要么:

  • 本文向大家介绍Android Studio无法执行Java类的main方法问题及解决方法,包括了Android Studio无法执行Java类的main方法问题及解决方法的使用技巧和注意事项,需要的朋友参考一下 Android Studio升级到哦最新版3.6.1后,新建了个项目,发现无法执行Java类的main方法。试了网上的各种方法,比如切换gradle离线模式、gradle.properti