954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Error Checking for user input

Hello all, is that possible to help me out with Error Checking for user input? I am developing a peg solitaire program and now need a error checking for user input or for input file.

Either use try and catch.. or making another method.. can anyone give a me a hint or help me out here please.

Regards

guessvic
Newbie Poster
2 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

what kind of error checking? like when the user tries to put a king on a 7? you can use a method to check that and if the user is being a moron, then you can display a joptionpane or you can throw one of your own exceptions which will have to be dealt with. something like InvalidMoveException.

Easter Bunny
Junior Poster in Training
57 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
 

For something like that I would say some if else statements would work. Like:

if (!card slot is already taken)
{
      //do something
}
else
{
    //do something else
}


Of course it would be cool to experiment making your own exception as EB said.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

Thanks for all replies. I just got it working with try and catch exception, my problem was I use try {}catch (IOException e) {} instead of just use catch (Exception e) {}

The input only reads: From To
Exception prevent any invalid input such as "jslkfjsdlkfjlkd".

guessvic
Newbie Poster
2 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

import javax.swing.*;

public class aaa{
public static void main(String[]args){

String username;
int i;
String password;
int j;

String[]uname={"geerthan"};
String[]pwd={"19881108"};
password.setEchoChar('*');

boolean loop=true;
while(loop){
username=JOptionPane.showInputDialog("Enter the Username");
if(username.equals("")){
String message="Please Enter the Username";
JOptionPane.showMessageDialog(new JFrame(),message,"Warning",JOptionPane.WARNING_MESSAGE);
}
else
{
password=JOptionPane.showInputDialog("Enter the Password");
if(password.equals("")){
String message="Please Enter the Password";
JOptionPane.showMessageDialog(new JFrame(),message,"WARNING",JOptionPane.WARNING_MESSAGE);
}
else
{

for(i=0;i

geerthan08
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You