943,983 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1836
  • Java RSS
Jun 18th, 2007
0

Java rmi-Ps help

Expand Post »
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);
}
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ssimkhan is offline Offline
6 posts
since May 2007
Jun 18th, 2007
0

Re: Java rmi-Ps help

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.
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Jun 19th, 2007
0

Re: Java rmi-Ps help

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:

Java Syntax (Toggle Plain Text)
  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:
Java Syntax (Toggle Plain Text)
  1. BankImpl b = new BankImpl();
but something like:
Java Syntax (Toggle Plain Text)
  1. BankImpl b = new BankImpl(1, "LastName","FirstName",2517.26);
Reputation Points: 935
Solved Threads: 356
Posting Maven
stultuske is online now Online
2,504 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Java Session
Next Thread in Java Forum Timeline: Help me to get Attribute from ADAM directory





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC