-2

我已经为名称、体重和身高创建了三个编辑文本视图,名称采用 PersonName 值,体重和身高采用数字值,我正在使用以下代码检查 EditText 视图是否为空。正如您在下面看到的,如果代码块为空,我尝试了所有方法来获取,但是当我将 editText 视图留空时,应用程序仍然崩溃。什么可能出错?

if(getName.equals("") || getName.length()<=2 || getName.equals(null) || getName.trim().length()<1)
                        {
                            NameWarning.setText("Please Enter Your Name Correctly");
                        }
                        else if(heightcm.getText().toString().equals("") || heightcm.getText()==null || heightcm.getText().toString().equals(null) || heightcm.getText().toString().trim().length()<1)
                        {
                            HeightWarning.setText("Please Enter Your Height Correctly");
                        }
                        else if(getWeight.getText().toString().equals("") || getWeight.getText().toString()==null || getWeight.getText().toString().equals(null) || getWeight.getText().toString().trim().length()<1)
                        {
                            WeightWarning.setText("Please Enter Your Weight Correctly");
                        }
                        else if (getName.equals("") || heightcm.getText().toString().equals("") || getWeight.getText().toString().equals("") || getName==null || heightcm.getText().toString()==null || getWeight.getText().toString()==null || getName.equals(null) || heightcm.getText().toString().equals(null) || getWeight.getText().toString().equals(null)
                                || getName.trim().length()<1 || heightcm.getText().toString().trim().length()<1 || getWeight.getText().toString().trim().length()<1)
                        {
                            NameWarning.setText("Please Fill Your Details Correctly !!");
                            HeightWarning.setText("Please Fill Your Details Correctly !!");
                            WeightWarning.setText("Please Fill Your Details Correctly !!");
                        }

当应用程序崩溃时,我正在获取此文件

// Compiled from Integer.java (version 1.5 : 49.0, super bit)
// Signature: Ljava/lang/Number;Ljava/lang/Comparable<Ljava/lang/Integer;>;
public final class java.lang.Integer extends java.lang.Number implements java.lang.Comparable {

  // Field descriptor #11 I
  public static final int MAX_VALUE = 2147483647;

  // Field descriptor #11 I
  public static final int MIN_VALUE = -2147483648;

  // Field descriptor #11 I
  public static final int SIZE = 32;

  // Field descriptor #19 Ljava/lang/Class;
  // Signature: Ljava/lang/Class<Ljava/lang/Integer;>;
  public static final java.lang.Class TYPE;

  // Method descriptor #23 (I)V
  // Stack: 3, Locals: 2
  public Integer(int value);
     0  aload_0 [this]
     1  invokespecial java.lang.Number() [1]
     4  new java.lang.RuntimeException [2]
     7  dup
     8  ldc <String "Stub!"> [3]
    10  invokespecial java.lang.RuntimeException(java.lang.String) [4]
    13  athrow
      Line numbers:
        [pc: 0, line: 6]
      Local variable table:
        [pc: 0, pc: 14] local: this index: 0 type: java.lang.Integer
        [pc: 0, pc: 14] local: value index: 1 type: int

  // Method descriptor #30 (Ljava/lang/String;)V
  // Stack: 3, Locals: 2
  public Integer(java.lang.String string) throws java.lang.NumberFormatException;
     0  aload_0 [this]
     1  invokespecial java.lang.Number() [1]
     4  new java.lang.RuntimeException [2]
     7  dup
     8  ldc <String "Stub!"> [3]
    10  invokespecial java.lang.RuntimeException(java.lang.String) [4]
    13  athrow
      Line numbers:
        [pc: 0, line: 7]
      Local variable table:
        [pc: 0, pc: 14] local: this index: 0 type: java.lang.Integer
        [pc: 0, pc: 14] local: string index: 1 type: java.lang.String

  // Method descriptor #36 ()B
  // Stack: 3, Locals: 1
  public byte byteValue();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 8]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer

  // Method descriptor #38 (Ljava/lang/Integer;)I
  // Stack: 3, Locals: 2
  public int compareTo(java.lang.Integer object);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 9]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer
        [pc: 0, pc: 10] local: object index: 1 type: java.lang.Integer

  // Method descriptor #41 (Ljava/lang/String;)Ljava/lang/Integer;
  // Stack: 3, Locals: 1
  public static java.lang.Integer decode(java.lang.String string) throws java.lang.NumberFormatException;
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 10]
      Local variable table:
        [pc: 0, pc: 10] local: string index: 0 type: java.lang.String

  // Method descriptor #43 ()D
  // Stack: 3, Locals: 1
  public double doubleValue();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 11]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer

  // Method descriptor #45 (Ljava/lang/Object;)Z
  // Stack: 3, Locals: 2
  public boolean equals(java.lang.Object o);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 12]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer
        [pc: 0, pc: 10] local: o index: 1 type: java.lang.Object

  // Method descriptor #49 ()F
  // Stack: 3, Locals: 1
  public float floatValue();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 13]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer

  // Method descriptor #41 (Ljava/lang/String;)Ljava/lang/Integer;
  // Stack: 3, Locals: 1
  public static java.lang.Integer getInteger(java.lang.String string);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 14]
      Local variable table:
        [pc: 0, pc: 10] local: string index: 0 type: java.lang.String

  // Method descriptor #51 (Ljava/lang/String;I)Ljava/lang/Integer;
  // Stack: 3, Locals: 2
  public static java.lang.Integer getInteger(java.lang.String string, int defaultValue);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 15]
      Local variable table:
        [pc: 0, pc: 10] local: string index: 0 type: java.lang.String
        [pc: 0, pc: 10] local: defaultValue index: 1 type: int

  // Method descriptor #53 (Ljava/lang/String;Ljava/lang/Integer;)Ljava/lang/Integer;
  // Stack: 3, Locals: 2
  public static java.lang.Integer getInteger(java.lang.String string, java.lang.Integer defaultValue);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 16]
      Local variable table:
        [pc: 0, pc: 10] local: string index: 0 type: java.lang.String
        [pc: 0, pc: 10] local: defaultValue index: 1 type: java.lang.Integer

  // Method descriptor #55 ()I
  // Stack: 3, Locals: 1
  public int hashCode();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 17]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer

  // Method descriptor #55 ()I
  // Stack: 3, Locals: 1
  public int intValue();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 18]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer

  // Method descriptor #58 ()J
  // Stack: 3, Locals: 1
  public long longValue();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 19]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer

  // Method descriptor #60 (Ljava/lang/String;)I
  // Stack: 3, Locals: 1
  public static int parseInt(java.lang.String string) throws java.lang.NumberFormatException;
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 20]
      Local variable table:
        [pc: 0, pc: 10] local: string index: 0 type: java.lang.String

  // Method descriptor #61 (Ljava/lang/String;I)I
  // Stack: 3, Locals: 2
  public static int parseInt(java.lang.String string, int radix) throws java.lang.NumberFormatException;
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 21]
      Local variable table:
        [pc: 0, pc: 10] local: string index: 0 type: java.lang.String
        [pc: 0, pc: 10] local: radix index: 1 type: int

  // Method descriptor #64 ()S
  // Stack: 3, Locals: 1
  public short shortValue();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 22]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer

  // Method descriptor #66 (I)Ljava/lang/String;
  // Stack: 3, Locals: 1
  public static java.lang.String toBinaryString(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 23]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #66 (I)Ljava/lang/String;
  // Stack: 3, Locals: 1
  public static java.lang.String toHexString(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 24]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #66 (I)Ljava/lang/String;
  // Stack: 3, Locals: 1
  public static java.lang.String toOctalString(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 25]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #71 ()Ljava/lang/String;
  // Stack: 3, Locals: 1
  public java.lang.String toString();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 26]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.Integer

  // Method descriptor #66 (I)Ljava/lang/String;
  // Stack: 3, Locals: 1
  public static java.lang.String toString(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 27]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #72 (II)Ljava/lang/String;
  // Stack: 3, Locals: 2
  public static java.lang.String toString(int i, int radix);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 28]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int
        [pc: 0, pc: 10] local: radix index: 1 type: int

  // Method descriptor #41 (Ljava/lang/String;)Ljava/lang/Integer;
  // Stack: 3, Locals: 1
  public static java.lang.Integer valueOf(java.lang.String string) throws java.lang.NumberFormatException;
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 29]
      Local variable table:
        [pc: 0, pc: 10] local: string index: 0 type: java.lang.String

  // Method descriptor #51 (Ljava/lang/String;I)Ljava/lang/Integer;
  // Stack: 3, Locals: 2
  public static java.lang.Integer valueOf(java.lang.String string, int radix) throws java.lang.NumberFormatException;
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 30]
      Local variable table:
        [pc: 0, pc: 10] local: string index: 0 type: java.lang.String
        [pc: 0, pc: 10] local: radix index: 1 type: int

  // Method descriptor #75 (I)I
  // Stack: 3, Locals: 1
  public static int highestOneBit(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 31]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #75 (I)I
  // Stack: 3, Locals: 1
  public static int lowestOneBit(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 32]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #75 (I)I
  // Stack: 3, Locals: 1
  public static int numberOfLeadingZeros(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 33]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #75 (I)I
  // Stack: 3, Locals: 1
  public static int numberOfTrailingZeros(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 34]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #75 (I)I
  // Stack: 3, Locals: 1
  public static int bitCount(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 35]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #81 (II)I
  // Stack: 3, Locals: 2
  public static int rotateLeft(int i, int distance);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 36]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int
        [pc: 0, pc: 10] local: distance index: 1 type: int

  // Method descriptor #81 (II)I
  // Stack: 3, Locals: 2
  public static int rotateRight(int i, int distance);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 37]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int
        [pc: 0, pc: 10] local: distance index: 1 type: int

  // Method descriptor #75 (I)I
  // Stack: 3, Locals: 1
  public static int reverseBytes(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 38]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #75 (I)I
  // Stack: 3, Locals: 1
  public static int reverse(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 39]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #75 (I)I
  // Stack: 3, Locals: 1
  public static int signum(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 40]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #87 (I)Ljava/lang/Integer;
  // Stack: 3, Locals: 1
  public static java.lang.Integer valueOf(int i);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 41]
      Local variable table:
        [pc: 0, pc: 10] local: i index: 0 type: int

  // Method descriptor #88 (Ljava/lang/Object;)I
  // Stack: 2, Locals: 2
  public bridge synthetic int compareTo(java.lang.Object x0);
    0  aload_0 [this]
    1  aload_1 [x0]
    2  checkcast java.lang.Integer [5]
    5  invokevirtual java.lang.Integer.compareTo(java.lang.Integer) : int [6]
    8  ireturn
      Line numbers:
        [pc: 0, line: 2]
      Local variable table:
        [pc: 0, pc: 9] local: this index: 0 type: java.lang.Integer
        [pc: 0, pc: 9] local: x0 index: 1 type: java.lang.Object

  // Method descriptor #91 ()V
  // Stack: 1, Locals: 0
  static {};
    0  aconst_null
    1  putstatic java.lang.Integer.TYPE : java.lang.Class [7]
    4  return
      Line numbers:
        [pc: 0, line: 47]
}
4

1 回答 1

0

试试这种方式:

 if(getName.getText.toString().equals("") || getName.getText().toString().length()<=2 || getName.getText().toString().equals(null) || getName.getText().toString().trim().length()<1)
                    {
                        NameWarning.setText("Please Enter Your Name Correctly");
                    }
                   ..................

也用于.getText().toString()您的第一个 if 条件。

于 2013-01-20T06:50:02.223 回答