| | |
Java rmi-Ps help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2007
Posts: 6
Reputation:
Solved Threads: 0
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.
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);
}
}
}
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:
so, in BankServer, do not use:
but something like:
Java Syntax (Toggle Plain Text)
public BankImpl (int acctNo, String lname, String fname, double bal) { accountNumber = acctNo; lastName = lname; firstName = fname; balance = bal; }
so, in BankServer, do not use:
Java Syntax (Toggle Plain Text)
BankImpl b = new BankImpl();
Java Syntax (Toggle Plain Text)
BankImpl b = new BankImpl(1, "LastName","FirstName",2517.26);
![]() |
Similar Threads
- is it possible for PHP to call API written on java ? HELP (Java)
- Error in exception(RMI) (Java)
- Java rmi-ps help (Java)
- Java EE (Java)
- URGENT: FTP Client / Server using RMI (Java)
- Playing with RMI in Tiger (Java)
Other Threads in the Java Forum
- Previous Thread: Java Session
- Next Thread: Help me to get Attribute from ADAM directory
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes client code component consumer database draw eclipse ee error event exception file fractal free game gameprogramming gis givemetehcodez graphics gui helpwithhomework html ide image input integer j2me j2seprojects java javaprojects jmf jni jpanel julia jvm linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nls notdisplaying number object oracle print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows





