I have compiled this program. I got following errors:
Exception in thread "main" java.lang.NoClassDefFoundError: Utils
(wrong name: utils/Utils)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at java.security.SecureClassLoader.defineClass
(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass
(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass
(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal
(ClassLoader.java:313)
What is the problem?
---------------------------
package utils;
import java.text.*;
import java.io.*;
import java.util.*;
public class Utils
{
// Variables
// Main function
public void main()
{
String pNum = "New York", pDate = "30/02/2002",
pFormat = "DD/MM/YYYY", pEmail = "NY@...";
if (isValidNum(pNum))
{ System.out.println("Valid string : " + pNum); }
else { System.out.println("Invalid string : " + pNum); }
if (isValidDate(pDate, pFormat))
{ System.out.println("Valid date : " + pDate); } else
{ System.out.println("Invalid date : " + pDate); }
if (isValidEmail(pEmail))
{ System.out.println("Valid email : " + pEmail); }
else { System.out.println("Invalid email : " + pEmail); }
}
// Functions
public boolean isValidNum(String pNum)
{
try {
Integer.parseInt(pNum);
return true;
}
catch(NumberFormatException e){
return false;
}
}
public boolean isValidDate(String pDate, String pFormat)
{
try
{
DateFormat dateformatfrm = new SimpleDateFormat
(pFormat);
System.out.println(dateformatfrm.parse(pDate));
return true;
}
catch (ParseException e)
{
System.out.println(e);
}
return false;
}
public boolean isValidEmail(String pEmail)
{
int vIndex1, vIndex2;
vIndex1 = pEmail.indexOf("@");
vIndex2 = pEmail.indexOf(".", vIndex1);
if ( (vIndex1 > 0) && (vIndex2 > vIndex1) )
{
return true;
}
else
{
return false;
}
}
}