Java rmi-Ps help

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2007
Posts: 6
Reputation: ssimkhan is an unknown quantity at this point 
Solved Threads: 0
ssimkhan ssimkhan is offline Offline
Newbie Poster

Java rmi-Ps help

 
0
  #1
Jun 18th, 2007
I've tried to run the BankServer.java class for several hours and this is the error it gives me:
G:\Distributed Objects\Exercise 3\BankServer.java:11: cannot find symbol
symbol : constructor BankImpl()
location: class BankImpl
BankImpl b = new BankImpl();

I have other classes orf the Bank interface, BankImpl and BankClient but they're all working fine. I've tried to add a no-argument constructor to BankImpl, or change the way I'm calling it to match one of the declared constructors but it stil wont work. here are all of the classes.ps help.


//Bank.java
//RMI interface.
import java.rmi.*;
public interface Bank extends Remote
{
public int getAcctNum() throws RemoteException;
public String getName() throws RemoteException;
public double getBalance() throws RemoteException;
public double withdraw(double amount) throws RemoteException;
public void deposit(double amount) throws RemoteException;
}


//BankImpl.java
//Implementation of RMI interface.
import java.rmi.*;
import java.rmi.server.*;
public class BankImpl implements Bank
{
private int accountNumber;
private String lastName;
private String firstName;
private double balance;

public BankImpl (int acctNo, String lname, String fname, double bal)
{
accountNumber = acctNo;
lastName = lname;
firstName = fname;
balance = bal;
}
public int getAcctNum() throws RemoteException
{
return accountNumber;
}
public String getName() throws RemoteException
{
return (firstName + " " + lastName);
}
public double getBalance() throws RemoteException
{
return balance;
}
public double withdraw(double amount) throws RemoteException
{
if (amount <= balance) return amount;
else return 0;
}
public void deposit(double amount) throws RemoteException
{
if (amount > 0) balance += amount;
}
}


//BankClient.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class BankClient
{
private static final int[] acctNo = {111111, 222222, 333333, 444444};
public static void main(String args[])
{
try{
//get remote objectreference (stub)
Registry registry = LocateRegistry.getRegistry("Localhost");
Bank b = (Bank)registry.lookup("BankService");
for (int i=0; i<acctNo.length; i++)
{
System.out.println("\nAccount number: " + b.getAcctNum());
System.out.println("Name: " + b.getName());
System.out.println("Balance: " + b.getBalance());
}

} catch (java.rmi.RemoteException re){
System.out.println("RemoteException");
System.out.println(re);
}
catch (java.rmi.NotBoundException nbe){
System.out.println("NotBoundException");
System.out.println(nbe);
}
catch (java.lang.ArithmeticException ae){
System.out.println("java.lang.ArithmeticException");
System.out.println(ae);
}
}
}

//BankServer.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class BankServer
{
public static void main(String[] args) throws Exception
{
try{
BankImpl b = new BankImpl();

//'0' denotes location where exported object 'c' is to be stored
Bank stub = (Bank)UnicastRemoteObject.exportObject(b,0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind("BankService", stub);
System.out.println("Bank server running");
BankImpl[] account =
{new BankImpl(111111, "Smith", "James", 112.58),
new BankImpl(222222, "Jones", "Sally", 507.85),
new BankImpl(333333, "White", "Mary Jane", 2345.00),
new BankImpl(444444, "Brooks", "Mark", 10028.00)};
for (int i=0; i<account.length; i++)
{
int accountNumber= account[i].getAcctNum();
}
}catch(Exception e){
System.out.println("Trouble: " + e);
}
}
}
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Java rmi-Ps help

 
0
  #2
Jun 18th, 2007
May be you have an old .class file in your path. Check by explicitly setting the classpath OR passing it on command line OR running on a different machine/window.
Are you Agile.. ?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Java rmi-Ps help

 
0
  #3
Jun 19th, 2007
it's quite normal that this code gives an error. you're calling the default constructor of BankImpl, but your BankImpl class doesn't have a default constructor. you should just use the constructor that does exist:

  1. public BankImpl (int acctNo, String lname, String fname, double bal)
  2. {
  3. accountNumber = acctNo;
  4. lastName = lname;
  5. firstName = fname;
  6. balance = bal;
  7. }

so, in BankServer, do not use:
  1. BankImpl b = new BankImpl();
but something like:
  1. BankImpl b = new BankImpl(1, "LastName","FirstName",2517.26);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC