I have a button which works according to its function when user enters a number in an EditText. However,when my EditText is numerically empty,when i click on the same button, it make my app stop working. Any help?
Please consider the "numerically" part because i could not find any answers to my query?
code
public void send(View v){
String text = edittext.getText().toString();
if (text.matches("")) {
myButton.setEnabled(false);
return;
}
}
xml
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:inputType="number"
android:layout_height="wrap_content"
android:hint="Enter:"
android:id="@+id/edittext"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:onClick="send"
android:id="@+id/btn"/>
</LinearLayout>
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
logcat
01-16 10:49:15.208 3014-3014/? I/SELinux: Function: selinux_android_load_priority [0], There is no sepolicy file.
01-16 10:49:15.208 3014-3014/? I/SELinux: Function: selinux_android_load_priority [1], There is no sepolicy version file.
01-16 10:49:15.208 3014-3014/? I/SELinux: Function: selinux_android_load_priority , priority version is VE=GOOGLE_POLICY
01-16 10:49:15.208 3014-3014/? I/SELinux: selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
01-16 10:49:15.208 3014-3014/? E/SELinux: [DEBUG] seapp_context_lookup: seinfoCategory = default
01-16 10:49:15.208 3014-3014/? E/SELinux: [DEBUG] seapp_context_lookup: seinfoCategory = default
01-16 10:49:15.208 3014-3014/? D/dalvikvm: Late-enabling CheckJNI
01-16 10:49:15.298 3014-3014/com.example.dell.uomopenday I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
01-16 10:49:15.298 3014-3014/com.example.dell.uomopenday W/dalvikvm: VFY: unable to resolve virtual method 254: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
01-16 10:49:15.298 3014-3014/com.example.dell.uomopenday D/dalvikvm: VFY: replacing opcode 0x6e at 0x00c8
01-16 10:49:15.308 3014-3014/com.example.dell.uomopenday I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzj
01-16 10:49:15.308 3014-3014/com.example.dell.uomopenday W/dalvikvm: VFY: unable to resolve virtual method 549: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
01-16 10:49:15.308 3014-3014/com.example.dell.uomopenday D/dalvikvm: VFY: replacing opcode 0x6e at 0x000b
01-16 10:49:15.358 3014-3037/com.example.dell.uomopenday I/GMPM: App measurement is starting up
01-16 10:49:15.358 3014-3037/com.example.dell.uomopenday E/GMPM: getGoogleAppId failed with status: 10
01-16 10:49:15.368 3014-3037/com.example.dell.uomopenday E/GMPM: Uploading is not possible. App measurement disabled
01-16 10:49:15.378 3014-3014/com.example.dell.uomopenday W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
01-16 10:49:15.378 3014-3014/com.example.dell.uomopenday I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
01-16 10:49:15.378 3014-3014/com.example.dell.uomopenday W/dalvikvm: VFY: unable to resolve interface method 19469: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
01-16 10:49:15.378 3014-3014/com.example.dell.uomopenday D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-16 10:49:15.378 3014-3014/com.example.dell.uomopenday I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
01-16 10:49:15.378 3014-3014/com.example.dell.uomopenday W/dalvikvm: VFY: unable to resolve interface method 19473: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
01-16 10:49:15.378 3014-3014/com.example.dell.uomopenday D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-16 10:49:15.408 3014-3014/com.example.dell.uomopenday I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
01-16 10:49:15.408 3014-3014/com.example.dell.uomopenday W/dalvikvm: VFY: unable to resolve virtual method 627: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-16 10:49:15.408 3014-3014/com.example.dell.uomopenday D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-16 10:49:15.408 3014-3014/com.example.dell.uomopenday I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
01-16 10:49:15.408 3014-3014/com.example.dell.uomopenday W/dalvikvm: VFY: unable to resolve virtual method 649: Landroid/content/res/TypedArray;.getType (I)I
01-16 10:49:15.408 3014-3014/com.example.dell.uomopenday D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-16 10:49:15.508 3014-3014/com.example.dell.uomopenday I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
OpenGL ES Shader Compiler Version: E031.24.00.08
Build Date: 03/21/14 Fri
Local Branch: AU200+patches_03212014
Remote Branch:
Local Patches:
Reconstruct Branch:
01-16 10:49:15.758 3014-3014/com.example.dell.uomopenday D/OpenGLRenderer: Enabling debug mode 0
buttononclick
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Search = new ArrayList<>();
int points = Integer.parseInt(edittext.getText().toString());
for (int i = 0; i < courses.length; i++) {
Course c2 = courses[i];
if (c2.getPoints() <= points) {
Search.add(c2);
}
}
Course searching [] = new Course[Search.size()];
searching = Search.toArray(searching);
adapter = new listAdapter(MainActivity.this, searching);
myList.setAdapter(adapter);
}
String text = edittext.getText().toString();
if (text.matches("")) {
button.setEnabled(false);
return;
}
});