Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

compilation error

  Asked By: Carlton    Date: Dec 12    Category: Java    Views: 910
  

I am trying to run this code. It is giving me the error:
Exception in thread "main" java.lang.NoClassDefFoundError: aim_basic

package aim;

import javax.net.ssl.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.security.*;


public class aim_basic {

public static void main(String[] Args){

try{

StringBuffer sb = new StringBuffer();

sb.append("x_login=yourloginid&"); // replace with
your own
sb.append("x_password=kjshdkjshfkdshhd&"); // replace with
your own
sb.append("x_version=3.1&");
sb.append("x_test_request=TRUE&"); // for testing
sb.append("x_method=CC&");
sb.append("x_type=AUTH_ONLY&");
sb.append("x_amount=1.00&");
sb.append("x_delim_data=TRUE&");
sb.append("x_delim_char=|&");
sb.append("x_relay_response=FALSE&");

sb.append("x_description=Java Transaction&");


// open secure connection
URL url = new URL("https://mygatewaysite/trfile.dll");

URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setUseCaches(false);

connection.setRequestProperty("Content-Type","application/x-www-
form-urlencoded");

// POST the data in the string buffer
DataOutputStream out = new DataOutputStream(
connection.getOutputStream() );
out.write(sb.toString().getBytes());
out.flush();
out.close();

// process and read the gateway response
BufferedReader in = new BufferedReader(new InputStreamReader
(connection.getInputStream()));
String line;
line = in.readLine();
in.close(); // no more data
System.err.println(line);

Vector ccrep = split("|", line);

System.out.print("Response Code: ");
System.out.println(ccrep.elementAt(0));
System.out.print("Human Readable Response Code: ");
System.out.println(ccrep.elementAt(3));
System.out.print("Approval Code: ");
System.out.println(ccrep.elementAt(4));
System.out.print("Trans ID: ");
System.out.println(ccrep.elementAt(6));
System.out.print("MD5 Hash Server: ");
System.out.println(ccrep.elementAt(37));


}catch(Exception e){
e.printStackTrace();
}
}


// utility functions
public static Vector split(String pattern, String in){
int s1=0, s2=-1;
Vector out = new Vector(30);
while(true){
s2 = in.indexOf(pattern, s1);
if(s2 != -1){
out.addElement(in.substring(s1, s2));
}else{
//the end part of the string (string not
pattern terminated)
String _ = in.substring(s1);
if(_ != null && !_.equals("")){
out.addElement(_);
}
break;
}
s1 = s2;
s1 += pattern.length();
}
return out;
}

public static String toHexString ( byte[] b ){
StringBuffer sb = new StringBuffer( b.length * 2 );
for ( int i=0 ; i<b.length ; i++ )
{
// look up high nibble char
sb.append( hexChar [ ( b[ i] & 0xf0 ) >>> 4 ] ) ;

// look up low nibble char
sb.append( hexChar [ b[ i] & 0x0f ] ) ;
}
return sb.toString() ;
}

// table to convert a nibble to a hex character
static char[] hexChar = {
'0' , '1' , '2' , '3' ,
'4' , '5' , '6' , '7' ,
'8' , '9' , 'A' , 'B' ,
'C' , 'D' , 'E' , 'F' }
;
}

Share: 

 

10 Answers Found

 
Answer #1    Answered By: Kelly Bell     Answered On: Dec 12

This might be a problem with classpath.
just unset ur class  path, I mean echo %classpath% should be %classpath%
and try. It might work. else try experimenting
with just the classpath variable. This will solve this problem

make sure your classpath has a .
i.e..
.;(path of the to other jar files)

CLASSPATH environment variable should start with '.;'

e.g. CLASSPATH=".;C:\path1;C:\path2"

 
Answer #2    Answered By: Angel Harris     Answered On: Dec 12

There is actually someone saying that it does not matter if you use args or
Args.
And he has the gutes to say that the previous answer (which was correct) is
rubbish.
Ignorance is bliss.
So Mr. Singh, here is your homework:
Write a class  with a method public  static void  main(String[] Args) and then
try to run  it.
I think with your little knowledge of Java you might be surprised what the
result will be.
The rest of us here will already know the answer. But you should try it.

 
Answer #3    Answered By: Cheri Garcia     Answered On: Dec 12

Because you are using a package in your program, just remember these points
- You have to set classpath to the folder containing your package.
- You have to compile ur program with full directory information.
- While running also u have to prefix you package name.

(by the error  message u attached i can make out that u forgot to prefix ur
package name with class  name)

fox ex. if your program is in "C:\JavaPrograms" folder & ur package name is
"aim" --try this

1. You have to set classpath to the folder containing the package, so
set classpath=%classpath%;C:\JavaPrograms;

2. Compiling
javac -d C:\JavaPrograms aim_basic.java

3. Running
java aim.aim_basic

 
Answer #4    Answered By: Julian Long     Answered On: Dec 12

I think the problem is not in your package path, I mean try that too,
but I get the same error  whenever lets say i have file
Main.java and inside is a class  called class House

Now when you compile it is javac Main.java,
but when you run  you do not call java  Main.java or java Main
You must call the name of the class which in this case is House
so
java House
should compile without error

Remeber name of the file when you compile but name of the Driver class
(the one that executes main() ) when running the application

 
Answer #5    Answered By: Omar Walker     Answered On: Dec 12

I once had the error  exception in main  subroutine. All of your code  seems
to be correct;however,you ended up compiling in the wrong subfolder path.

A way to correct this is to go to the Windows Explorer (if you have Windows OS)
and search for the file name, (aim_basic.java) that is the same name as the
class.

If you don't have the filename, then save the java  filename as aim_basic.java
and compile it from there.

Hopefully, one of these solutions could help.

 
Answer #6    Answered By: Bonnie Hughes     Answered On: Dec 12

one more suggestion: try
public static  void main(String[] args){
instead of
public static void  main(String[] Args){

I mean, spell the "args" with a lowercase 'a' instead of an
uppercase 'A'. I don't know for sure, but I would at least try it.

 
Answer #7    Answered By: Percy Morgan     Answered On: Dec 12

I don't think the case of letters matters here. 'Args'
is just an identifier and the programmer is free to
use any case of letters in identifier names.

 
Answer #8    Answered By: Aaron Kennedy     Answered On: Dec 12

i think u would have not set the classpath correctly..this may also cause the
NoClassDefFoundError.I think so..hav a try on it

 
Answer #9    Answered By: Ana Silva     Answered On: Dec 12

there is no difference between
public static  void main(String[] args){
and
public static void  main(String[] Args){

args and Args are just variable.......

for solving ur problem u just check ur class  path , i m sure that its not
finding ur class in ur class path ...... just put (dot .; ) in ur classpath
.....

 
Answer #10    Answered By: Dustin Dean     Answered On: Dec 12

the error  that u have stated is because the class  file
could not be located..
it can due to three reasons:
1) the file is getting compiled but cannot be executed
2) the package that u have created could not be traced
3) the aim_basic file is present somewhere else and
could not be traced....

args being in uppercase or lowercase will not create
any probs

 
Didn't find what you were looking for? Find more on compilation error Or get search suggestion and latest updates.




Tagged: