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 5976393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:13:19+00:00 2026-05-22T21:13:19+00:00

game.getS().getVehicles().get(1).updatePosition(positions.get(0)); we are making a client – server racing game and we got this

  • 0
game.getS().getVehicles().get(1).updatePosition(positions.get(0));

we are making a client – server racing game and we got this exception in this exact line what can we do or what can we change? here i will show you the all code:

package speedrace.client;

import static speedrace.common.Config.*;

import speedrace.common.*;
import speedrace.game.Car;
import speedrace.game.CarGame;
import speedrace.game.Player;

import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Float;
import java.rmi.*;
import java.rmi.server.*;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.*;

public class SpeedRaceClientController extends UnicastRemoteObject implements
        RaceObserver, RaceUpdate
{
    private RaceSubject serverGet;
    private RaceUpdate serverSet;
    private SpeedRaceClientView view;

    private int clientID = 0;
    private Player currentPlayer = null;
    private CarGame game = new CarGame();

    public SpeedRaceClientController() throws Exception
    {
        super();
        game.setVisible(false);
    }

    @Override
    public Player getCurrentPlayer() throws RemoteException
    {
        return currentPlayer;
    }

    @Override
    public void setCurrentPlayer(Player currentPlayer) throws RemoteException
    {
        this.currentPlayer = currentPlayer;

    }

    @Override
    public int getClientID()
    {
        return clientID;
    }

    @Override
    public void setClientID(int clientID)
    {
        this.clientID = clientID;
    }

    @Override
    public CarGame getGame()
    {
        return game;
    }

    @Override
    public void setGame(CarGame game)
    {
        this.game = game;
    }

    public void begin(SpeedRaceClientView view)
    {
        this.view = view;

        try
        {
            String ip = view.inputIP();
            String URL = "rmi://" + ip + "/" + SERVICE;

            serverSet = (RaceUpdate) Naming.lookup(URL);
            serverGet = (RaceSubject) Naming.lookup(URL);

            serverGet.attach(this);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            view.error("Trouble connecting to server");

            System.exit(1);
        }
    }

    @Override
    public void updatePlayerList(Vector<Player> playersList)
            throws RemoteException
    {
        view.showOnlinePlayers(playersList);

    }

    @Override
    public void registerNewPlayer(Player player, int clientID)
            throws RemoteException
    {
        try
        {
            serverSet.registerNewPlayer(player, clientID);
        }
        catch (RemoteException ex)
        {
            ex.printStackTrace();
            view
                    .error("Trouble connecting to server. Please restart the server.");
            System.exit(1);
        }

    }

    @Override
    public void startGame() throws RemoteException
    {

        try
        {
            serverSet.startGame();

        }

        catch (RemoteException re)
        {
            re.printStackTrace();
            view
                    .error("Trouble connecting to server. Please restart the server.");
            System.exit(1);
        }
    }

    @Override
    public void startTheGame(ArrayList<Point2D.Float> positions,
            Vector<RaceObserver> observers) throws RemoteException
    {

        switch (clientID)
        {
            case 1:
                game.updatePosition(273, 471);
                break;
            case 2:
                game.updatePosition(315, 408);
                break;
            case 3:
                game.updatePosition(353, 471);
                break;
            case 4:
                game.updatePosition(395, 408);
                break;
            case 5:
                game.updatePosition(433, 471);
                break;
            case 6:
                game.updatePosition(475, 408);
                break;
            case 7:
                game.updatePosition(513, 471);
                break;
            case 8:
                game.updatePosition(555, 408);
                break;
        }

        for (int i = 1; i < observers.size(); i++)
        {
            game.getS().getVehicles().add(
                    new Car(getClass().getResource(
                            "/speedrace/game/bluecar.png")));

            game.getS().getVehicles().get(i).setMass(0.9f);
            game.getS().getVehicles().get(i).setMaxSteering(500.0f);
            game.getS().getVehicles().get(i).updateVelocity(80.0f, 0.0f);
        }
        updatePosition(clientID, positions);

        game.setVisible(true);
        game.getS().requestFocusInWindow();
        sendCurrentCarPosition(game.getS().getVehicles().get(0).getPosition(),clientID);
    }

    public void updatePosition(int id, ArrayList<Point2D.Float> positions){
        if(id==1){
            for (int i = 1; i < game.getS().getVehicles().size(); i++)
            {
                game.getS().getVehicles().get(i).updatePosition(positions.get(i));              
            }

        }else if(id==2){
            game.getS().getVehicles().get(1).updatePosition(positions.get(0));              
            for (int i = 2; i < game.getS().getVehicles().size(); i++)
            {
                game.getS().getVehicles().get(i).updatePosition(positions.get(i));  
            }
        }else if(id==3){
            game.getS().getVehicles().get(1).updatePosition(positions.get(0));  
            game.getS().getVehicles().get(2).updatePosition(positions.get(1));
            for (int i = 3; i < game.getS().getVehicles().size(); i++)
            {
                game.getS().getVehicles().get(i).updatePosition(positions.get(i));  
            }
        }else if(id==4){
            game.getS().getVehicles().get(1).updatePosition(positions.get(0));  
            game.getS().getVehicles().get(2).updatePosition(positions.get(1));
            game.getS().getVehicles().get(3).updatePosition(positions.get(2));
            for (int i = 4; i < game.getS().getVehicles().size(); i++)
            {
                game.getS().getVehicles().get(i).updatePosition(positions.get(i));  
            }
        }else if(id==5){
            game.getS().getVehicles().get(1).updatePosition(positions.get(0));  
            game.getS().getVehicles().get(2).updatePosition(positions.get(1));
            game.getS().getVehicles().get(3).updatePosition(positions.get(2));
            game.getS().getVehicles().get(4).updatePosition(positions.get(3));
            for (int i = 5; i < game.getS().getVehicles().size(); i++)
            {
                game.getS().getVehicles().get(i).updatePosition(positions.get(i));  
            }
        }else if(id==6){
            game.getS().getVehicles().get(1).updatePosition(positions.get(0));  
            game.getS().getVehicles().get(2).updatePosition(positions.get(1));
            game.getS().getVehicles().get(3).updatePosition(positions.get(2));
            game.getS().getVehicles().get(4).updatePosition(positions.get(3));
            game.getS().getVehicles().get(5).updatePosition(positions.get(4));
            for (int i = 6; i < game.getS().getVehicles().size(); i++)
            {
                game.getS().getVehicles().get(i).updatePosition(positions.get(i));  
            }
        }else if(id==7){
            game.getS().getVehicles().get(1).updatePosition(positions.get(0));  
            game.getS().getVehicles().get(2).updatePosition(positions.get(1));
            game.getS().getVehicles().get(3).updatePosition(positions.get(2));
            game.getS().getVehicles().get(4).updatePosition(positions.get(3));
            game.getS().getVehicles().get(5).updatePosition(positions.get(4));
            game.getS().getVehicles().get(6).updatePosition(positions.get(5));
            for (int i = 7; i < game.getS().getVehicles().size(); i++)
            {
                game.getS().getVehicles().get(i).updatePosition(positions.get(i));  
            }
        }else if(id==8){
            game.getS().getVehicles().get(1).updatePosition(positions.get(0));  
            game.getS().getVehicles().get(2).updatePosition(positions.get(1));
            game.getS().getVehicles().get(3).updatePosition(positions.get(2));
            game.getS().getVehicles().get(4).updatePosition(positions.get(3));
            game.getS().getVehicles().get(5).updatePosition(positions.get(4));
            game.getS().getVehicles().get(6).updatePosition(positions.get(5));
            game.getS().getVehicles().get(7).updatePosition(positions.get(6));
        }
    }

    @Override
    public void updateCarPosition(ArrayList<Point2D.Float> positions)
            throws RemoteException
    {
        for (int i = 0; i < positions.size(); i++)
        {
            System.out.println(i+"= ["+positions.get(i).x+", "+positions.get(i).y+"]");         
        }
        System.out.println("My clienID is: "+clientID+" my car size is: "+ game.getS().getVehicles().size());
        updatePosition(clientID, positions);

    }

    @Override
    public void sendCurrentCarPosition(final Point2D.Float position, final int clientID) throws RemoteException
    {

        class UpdateThread implements Runnable
        {
            boolean running = true;
            public void run()
            {
                while (running)
                {
                    try
                    {
                        System.out.println(clientID+" send  his position to the server: "+position.x+", "+position.y);
                        serverSet.sendCurrentCarPosition(position, clientID);
                        Thread.sleep(20);
                    }

                    catch (RemoteException re)
                    {
                        re.printStackTrace();
                        view
                                .error("Trouble connecting to server. Please restart the server.");
                        System.exit(1);
                    }
                    catch (InterruptedException e)
                    {
                        e.printStackTrace();
                        view
                                .error("Trouble connecting to server. Please restart the server.");
                        System.exit(1);
                    }
                }
            }
        }
        final UpdateThread t = new UpdateThread();
        new Thread(t).start();
    }



}
  • 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-22T21:13:20+00:00Added an answer on May 22, 2026 at 9:13 pm

    In your for-loops you almost always start from 1. Is that correct?

    To let us find the problem, you should post more code, I guess.

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

Sidebar

Related Questions

I have an ASP.NET page that gets a list of game server ip addresses
We are making our very first iPhone game, and if the user gets a
I am creating a matching game for Android, and when the user gets a
I'm making a game for the iPhone using Cocos2D. At the beginning of the
I'm trying to make this 2-player web game application using Spring MVC. I have
Trying to write a game such that most of the screen gets filled with
I have two arrays used in a small game. If the player gets a
I'm making a game right now and pretty much everything has its own class.
The update() function below gets called on every frame of a game. If the
I am creating a game where where you complete shapes and the area gets

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.