Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 587131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:10:49+00:00 2026-05-13T15:10:49+00:00

For school we made a Java application with RMI, there are 3 applications: Server,

  • 0

For school we made a Java application with RMI, there are 3 applications: Server, Client and Rekenaar.

The line where it goes wrong is the Line: “test = (Range[])m.getAllRange();”, it gives an dispatchUncaughtException.

package rekenaar;

import server.Opdracht;
import java.rmi.Naming;
import java.util.logging.Level;
import java.util.logging.Logger;
import interfaces.*;
import java.rmi.RemoteException;

/**
 *
 * @author Windows
 */
public class Rekenaar implements Runnable{

    private Range range;
    private IRekenCoördinator coordinator;
    private long[] priemgetallen;
    private Opdracht op;
    private Range[] test;

    public Rekenaar()
    {
        try{
        this.coordinator = null;
        this.coordinator = (IRekenCoördinator) Naming.lookup("rmi://127.0.0.1:1099/RekenC");
        this.priemgetallen = coordinator.getPriemgetallen();
        this.op = null;
        }catch(Exception ex){ex.printStackTrace();}

    }


    public void Bereken() 
    {
        try{
        long rangeOndergrens = (op.getGetal()/2000) * 2000;
        range = new Range(priemgetallen, rangeOndergrens);
        op.setRange(range);
        op.setUitkomst(range.geefSemiPriem(op.getGetal()));
        coordinator.RemoveID(op.CheckRange());

        IMagazijn m = op.getMagazijn();
        test = (Range[])m.getAllRange();
        String hoi = m.hoi();


        m.AddRange(op);
        }catch(RemoteException ex){ex.printStackTrace();}
    }


    @Override
    public void run() {
                KrijgtOpdracht();
    }

    private void KrijgtOpdracht() 
    {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ex) {
            Logger.getLogger(Rekenaar.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(coordinator != null)
        {
            try{
        op = (Opdracht)coordinator.getOpdracht();
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
        if(op != null ) this.Bereken();

        this.run();

        }
    }

}

Interface:

package interfaces;

import java.io.IOException;
import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 *
 * @author Windows
 */
public interface IMagazijn extends Remote {

    /**
     *
     * @param op        Uitgerekende opdracht waarvan de gegevens verwerkt moeten worden op de server
     * @throws IOException
     */
    public String hoi() throws RemoteException;
    public IRange[] getAllRange() throws RemoteException;
    public void AddRange(IOpdracht op) throws RemoteException;

}

And here is the Magazijn itself which gives the IRange over RMI:

package server;


import java.rmi.RemoteException;
import java.util.ArrayList;

import interfaces.*;
import java.rmi.server.UnicastRemoteObject;



public class Magazijn extends UnicastRemoteObject implements IMagazijn{

private IRange[] ranges;
private long ondergrens;

public void setOndergrens(long ondergrens) {
    this.ondergrens = ondergrens;
}
private long bovengrens;

public void setBovengrens(long bovengrens) {
    this.bovengrens = bovengrens;
}
private transient MagazijnManager MM;
private transient ArrayList<Opdracht> dubbeleOpdrachten;
private transient RekenCoördinator RC;
private transient int MAGAZIJN_GROOTTE;

public Magazijn(long ondergrens, long bovengrens, MagazijnManager mm, RekenCoördinator RC)throws RemoteException
{
    ranges = new IRange[(int)(bovengrens-ondergrens)/2000];
    this.bovengrens = bovengrens;
    this.ondergrens = ondergrens;
    dubbeleOpdrachten = new ArrayList<Opdracht>();
    this.MM = mm;
    this.RC = RC;
    MAGAZIJN_GROOTTE = (int)(bovengrens - ondergrens) + 1;
}

public void AddRange(IOpdracht op) throws RemoteException
{
    ArrayList<IOpdracht> returnList = new ArrayList<IOpdracht>();
    ranges[op.getRangeIndex()] = op.getRange();
    returnList.add(op);
    for(Opdracht o : dubbeleOpdrachten)
    {
        if(o.getRangeIndex() == op.getRangeIndex())
        {
            o.setRange(op.getRange());
            o.setUitkomst(o.getRange().geefSemiPriem(o.getGetal()));
            returnList.add(o);
        }
    }
    MM.StuurOpdrachtenTerug(returnList);
}

public IRange[] getAllRange() throws RemoteException
{
    return ranges;
}

 public String hoi() throws RemoteException
{
    return "poep";
}

public IRange getRange(int rangeIndex)
{
    return ranges[rangeIndex];
}

public void StuurOpdracht(Opdracht op)
{
    Opdracht o =null;
        o = RC.AddOpdracht(op);
    if(o!=null)
    {
        dubbeleOpdrachten.add(o);
    }
}

public long getOndergrens()
{
    return ondergrens;
}

 public long getBovengrens()
{
    return bovengrens;
}

 public int getMagazijnGrootte()
 {
     return MAGAZIJN_GROOTTE;
 }

}

The Rekenaar got the whole class “Range” so that is not the problem. The problem is something between the casting of IRange into Range. Range itself is Serializable and implements IRange.

The error I get: Exception in thread “main” java.lang.ClassCastException: [Linterfaces.IRange; cannot be cast to [Lrekenaar.Range;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:10:49+00:00Added an answer on May 13, 2026 at 3:10 pm

    When using RMI, you won’t receive the same implementations you have on the server side. Instead you get a proxy class which will call your server. So you cannot cast your method.
    Change test to a

    IRange[] test
    

    That should do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Entity Framework designer is terrible - I've had the… May 14, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer If by "hijack" you meant sniff the packets then what… May 14, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer If you want two actions to be atomic, embed them… May 14, 2026 at 5:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.