Hey,
hoffe ihr könnt mir helfen. Und zwar bin ich gerade dabei ein Flughafen-Informations-System zu basteln und hänge an einer Login-Funktion für die Clients. Für mich sieht es so aus als ob der Client über die Methode erst gar nicht auf den Server zugreifen kann. Ich hab versucht den Methodenrumpf in der Klasse RMIServerImpl auszukommentieren sprich es sah dann so aus: methodenname(parameter){/*....*/} und er hat mir trotzdem eine Fehler ausgespuckt.
Hier der Fehler:
Exception in thread "Thread-1" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$254(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/482761588.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy1.login(Unknown Source)
at RMIClientImpl.run(RMIClientImpl.java:90)
at java.lang.Thread.run(Unknown Source)
RMIClient
RMIClientImpl
RMIServer
RMIServerImpl
Es dreht sich um die Methode server.login() im RMIClientImpl unter dem punkt case4.
Hoffe ihr könnt mir bei dem Problem weiterhelfen.
Ach ja die anderen Cases(1,2,3) funktionieren alle.
hoffe ihr könnt mir helfen. Und zwar bin ich gerade dabei ein Flughafen-Informations-System zu basteln und hänge an einer Login-Funktion für die Clients. Für mich sieht es so aus als ob der Client über die Methode erst gar nicht auf den Server zugreifen kann. Ich hab versucht den Methodenrumpf in der Klasse RMIServerImpl auszukommentieren sprich es sah dann so aus: methodenname(parameter){/*....*/} und er hat mir trotzdem eine Fehler ausgespuckt.
Hier der Fehler:
Exception in thread "Thread-1" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$254(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/482761588.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy1.login(Unknown Source)
at RMIClientImpl.run(RMIClientImpl.java:90)
at java.lang.Thread.run(Unknown Source)
RMIClient
Java:
public class RMIClient {
public static void main(String[] args)
{
try
{
Thread t = new Thread (new RMIClientImpl ());
t.start();
t.join();
System.exit(0);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
RMIClientImpl
Java:
import java.rmi.*;
import java.rmi.UnknownHostException;
import java.rmi.server.UnicastRemoteObject;
import java.util.*;
import java.net.*;
import java.text.*;
import MyExceptions.idNotExistingException;
import MyExceptions.noFlightMatchesException;
import MyExceptions.notEnoughSeatsException;
public class RMIClientImpl extends UnicastRemoteObject implements RMIClientInterface, Runnable {
private static final String HOST = "localhost";
private static String BIND_NAME = "RMI-Server";
private static int id = 123456789;
private String monitoringTime;
public RMIClientImpl() throws RemoteException
{
}
public void sendStatus(String status) throws RemoteException
{
System.out.println(status);
}
public int getId()
{
return id;
}
public void run()
{
try
{
String bindURL = "rmi://" + HOST + "/" + BIND_NAME;
RMIServer server = (RMIServer) Naming.lookup (bindURL);
System.out.println ("Remote-Referenz erfolgreich erhalten.");
System.out.println("Server ist gebunden an: " +bindURL);
while(true){
System.out.println(server.options());
int i = IO.promptAndReadInt("");
switch(i)
{
case 1:
try{
int id = IO.promptAndReadInt("Please enter the identifier of th flight for your reservation: ");
int s = IO.promptAndReadInt("Please enter the amount on seats you would like to reservate: ");
System.out.println(server.reservateSeats(id, s));
}
catch(idNotExistingException e){
System.out.println(e.getMessage());
}
catch(notEnoughSeatsException e){
System.out.println(e.getMessage());
}
break;
case 2:
try{
String source = IO.promptAndReadString("Bitte geben Sie ihren gewünschten Abflugsort ein: ");
String destination = IO.promptAndReadString("Bitte geben Sie ihren gewünschten Zielort ein: ");
System.out.print(server.searchId(source, destination));
}
catch(noFlightMatchesException e){
System.out.println(e.getMessage());
}
break;
case 3:
try{
int search = IO.promptAndReadInt("Please enter the identifier of th flight for your reservation: ");
System.out.println(server.seachInformation(search));
}
catch(idNotExistingException e){
System.out.println(e.getMessage());
}
break;
case 4:
try{
int idFlight = IO.promptAndReadInt("Please enter the ID-number of the flight you would like to monitor: ");
String time = IO.promptAndReadString("How long do you want to monitor the flight?");
server.login(this, idFlight, time);
}
catch(idNotExistingException e){
System.out.println(e.getMessage());
}
default:
System.out.println("Invalid number, please re-choose your option!\n\n");
break;
}
}
}
catch(NotBoundException e){
System.out.println("Server ist nicht gebunden:\n"+e.getMessage());
}
catch(MalformedURLException e){
System.out.println("URL ungültig:\n" +e.getMessage());
}
catch(RemoteException e){
System.out.println("Fehler während Kommunikation;\n" +e.getMessage());
}
}
public void setMonitoringTime(String monitoringTime) throws RemoteException {
this.monitoringTime = monitoringTime;
}
public String getMonitoringTime() throws RemoteException {
return monitoringTime;
}
}
RMIServer
Java:
import java.rmi.Remote;
import java.rmi.RemoteException;
import MyExceptions.*;
import java.net.*;
public interface RMIServer extends Remote {
String options() throws RemoteException;
String reservateSeats(int id, int s) throws RemoteException, idNotExistingException, notEnoughSeatsException;
String searchId(String source, String destination) throws noFlightMatchesException, RemoteException;
String seachInformation(int id) throws RemoteException, idNotExistingException;
void login(RMIClientImpl client, int idFlight, String time) throws RemoteException, idNotExistingException;
}
RMIServerImpl
Java:
import java.rmi.*;
import java.rmi.server.*;
import java.util.ArrayList;
import java.util.Vector;
import java.net.*;
import MyExceptions.*;
public class RMIServerImpl extends UnicastRemoteObject implements RMIServer {
private static final String HOST = "localhost";
private static final String SERVICE_NAME = "RMI-Server";
private static ArrayList<Flights> flights = new ArrayList<Flights>();
private static addMinutes monitoringTime;
public RMIServerImpl() throws RemoteException
{
String bindURL = null;
try
{
bindURL= "rmi://" + HOST + "/" + SERVICE_NAME;
Naming.rebind(bindURL, this);
System.out.println("RMI-Server gebunden unter Namen: " + SERVICE_NAME);
System.out.println("RMI-Server ist bereit...");
instanceFlights();
}
catch(MalformedURLException e)
{
System.out.println("Ungültige URL: " + bindURL);
System.out.println(e.getMessage());
System.exit(1);
}
}
public static void main (String[] args)
{
try
{
new RMIServerImpl();
}
catch(RemoteException e)
{
System.out.println ("Fehler während er Erzeugung des Server-Objekts");
System.out.println(e.getMessage());
System.exit(1);
}
}
public String options () throws RemoteException
{
String option = "";
option += ("Options" + "\n");
option += ("1. Reservation of Seats" + "\n");
option += ("2. Search ID-number" + "\n");
option += ("3. Search Flight Information" + "\n");
return option;
}
public String searchId(String source, String destination) throws RemoteException, noFlightMatchesException{
String flightIds = "";
ArrayList<Flights> result = new ArrayList<Flights>();
try
{
for (int i = 0; i<flights.size();i++)
{
if(flights.get(i).getSource().equalsIgnoreCase(source)&&flights.get(i).getDestination().equalsIgnoreCase(destination))
{
result.add(flights.get(i));
}
}
if (result.isEmpty())
{
noFlightMatchesException ex = new noFlightMatchesException();
throw ex;
}
for(Flights flights : result)
{
flightIds += (flights.getIdentifier() + ", ");
}
return ("The Flights with the ID: " + flightIds + " are flying your route\n\n");
}
finally
{}
}
public String reservateSeats(int id, int s) throws RemoteException, idNotExistingException, notEnoughSeatsException
{
int j = 0;
for (int i = 0; i<flights.size();i++)
{
if(flights.get(i).getIdentifier()==id)
{
flights.get(i).reservateSeats(s);
flights.get(i).sendStatus(id);
j++;
}
}
if(j==0)
{
idNotExistingException e = new idNotExistingException();
throw e;
}
return "Your reservation has been successful";
}
public void instanceFlights ()
{
flights.add(new Flights ("Stuttgart", "Nuernberg", "12:00", 150, 300));
flights.add(new Flights ("Stuttgart", "Rom", "12:00", 300, 400));
flights.add(new Flights ("Stuttgart", "Berlin", "12:00", 250, 200));
flights.add(new Flights ("Stuttgart", "Singapore", "12:00", 750, 300));
flights.add(new Flights ("Stuttgart", "New York", "12:00", 450, 400));
flights.add(new Flights ("Capetown", "Nuernberg", "12:00", 950, 200));
flights.add(new Flights ("Stuttgart", "Nuernberg", "12:00", 1150, 150));
flights.add(new Flights ("Brisbane", "Cairns", "12:00", 1502, 100));
flights.add(new Flights ("Tokyo", "Paris", "12:00", 1507, 180));
flights.add(new Flights ("San Francisco", "Shanghai", "12:00", 550, 130));
flights.add(new Flights ("Stuttgart", "Nuernberg", "12:00", 350, 190));
}
public String seachInformation(int id) throws RemoteException, idNotExistingException {
String result="";
int j = 0;
for (int i = 0; i<flights.size();i++)
{
if(flights.get(i).getIdentifier()==id)
{
result += "The departure time of the flight is: " + (flights.get(i).getDepartureTime())+"\n";
result += "The airfare is: " + (flights.get(i).getAirfare())+"\n";
result += "On the flight are still: " + (flights.get(i).getNumberSeats())+" seats avialable";
j++;
}
}
if(j==0)
{
idNotExistingException e = new idNotExistingException();
throw e;
}
return result;
}
public void login(RMIClientImpl client, int idFlight, String time) throws RemoteException, idNotExistingException {
{
for (int i = 0; i<flights.size();i++)
{
if(flights.get(i).getIdentifier()==(idFlight))
{
for(int j = 0; j<flights.get(i).getClients().size(); j++)
{
if(flights.get(i).getClients().get(j).getId()!=client.getId())
{
System.out.println("Test");
flights.get(i).getClients().add(client);
monitoringTime = new addMinutes(time);
String finalTime = monitoringTime.getMonitoringTime();
int index=(flights.get(i).getClients().size())-1;
flights.get(i).getClients().get(index).setMonitoringTime(finalTime);
}
}
}
}
}
}
}
Es dreht sich um die Methode server.login() im RMIClientImpl unter dem punkt case4.
Hoffe ihr könnt mir bei dem Problem weiterhelfen.
Ach ja die anderen Cases(1,2,3) funktionieren alle.
Zuletzt bearbeitet: