Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-05-2009, 02:58 PM
jon80's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 195
Rep Power: 2
jon80 is on a distinguished road
Default [newbie] javax.naming.NameNotFoundException: toaster
I'm trying out a tutorial example, and, noted that when running the last line of the batch file, it can't seem to find the toaster , although when running the command by opening a console window and simply typing the last line it seems to work.



Code:
run_demo.bat
@echo off
rem demonstrates the use of calling a remote method
rem javac Product*.java
rmic -v1.2 ProductImpl 2> rmic.error.log
start rmiregistry 2>>rmic.error.log
start java ProductServer 2> ProductServer.log  //I have to run this manually; otherwise an err is displayed (see error).
java ProductClient 
pause

Product.java
 import java.rmi.*;

 
  /**
     The interface for remote product objects.
  */
  public interface Product extends Remote
  {
     /**
        Gets the description of this product.
       @return the product description
    */
    String getDescription() throws RemoteException;

 }


ProductClient.java
 import java.rmi.*;

  import java.rmi.server.*;

  import javax.naming.*;


  /**
     This program demonstrates how to call a remote method
     on two objects that are located through the naming service.
  */
  public class ProductClient
 {
    public static void main(String[] args)
    {
       System.setProperty("java.security.policy", "client.policy");

       System.setSecurityManager(new RMISecurityManager());

       String url = "rmi://localhost/";

 /*TODO change to "rmi://yourserver.com/" when server runs on remote machine
 		yourserver.com*/
       try
       {
          Context namingContext = new InitialContext();

          Product c1 = (Product) namingContext.lookup(url + "toaster");

          Product c2 = (Product) namingContext.lookup(url + "microwave");


          System.out.println(c1.getDescription());

          System.out.println(c2.getDescription());

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

       }
    }
 }

ProductImpl.java
  import java.rmi.*;

  import java.rmi.server.*;

 
  /**
     This is the implementation class for the remote product
     objects.
  */
  public class ProductImpl
     extends UnicastRemoteObject
    implements Product
 {
    /**
       Constructs a product implementation
       @param n the product name
    */
    public ProductImpl(String n) throws RemoteException
    {
       name = n;

    }

    public String getDescription() throws RemoteException
    {
       return "I am a " + name + ". Buy me!";

    }

    private String name;

 }

ProductServer.java
  import java.rmi.*;
  import java.rmi.server.*;
  import javax.naming.*;


  /**
     This server program instantiates two remote objects,
     registers them with the naming service, and waits for
     clients to invoke methods on the remote objects.
  */
 public class ProductServer
 {
    public static void main(String args[])
    {
       try
       {
          System.out.println("Constructing server implementations...");


          ProductImpl p1 = new ProductImpl("Blackwell Toaster");
          ProductImpl p2 = new ProductImpl("ZapXpress Microwave Oven");


          System.out.println("Binding server implementations to registry...");
          Context namingContext = new InitialContext();
          namingContext.bind("rmi:toaster", p1);
          namingContext.bind("rmi:microwave", p2);
          System.out.println("Waiting for invocations from clients...");

       }
       catch (Exception e)
       {
          e.printStackTrace();
       }
    }}
Code:
Error
Displayed when running run_demo.bat
javax.naming.NameNotFoundException: toaster
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(Unknown Source)
        at com.sun.jndi.toolkit.url.GenericURLContext.lookup(Unknown Source)
        at javax.naming.InitialContext.lookup(Unknown Source)
        at ProductClient.main(ProductClient.java:35)
Press any key to continue . . .
Environment notes:
Microsoft Windows [Version 6.0.6001] //Windows Server 2008 x64
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)

C:\Users\Administrator>
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-05-2009, 05:28 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,256
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Quote:
at ProductClient.main(ProductClient.java:35)
Did you check that what's on the above line?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-05-2009, 08:03 PM
jon80's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 195
Rep Power: 2
jon80 is on a distinguished road
Default
Code:
ProductClient.java
...
try
       {
          Context namingContext = new InitialContext();

          Product c1 = (Product) namingContext.lookup(url + "toaster");

          Product c2 = (Product) namingContext.lookup(url + "microwave");


          System.out.println(c1.getDescription());

          System.out.println(c2.getDescription()); //line 35 
....
       }
...


NOTE: It would be helpful to have the functionality that tags automatically generate line numbers (editable).

Last edited by jon80; 07-05-2009 at 08:07 PM. Reason: update #1
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-06-2009, 06:13 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,256
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Hmmm, your error message notify something invalid naming conventions. Let see your complete code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-06-2009, 06:25 AM
Senior Member
 
Join Date: Mar 2009
Posts: 376
Rep Power: 1
Singing Boyo is on a distinguished road
Default
I'd look for an error in whatever class c2 is. It's definitely a class that implements Product, but there appears to be an error in the getDescription() method, which would be implemented in the class itself.
__________________
So you came along and found Java? Randomly?
Well then, you're just like me!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception in thread "main" javax.naming.NameNotFoundException: jmx not bound Vartika Advanced Java 2 08-07-2009 11:21 PM
[SOLVED] [newbie] java.lang.String cannot be cast to javax.swing.Icon jon80 New To Java 6 05-27-2009 02:17 AM
javax.naming.NameNotFoundException: bean not bound Sirisha_24 Enterprise JavaBeans 2 04-01-2009 11:51 AM
javax.microedition.io/ javax.bluetooth ahtiven New To Java 3 01-13-2009 03:54 PM
javax.naming.NameNotFoundException: ejb/RatingEJB Daniel Enterprise JavaBeans 2 06-29-2007 03:12 AM


All times are GMT +2. The time now is 06:06 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org