It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

Issue Related to command line arguments

Issue Related to command line arguments

Postby ajayyaduwanshi on Sat Oct 13, 2007 5:47 am

Hi All
I am having issue with command line arguments below is my program, when I passed arguments like 800PBXMAIN 2 3 4 5 6 7, I just got the out put of these lines

System.out.println ("Incorrect number of errors!");
System.out.println ("Usage: java PBXMain filename");
System.exit(0);

While the program runs properly and dedugging is also with no issue.

package com.pbx.main;

import java.net.*;
import java.io.*;
import com.pbx.core.*;
import java.util.*;


public class PBXMain {

/**
* Properties file
*/
private static final String CONFIG_BUNDLE_NAME = "properties.ApplicationConfigurations";

/**
* Properties file
*/
private static final String CONFIG_BUNDLE_NAME2 = "properties.PBXLogging";


/**
* For holding the PropertyResourceBundle
*/
private static PropertyResourceBundle configBundle;




static {
try {
configBundle = (PropertyResourceBundle) PropertyResourceBundle.
getBundle(CONFIG_BUNDLE_NAME);

} catch (Exception ex) {

ex.printStackTrace();
}
}

/**
* jarFilePath
*/
private static String jarFilePath = configBundle.getString("800PBXMAIN");


public PBXMain() {

}

public static void main(String[] args) {
PBXMain pbxmain = new PBXMain();

Call call =null;

if (args.length >= 0) {
System.out.println ("Incorrect number of errors!");
System.out.println ("Usage: java PBXMain filename");
System.exit(0);
}



int startint = args[0].indexOf("/");

String jarFile = args[0].trim() + ".jar";

int endint = args[0].indexOf("_");

args[0] = args[0].substring(startint + 1 , endint);

String mainClass = args[0].trim();

String iDNum =args[1].trim();

String itemID =args[2].trim();

String pinNO =args[3].trim();

String pinNO1 =args[4].trim();

String pinNO2 =args[5].trim();

String pinNO3 =args[6].trim();




try {
// Load all classes from jar file without giving classpath
URL url = new URL("jar:file:" + jarFilePath + "/" + jarFile + "!/");

JarURLConnection jarConnection = (JarURLConnection) url.openConnection();

URL[] urls = new URL[] {url};

ClassLoader classLoader = new URLClassLoader(urls);

CallHandler callobject =(CallHandler) (classLoader.loadClass(mainClass).newInstance());

try{ call = new Call();

} catch (Exception ex){

ex.printStackTrace();
}

try{
callobject.answerCall(call,iDNum,itemID,pinNO,pinNO1,pinNO2,pinNO3);
} catch (Exception ex){

ex.printStackTrace();
}


} catch (InstantiationException ie) {
ie.printStackTrace();
/*

( "Raised InstantiationException while reading protocol. " +
ie.getMessage());
*/

} catch (ClassCastException cce) {
cce.printStackTrace();

/*
( "Raised ClassCastException while reading protocol. " +
cce.getMessage());
*/

} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();

/* ("Raised ClassNotFoundException while reading protocol. " +
cnfe.getMessage());
*/
}

catch (FileNotFoundException fe) {
fe.printStackTrace();

/* ("Raised FileNotFoundException while reading protocol. " +
fe.getMessage());
*/

} catch (SecurityException se) {
se.printStackTrace();

/* ("Raised SecurityException while reading protocol. " +
se.getMessage());
*/

} catch (IOException ioe) {
ioe.printStackTrace();

/* ("Raised IOException while reading protocol. " +
ioe.getMessage());
*/

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

/* ("Raised Exception while reading protocol. " +
e.getMessage());
*/
}

}
}



Sorry for confusion.

Even after putting Sytem.out.println("args[1]" + iDNum);

I am not getting the command line argument printed in the console..

Please help me with this

Thanks & Regards

Ajay Singh Yaduwanshi
ajay.yaduwanshi@gmail.com
ajayyaduwanshi
 
Posts: 0
Joined: Sat Oct 13, 2007 5:44 am

Who is online

Users browsing this forum: No registered users and 1 guest