- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试为 ExpenseName 和 ExpenseCost Edittext 创建验证,以便如果没有用户输入,它将提醒用户输入一些数据,并且 boolean 值中的“文本”也有错误,因为它是红色的。我从另一个 .java 复制了代码,所以我很确定它工作得很好
package com.example.back4app.userregistrationexample.Classes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.back4app.userregistrationexample.R;
public class ExpenseActivity extends AppCompatActivity {
private EditText ExpenseName;
private EditText ExpenseCost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_expense);
ExpenseName = (EditText) findViewById(R.id.txt_expensename);
ExpenseCost = (EditText) findViewById(R.id.txt_expensecost);
final Button btn_addexpense = findViewById(R.id.btn_addexpense);
btn_addexpense.setOnClickListener(new View.OnClickListener()); {
@Override
public void onClick(View v) {
//Validating the log in data
boolean validationError = false;
StringBuilder validationErrorMessage = new StringBuilder("Please, insert ");
if (isEmpty(ExpenseCost)) {
validationError = true;
validationErrorMessage.append("the cost of the expense");
}
if (isEmpty(ExpenseName)) {
if (validationError) {
validationErrorMessage.append(" and ");
}
validationError = true;
validationErrorMessage.append("the name of the expense");
}
}
}
private boolean isEmpty(EditText text) {
if (text.getText().toString().trim().length() > 0) {
return false;
} else {
return true;
}
}
}
}
我尝试将“(”和“)”放在“文本”之外,但它仍然是红色,我还尝试将“isEmpty”更改为任何其他名称,因为它可能正在另一个.java上读取,但仍然发生同样的事情。另外,我尝试重建项目和清理项目,但没有任何效果,我还尝试使缓存无效/重新启动,因为我读到有人说 Android 出现这样的错误并不罕见。我的代码有问题吗?
编辑:
好的。所以我关闭了 OnClickListener 但现在更多“错误:';'”出现“expected”并且“OnClickListener”是抽象的;无法实例化”
最佳答案
您没有在发布的代码中关闭 onCreate
或 setOnClickListener
。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_expense);
ExpenseName = (EditText) findViewById(R.id.txt_expensename);
ExpenseCost = (EditText) findViewById(R.id.txt_expensecost);
final Button btn_addexpense = findViewById(R.id.btn_addexpense);
btn_addexpense.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Validating the log in data
boolean validationError = false;
StringBuilder validationErrorMessage = new StringBuilder("Please, insert ");
if (isEmpty(ExpenseCost)) {
validationError = true;
validationErrorMessage.append("the cost of the expense");
}
if (isEmpty(ExpenseName)) {
if (validationError) {
validationErrorMessage.append(" and ");
}
validationError = true;
validationErrorMessage.append("the name of the expense");
}
}
}); // here
}
private boolean isEmpty(EditText text) {
if (text.getText().toString().trim().length() > 0) {
return false;
} else {
return true;
}
}
关于java - 如何修复 "Error: ' ;' expected"或 "Error: ' )' expected"以及 boolean 值中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54614112/
我正在尝试从文本文件构建 boolean 值[][]。我正在读取每个字符,存储在 ArrayList 中(1 为真,0 为假)。我试过 ArrayList,但出现编译错误,意外元素。因此,我构建了一个
我想知道编程语言中的运算符优先级是否取决于实现,还是所有语言都遵循固定的规则。并且,如果可能的话,您可以先排序以下具有最高优先级的运算符吗:AND,OR,NOT,XOR。 最佳答案 我在Google上
这是同样的事情,对吗?还是有细微的差别?我只是想确保我没有误解任何事情。 最佳答案 通过简单地将 AND 替换为 OR 以及将 OR 替换为 AND 即可生成 boolean 对偶。补码本身不受影响,
我想这对于大多数优秀的程序员来说是微不足道的,但我已经习惯使用 true 进行编程。和 false 2、当我遇到0和1的时候,我永远记不住哪一个是真的,哪一个是假的。 有什么建议? 1好:I mean
我正在尝试将此 Java 示例转换为 Kotlin: Gson gson = new GsonBuilder() .registerTypeAdapter(Boolean.class,
下面的代码打印 true。 public static void main(String[] args) { Boolean test = false; test =
我在处理应该导致在 iReport 中显示或隐藏 strip 的表达式时遇到困难。 这些是我拥有的变量: Integer mainGroupInt = Integer.valueOf(5); Inte
以下编码错误可能是因为 Boolean equals(Object) 方法不需要 boolean/Boolean 参数: private void foo() { Boolean isSome
我想简化一个 boolean 表达式。 表达式是这样的 X1 xor (X2 || X3 && X4 || x5) 如何使用 boolean 代数规则简化此表达式。 而且我想将上面的 boolean
我正在使用一些工具,它可以确定特定事务是否成功的唯一方法是它是否通过了各种检查。但是,它的方式有限制,一次只能做一次检查,而且必须是顺序的。一切都必须从左到右计算。 例如, A || C && D 它
在大多数编程语言中,1和 0可以用来代替 True和 False .然而,根据我的经验,整数似乎总是更容易使用。 以下是我的意思的一些示例: if x is True: x = False else:
我有一个 boolean 方程,想简化它。帮忙解决一下。 bool needLoad = isA || (!isA && !isB); 之后我使用 if (needLoad){ if (
我认为这始终是正确的 x || (x && y) 相当于 x 如果是这样,那条法律叫什么?我什至不知道如何通过 Google 搜索该信息。 最佳答案 它被称为 Redundancy Law . A +
是否有任何现有的方法或功能模块可以有效地翻转 boolean 值? 如果我必须定义自己的实用方法,我想出了一个简单的实现,但我想知道这是否是最有效的方法: IF iv_bool = abap_true
我有这个表达式:X'YZ'+X'YZ+XY'Z'+XYZ'+XYZ('表示不是)我知道答案是 Y+XZ' 但我陷入了最后一部分。有人可以帮我吗? 这是我到目前为止得到的: X'YZ' + X'YZ +
openCL 支持 boolean 变量吗?我目前正在使用 JOCL (java) 编写我的 openCL 调用代码,但我没有看到任何有关 boolean 值的信息。 最佳答案 tl;dr:是的,但您
我认为这是对的 x || (x && y) 相当于 x 如果是这样,那条法律叫什么?我什至不确定我会如何使用 Google。 最佳答案 它叫做 Redundancy Law . A + A·B = A
我有一些功能,例如 (A and ( B or c)) or (D and E and (F or H or R or P ))) 我想将该函数转换为仅包含 and 操作的函数(当然如果可能的话)我发
我参加了编程面试,由 3 名面试官组成,每人 45 分钟。虽然前两位面试官给了我 2-3 个简短的编码问题(即反向链表、使用 rand(5) 实现 rand(7) 等),但第三位面试官使用了整个时间段
如果我只想检查某事是否不可能(即,我不会使用类似 if(possible) 的东西),我应该将 boolean 值命名为 notPossible并使用 if(notPossible)或者我应该命名它p
我是一名优秀的程序员,十分优秀!