Results 1 to 13 of 13
  1. #1
    tajfun010 is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Unhappy java client in corba problem

    hi
    i am beaginer in java and I have a problem that can not get rid of more than 2 weeks. I work on the example from the book "Teach Yourself CORBA in 14Days" except that I use a java compiler idlj there used Visibroker. application is called StockMarket. server is ok, but there are problems with the Client Applications. I try to compile I get an error: connect (java.lang.String []) in StockMarket.StockClient can not be applied to (). this is the StockClient.java code:

    Java Code:
    import StockMarket.*;
    import org.omg.CosNaming.*;
    import org.omg.CosNaming.NamingContextPackage.*;
    import org.omg.CORBA.*;
    
    public class StockClient {
    	StockClient() {
    	}
    
    public void run() {
    	
    	connect();
    	if (myStock != null) {
    	doSomething();
    	}
    
    }
    
    
    protected void connect(String [] args) {
      try {
    	ORB orb = ORB.init (args, null);
    	org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService") ;
    	NamingContextExt  ncRef = NamingContextExtHelper.narrow(objRef);
    	
    	String name = "StockMarket";
    	myStock = StockHelper.narrow(ncRef.resolve_str(name)) ;
    
    	System.out.println("Obtained a handle on server object: " + myStock);
    	System.out.println("Succesfully bound to a StockServer.");
    	
             } 
    	catch (Exception e) {
    	System.out.println("EROR : " + e) ;
    	e.printStackTrace(System.out);
    	}
    }
    
    
    protected void doSomething() {
    try{
    	String [] stockSymbols = myStock.getStockSymbols();
    	for (int i = 0; i < stockSymbols.length; i++) {
    	       System.out.println(stockSymbols[i] + "  " + myStock.getStockValue (stockSymbols[i]));
    	}
    	}
    	catch (org.omg.CORBA.SystemException ex) {
    	   System.err.println("Fatal eror: " + ex);
    	}
    	}
    
    
    public static void main (String args []) {
    	
    	StockClient stockClient = new StockClient();
    	stockClient.connect(args) ;
    	stockClient.run();
    	while (true);
    	}
    
    private Stock myStock;
    }
    and this is StockMarket.idl code

    Java Code:
    	// StockMarket.idl
    	// The StockMarket module consists of definitions useful
    	// for building stock market-related applications.
    module StockMarket {
    		// The StockSymbol type is used for symbols (names)
    		// representing stocks.
    	typedef string StockSymbol;
    	
    		// A StockSymbolList is simply a sequence of
    		// StockSymbols. 
    	typedef sequence<StockSymbol> StockSymbolList;
    
    		// The StockServer interface is the interface for a
    		// server which provides stock market information.
    		// (See the comments on the individual methods for
    		// more information) 
    
    	interface Stock{
    			// getStockValue() returns the current value for
    			// the given StockSymbol. If the given StockSymbol
    			// is unknown, the results are undefined (this
    			// would be a good place to raise an exception).
    
    		float getStockValue(in StockSymbol symbol);
    
    			// getStockSymbols() returns a sequence of all
    			// StockSymbols known by this StockServer
    		StockSymbolList getStockSymbols();
    	};
    };
    I can post and servers code too if you need, but he work fine.
    what I'm doing wrong, can you give me some help? :confused:

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    I get an error: connect (java.lang.String []) in StockMarket.StockClient can not be applied to ().
    Please post the full text of the error message. It has important info needed to solve this.

    From what I can see, the connect() method requires a String array when it is called, but the call left it out.

  3. #3
    tajfun010 is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    this is the whole error message that I get when I try to compile StockClient.java

    StockClient.java:17: connect (java.lang.String []) in StockMarket.StockClient can not be applied to ()
    connect();

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Did you see the end of my post?

  5. #5
    tajfun010 is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    I have seen but still do not understand what to do, trying to solve this problem for more than two weeks and just do not know anymore what to do, I'm new to java, can you explain me a little closer to where the error is and what needs to I do to fix it

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    StockClient.java:17
    look at line 17 in the StockClient.java file.
    The compiler sees a call statement: collect();
    but your program does NOT define a collect method with no args.
    So the compiler complains that it can't find what it needs.

    You need to decide:
    why you are calling the connect() method without the proper args.
    OR
    why the connect() method requires the String array as args

    Change one or the other to make the compiler happy.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    BTW What is the following for?

    while (true);

  8. #8
    tajfun010 is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    This waits forever so that the DOS window doesn't disappear, so he writes in the book

  9. #9
    tajfun010 is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    I changed some things and I managed to compile a client application, but now I error occurs when I try to start the Clint. gives me this error:

    EROR: org.omg.CORBA.NO_IMPLEMENT: vmcid: 0x0 minog code: 0 completed:no
    org.omg.CORBA.NO_IMPLEMENT: vmcid: 0x0 minog code: 0 completed:no
    at com.sun.corba.se.internalcorba.ORBSingleton.resolv e_initial_references(ORBSingleton.java:290)
    at StockClient.connect(StockClient.java:25)
    at StockClient.main(StockClient.java:58)

    EROR: org.omg.CORBA.NO_IMPLEMENT: vmcid: 0x0 minog code: 0 completed:no
    org.omg.CORBA.NO_IMPLEMENT: vmcid: 0x0 minog code: 0 completed:no
    at com.sun.corba.se.internalcorba.ORBSingleton.resolv e_initial_references(ORBSingleton.java:290)
    at StockClient.connect(StockClient.java:25)
    at StockClient.run(StockClient.java:14)
    at StockClient.main(StockClient.java:59)

    this is a new client code:

    Java Code:
    import StockMarket.*;
    import org.omg.CosNaming.*;
    import org.omg.CosNaming.NamingContextPackage.*;
    import org.omg.CORBA.*;
    
    
    public class StockClient {
    	StockClient() {
    	}
    
    public void run() {
    	
    	connect();
    	if (myStock != null) {
    	doSomething();
    	}
    
    }
    
    
    protected void connect() {
      try {
    	ORB orb = ORB.init ();
    	org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService") ;
    	NamingContextExt  ncRef = NamingContextExtHelper.narrow(objRef);
    	
    	String name = "StockMarket";
    	myStock = StockHelper.narrow(ncRef.resolve_str(name)) ;
    
    	System.out.println("Obtained a handle on server object: " + myStock);
    	System.out.println("Succesfully bound to a StockServer.");
    	
             } 
    	catch (Exception e) {
    	System.out.println("EROR : " + e) ;
    	e.printStackTrace(System.out);
    	}
    }
    
    
    protected void doSomething() {
    try{
    	String [] stockSymbols = myStock.getStockSymbols();
    	for (int i = 0; i < stockSymbols.length; i++) {
    	       System.out.println(stockSymbols[i] + "  " + myStock.getStockValue (stockSymbols[i]));
    	}
    	}
    	catch (org.omg.CORBA.SystemException ex) {
    	   System.err.println("Fatal eror: " + ex);
    	}
    	}
    
    
    public static void main (String args []) {
    	
    	StockClient stockClient = new StockClient();
    	stockClient.connect() ;
    	stockClient.run();
    	while (true);
    	}
    
    private Stock myStock;
    }
    connect() method is used to bind to the Name Server, as I understand it or I was wrong?

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Now your out of my knowledge base. I don't know corba.

  11. #11
    tajfun010 is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    I changed the client code now looks like this and have no problems with Compiling, but when you start the Clint, I get this error:

    Client code:
    Java Code:
    // StockMarketClient.java
    
    package StockMarket;
    
    import org.omg.CORBA.ORB;
    
    import org.omg.CosNaming.NameComponent;
    
    import org.omg.CosNaming.NamingContext;
    
    import org.omg.CosNaming.NamingContextHelper;
    
    // StockMarketClient is a simple client of a StockServer.
    
    public class StockMarketClient {
    
    // Create a new StockMarketClient.
    
    StockMarketClient() {
    
    }
    
    // Run the StockMarketClient.
    
    public void run() {
    
    connect();
    
    if (myStock != null) {
    
    doSomething();
    
    }
    
    }
    
    // Connect to the StockServer.
    
    protected void connect() {
    
    try {
    
    // Get the root naming context.
    
    org.omg.CORBA.Object obj = ourORB.
    
    resolve_initial_references("NameService");
    
    NamingContext namingContext = NamingContextHelper.narrow(obj);
    
    // Attempt to locate a StockServer object in the naming context.
    
    NameComponent nameComponent = new NameComponent("StockServer", "");
    
    NameComponent path[] = { nameComponent };
    
    myStock = StockHelper.narrow(namingContext.resolve(path));
    
    }
    
    catch (Exception ex) {
    
    System.err.println("Couldn’t resolve StockServer:" + ex);
    
    myStock = null;
    
    return;
    
    }
    
    System.out.println("Succesfully bound to a StockServer.");
    
    }
    
    // Do some cool things with the StockServer.
    
    protected void doSomething() {
    
    try {
    
    // Get the valid stock symbols from the StockServer.
    
    String[] stockSymbols = myStock.getStockSymbols();
    
    // Display the stock symbols and their values.
    
    for (int i = 0; i < stockSymbols.length; i++) {
    
    System.out.println(stockSymbols[i] +"   " +
    
    myStock.getStockValue(stockSymbols[i]));
    
    }
    
    }
    
    catch (org.omg.CORBA.SystemException ex) {
    
    System.err.println("Fatal error: " + ex);
    
    }
    
    }
    
    // Start up a StockMarketClient.
    
    public static void main(String args[]) {
    
    // Initialize the ORB.
    
    ourORB = ORB.init(args, null);
    
    StockMarketClient stockClient = new StockMarketClient();
    
    stockClient.run();
    
    // This simply waits forever so that the DOS window doesn’t
    
    // disappear (for developers using Windows IDEs).
    
    while (true)
    
    ;
    
    }
    
    // My ORB.
    
    public static ORB ourORB;
    
    // My StockServer.
    
    private Stock myStock;
    
    }

    error message:

    Exception in thread "main" java.lang.No.ClassDefFoundError: StockMarketClient (wrong name: StockMarket/StockMarketClient)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :539)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:251)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:55)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 194)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 89)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 35)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:302)

    can you help me with this please?

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    when you start the Client, I get this error
    No.ClassDefFoundError: StockMarketClient (wrong name: StockMarket/StockMarketClient)

    The class is in a package. You need to specify the package and the class name:
    StockMarket.StockMarketClient
    You are only giving the class name

  13. #13
    tajfun010 is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Java Socket server with C client problem
    By rnvrnv in forum Networking
    Replies: 6
    Last Post: 11-09-2010, 12:47 AM
  2. a problem about java mail client program
    By lunarstyle in forum AWT / Swing
    Replies: 9
    Last Post: 12-19-2009, 04:14 PM
  3. corba ORB not working with java 6u14
    By erJava in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 07-31-2009, 07:24 PM
  4. Problem in Thread wakeup of Java NIO Client
    By sranil in forum Networking
    Replies: 0
    Last Post: 04-05-2009, 07:42 PM
  5. Replies: 2
    Last Post: 09-23-2008, 01:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •