- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 firebase 数据库通过自定义字段注册用户。突然我得到了这个意想不到的错误。我之前没有看到这个错误。
FATAL EXCEPTION: main Process:com.example.muhammadtehmoor.testing, PID: 23770 java.lang.NullPointerException:Attempt to invoke virtual method android.text.Editable android.widget.EditText.getText()' on a null object reference com.example.muhammadtehmoor.testing SignUpActivity$1 ..onClick(SignUpActivity.java:49)
这是我的注册 Activity :
package com.example.muhammadtehmoor.testing;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class SignUpActivity extends AppCompatActivity {
EditText txtname,txtphone,txtemail,txtpassword;
String fullname="",email="",phone="",password = "";
Button submit,cancel;
private FirebaseAuth firebaseAuth;
private DatabaseReference databaseReference;
private FirebaseDatabase firebaseDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
txtname = (EditText) findViewById(R.id.edittext2);
txtphone = (EditText)findViewById(R.id.editText3);
txtemail = (EditText)findViewById(R.id.editText4);
txtpassword = (EditText)findViewById(R.id.editText5);
submit = (Button)findViewById(R.id.btn_submit);
cancel = (Button)findViewById(R.id.btn_cancel);
databaseReference = FirebaseDatabase.getInstance().getReference("Driver");
firebaseAuth = FirebaseAuth.getInstance();
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fullname = txtname.getText().toString();
email = txtemail.getText().toString();
phone = txtphone.getText().toString();
password = txtpassword.getText().toString();
if(TextUtils.isEmpty(fullname))
{
txtname.setError("Enter a valid credential");
txtname.requestFocus();
return;
}
if(TextUtils.isEmpty(email))
{
txtemail.setError("Enter a valid credential");
txtemail.requestFocus();
return;
}
if(TextUtils.isEmpty(phone))
{
txtphone.setError("Enter a valid credential");
txtphone.requestFocus();
return;
}
if(TextUtils.isEmpty(password))
{
txtpassword.setError("Enter a valid credential");
txtpassword.requestFocus();
return;
}
if(password.length()<6)
{
txtpassword.setError("password too short");
txtpassword.requestFocus();
return;
}
firebaseAuth.createUserWithEmailAndPassword(txtemail.getText().toString(), txtpassword.getText().toString())
.addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Driver object = new Driver(
fullname,
phone,
email
);
FirebaseDatabase.getInstance().getReference("Driver")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(object).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
// next.setVisibility(View.GONE);
//back.setVisibility(View.GONE);
Toast.makeText(SignUpActivity.this, "Registeration Complete", Toast.LENGTH_SHORT).show();
startActivity(new Intent(SignUpActivity.this, LoginActivity.class));
} else {
Toast.makeText(SignUpActivity.this, "Account creation failed", Toast.LENGTH_SHORT).show();
}
}
});
//updateUserInfo(pickedImageUri,firebaseAuth.getCurrentUser());
} else {
Toast.makeText(SignUpActivity.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
// ...
}
});////firebase auth
}
});
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
这是我的注册 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.muhammadtehmoor.testing.SignUpActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Sign Up Form"
android:textSize="35dp"
android:gravity="center"
android:textColor="@android:color/black"/>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:textSize="20dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter your Name" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:textSize="20dp"
android:ems="10"
android:inputType="phone"
android:hint="Enter your phone no" />
<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:textSize="20dp"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="Enter your email" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:passwordToggleEnabled="true"
app:hintEnabled="true"
app:passwordToggleDrawable="@drawable/passwordlock">
<EditText
android:id="@+id/editText5"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:textSize="20dp"
android:ems="10"
android:inputType="textPassword"
android:hint="Enter your password" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/btn_submit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Submit"
android:background="@drawable/button_design"
android:layout_marginLeft="100dp"
android:drawableRight="@drawable/ic_send_black_24dp"
android:drawableTint="@color/colorPrimaryDark"
android:paddingRight="10dp"
android:layout_marginTop="20dp"
android:textColor="@android:color/black"/>
<Button
android:id="@+id/btn_cancel"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="@drawable/button_design"
android:drawableRight="@drawable/ic_cancel_black_24dp"
android:drawableTint="@color/colorPrimaryDark"
android:paddingRight="10dp"
android:text="Cancel"
android:textColor="@android:color/black"
tools:ignore="InvalidId" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
最佳答案
请更改
txtname = (EditText) findViewById(R.id.edittext2);
至
txtname = (EditText) findViewById(R.id.editText2);
您在 XML 中使用大写 T 声明了 id,而在 java 中使用小写 t。
关于java - 尝试调用虚拟方法 'android.text.Editable android.widget.EditText.getText()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57137002/
我有一个 Web 应用程序,其中有几个使用 gettext 的翻译。但是现在我已经对应用程序进行了重大重写,虽然大多数字符串是相同的,但也有相当多的字符串被显着更改或删除。 我使用 xgettext
我开始尝试在 C 程序中翻译一些最常用的文本条目 使用 gettext,但在深入研究时,我得到了一点 对所有不同的文件格式有点困惑 因为功能上似乎有些重叠? 我想了解不同格式的概述 .po .pot
gettext 是否有办法警告我有关未包装在 _() 或 N_() 中的字符串? 基本上有没有一种方法可以获取所有不与 xgettext 使用的关键字匹配的字符串的列表。所以,我想要: ! xgett
我们正在使用 Gettext 翻译我们的网站,但最近我们发现我们的翻译团队存在一些问题。 我们有一些像... Hi Bob this evening you win *three* red *ball
我尝试运行 Homebrew 程序,以便在 5 月份的 mac 上安装一些 unix 工具,但开始时遇到问题。我已经删除了 fink 和 macports 并安装了 Homebrew 软件。 (我正在
是否可以使两个或多个 msgid 与一个 msgstr 匹配? 例如,('list.empty')和('list.empty') null') 返回“还没有任何对象。” 如果我在 po 文件中这样写:
所以,我一直在查看 getText() 方法,并且了解到它返回一个 CharSequence。所以你不能只这样做: TextView myTextView = (TextView) findViewB
我正在尝试 gettext 并运行 msginit --locale=en --input=messages.po这就是我所看到的: [... blah ...] Is the following y
我们目前正在国际化我们的平台。平台的代码库和基于该平台构建的产品非常庞大,并且有许多硬编码字符串(除了我们将标签等外部化的 UI)。 我需要一些关于使用 gettext 或 Java i18n 的建议
我用 gettext翻译我的用户界面。我想写符号 %作为字符串中 UI 标题的一部分,但由于它具有特殊含义,因此无法按预期工作。如何转义百分比符号? 最佳答案 使用 %%逃脱%。 关于gettext
我发现字符串 (msgid) 的翻译为空,所有 gettext 工具都会将该字符串视为未翻译。 有解决方法吗?我确实希望有一个空字符串作为此项目的翻译。 最佳答案 由于这似乎是 gettext 规范中
所以我注意到似乎有两种方法可以获取相同的数据,我不确定是否有关于何时应该使用其中任何一种的指南(除了绕过 getResources 可以节省内存,如果你实际上不想多次使用该对象)。但除此之外,我想知道
例如在下面的代码中a和b和c是相等的。 EditText editText; editText = (EditText) findViewById(R.id.edttxt); editText.set
我想从 9 X 9 网格中排列的 81 个文本字段中获取 int 形式的文本,但不想单独进行。我试图将它放在一个循环中,但问题是文本字段名称必须以 a[i][j] 形式显示。 for (i = 0;
我想使用 angular-gettext 在我的应用程序上实现 i18n,我遵循了这个 http://lostechies.com/gabrielschenker/2014/02/11/angular
我遵循了在 Windows 上安装 gettext 的指导,当我在命令提示符中键入 xgettext --version 时,它说它已安装。但是当我想运行这个命令时: python manage.py
所以我正在尝试让 phpmyadmin 在 Windows 7 上运行,我已经完成并安装了所有正确的程序/文件(apache、mySQL、php 等),我在右边有 phpmyadmin 文件夹放在我的
我正在尝试设置 phpMyAdmin,并且我正在关注此 site ,但我收到一个关于“ fatal error :在第 177 行调用 C:\Users\Jarek\mywebsite\phpMyAd
我需要解析我的 php 文件,其中使用了多个文本域。我只想解析一个特定的域(其他域已经被翻译)如何让 Poedit 做到这一点? 是否需要编译绑定(bind)到某个文本域的mo文件?如果是的话,如何在
当我尝试在 vala 中使用 gettext 时,我没有收到来自 vala 的错误或警告,但我从 c 编译器收到以下错误: /usr/include/glib-2.0/glib/gi18n-lib.h
我是一名优秀的程序员,十分优秀!