Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

head first rmi error

 
kieran pattni
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all..copied the head first code examples rmi but get this error ..can anyone help..single on home desktop computer on loop back...


java.net.MalformedURLException: invalid URL String: Remote Hello
at java.rmi.Naming.parseURL(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at MyRemoteImp1.main(MyRemoteImp1.java:44)
Caused by: java.net.URISyntaxException: Illegal character in path at index 6: Remote Hello
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.checkChars(Unknown Source)
at java.net.URI$Parser.parseHierarchical(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
at java.rmi.Naming.intParseURL(Unknown Source)
... 3 more

import java.rmi.*;
public interface MyRemote extends Remote
{
public String sayHello() throws RemoteException;
}
import java.rmi.*;
import java.rmi.server.*;

public class MyRemoteImp1 extends UnicastRemoteObject implements MyRemote
{
public String sayHello()
{
return "Server says, 'Hey'";
}
public MyRemoteImp1() throws RemoteException
{

}

public static void main(String[]args)
{
try
{
MyRemote service = new MyRemoteImp1();
Naming.rebind("Remote Hello",service);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
import java.rmi.*;
public class MyRemoteClient
{
public static void main(String[]args)
{
new MyRemoteClient().go();
}
public void go()
{
try
{
MyRemote service = (MyRemote)Naming.lookup("rmi://127.0.0.1/Remote Hello");
String s =service.sayHello();
System.out.println(s);
}
catch(Exception ex){ex.printStackTrace();}


}
}
thank you
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kieran,

I can't test this at the moment but from the exception you get when trying to run this application I guess the problem is simply the space character between "Remote" and "Hello". I guess you should strip this space out or correctly encode the URL like other URLs (for example HTTP URLs).

I hope this helps...

Marco
 
kieran pattni
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you...not sure if it is mistake in the book but its working now..thanks
 
Z Winne
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok�, my problem is not the same as the original post but my exercice is. When I run my batch file (%rmic MyRemoteImpl) my command prompt goes haywire, it just keeps giving me the line "--location-->rmic MyRemoteImpl" endlessly. Does anyone have any ideas on what I'm doing wrong?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic