Results 1 to 5 of 5
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    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.

    :confused:

    Java Code:
    [B]run_demo.bat[/B]
    @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
    [B]start java ProductServer 2> ProductServer.log [/B] //I have to run this manually; otherwise an err is displayed (see error).
    java ProductClient 
    pause
    
    [B]Product.java[/B]
     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;
    
     }
    
    
    [B]ProductClient.java[/B]
     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();
    
           }
        }
     }
    
    [B]ProductImpl.java[/B]
      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;
    
     }
    
    [B]ProductServer.java[/B]
      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();
           }
        }}
    Java Code:
    [B]Error[/B]
    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>

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Java Code:
    [b]ProductClient.java[/b]
    ...
    try
           {
              Context namingContext = new InitialContext();
    
              Product c1 = (Product) namingContext.lookup(url + "toaster");
    
              Product c2 = (Product) namingContext.lookup(url + "microwave");
    
    
              System.out.println(c1.getDescription());
    
             [B] System.out.println(c2.getDescription()); //line 35 [/b]
    ....
           }
    ...


    NOTE: It would be helpful to have the functionality that tags automatically generate line numbers (editable).
    Last edited by jon80; 07-05-2009 at 07:07 PM. Reason: update #1

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hmmm, your error message notify something invalid naming conventions. Let see your complete code.

  5. #5
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    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.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. Replies: 2
    Last Post: 08-07-2009, 10:21 PM
  2. Replies: 6
    Last Post: 05-27-2009, 01:17 AM
  3. javax.naming.NameNotFoundException: bean not bound
    By Sirisha_24 in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 04-01-2009, 10:51 AM
  4. javax.microedition.io/ javax.bluetooth
    By ahtiven in forum New To Java
    Replies: 3
    Last Post: 01-13-2009, 02:54 PM
  5. javax.naming.NameNotFoundException: ejb/RatingEJB
    By Daniel in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 06-29-2007, 02:12 AM

Posting Permissions

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