Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Integer set in void, is being called upon.

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem with this, How?

    Hey, Well these are my problems and the code, I'm going to bed, hopefully someone could help me with this overnight.
    I know why its calling a nullpointer, its because its not set yet, which it wont be until a certain situation which is only when casting is set to true, but it's not and nothing has changed it to true. My question is why is it allowing it to run through that void in the first place? the boolean isnt set to true.
    ERROR:
    [4/12/12 8:14 PM]: java.lang.NullPointerException
    [4/12/12 8:14 PM]:      at server.model.players.SpellCast.FinishCast(SpellCast.java:58)
    [4/12/12 8:14 PM]:      at server.model.players.Client.process(Client.java:759)
    [4/12/12 8:14 PM]:      at server.model.players.PlayerHandler.process(PlayerHandler.java:138)
    [4/12/12 8:14 PM]:      at server.Server.main(Server.java:159)
    public void FinishCast() {
    		if (c.casting = false) {
    			return;
    		}
    		if (c.castTime <= 0) {
    			int i = c.playerIndex;
    			int pX = c.getX();
    			int pY = c.getY();
    			nX = Server.playerHandler.players[i].getX();//line 58
    			nY = Server.playerHandler.players[i].getY();
    			offX = (pY - nY)* -1;
    			offY = (pX - nX)* -1;
    			c.casting = false;
    			c.castTime = 0;
    			c.getPA().createPlayersProjectile(pX, pY, offX, offY, 50, 78, c.castGFX, 10, 10, i, 53);
    			}
    	}
    public void process() {
    /* ton of irrelevant code */
    if (casting = true) {
    			if (castTime > 0) {
    				castTime = castTime - 0.6;
    			}
    			if ((castTime == 0) && (casting = true)) {
    				getSpells().FinishCast(); //line 759
    			}
    		}
    /* another 2k lines of irrelevant code */
    public void process() {
    		synchronized (PlayerHandler.players) {
     
    			updatePlayerNames();
     
    			if(kickAllPlayers) {
    				for(int i = 1; i < Config.MAX_PLAYERS; i++) {
    					if(players[i] != null) {
    						players[i].disconnected = true;
    					}
    				}
    			}
     
    			for(int i = 0; i < Config.MAX_PLAYERS; i++) {
    				if(players[i] == null || !players[i].isActive) continue;
    				try {					
     
    					if(players[i].disconnected && (System.currentTimeMillis() - players[i].logoutDelay > 10000 || players[i].properLogout || kickAllPlayers)) {
    						if(players[i].inTrade) {
    							Client o = (Client) Server.playerHandler.players[players[i].tradeWith];
    							if(o != null) {
    								o.getTradeAndDuel().declineTrade();
    							}
    						}
    						if(players[i].duelStatus == 5) {
    							Client o = (Client) Server.playerHandler.players[players[i].duelingWith];
    							if(o != null) {
    								o.getTradeAndDuel().duelVictory();
    							}
    						} else if (players[i].duelStatus <= 4 && players[i].duelStatus >= 1) {
    							Client o = (Client) Server.playerHandler.players[players[i].duelingWith];
    							if(o != null) {
    								o.getTradeAndDuel().declineDuel();
    							}
    						}
    						Client o = (Client) Server.playerHandler.players[i];
    						if(PlayerSave.saveGame(o)) { 
    							System.out.println("Game saved for player "+players[i].playerName); 
    						} else { 
    							System.out.println("Could not save for "+players[i].playerName); 
    						}
    						removePlayer(players[i]);
    						players[i] = null;
    						continue;
    					}
     
    					players[i].preProcessing();			
    					while(players[i].processQueuedPackets());
    					players[i].process(); //line 138
    					players[i].postProcessing();
    					players[i].getNextPlayerMovement();
     
    				} catch(Exception e) {
    					e.printStackTrace();
    				}
    			}
    public static void main(java.lang.String args[]) throws NullPointerException, IOException {
    		/**
    		 * Starting Up Server
    		 */
    		//WalkingCheck.check();
    		try {
    			WalkingHandler.getSingleton().initialize();
    		} catch(Exception ex) {
    			ex.printStackTrace();
    		}
    		System.setOut(new Logger(System.out));
    		System.setErr(new Logger(System.err));
    		System.out.println("Server Launched...");
     
    		/**
    		 * World Map Loader
    		 */
    		//if(!Config.SERVER_DEBUG)
    		//	VirtualWorld.init();
    		//WorldMap.loadWorldMap();	
     
    		/**
    		 * Script Loader
    		 */
    		//ScriptManager.loadScripts();
     
    		/**
    		 * Accepting Connections
    		 */
    		acceptor = new SocketAcceptor();
    		connectionHandler = new ConnectionHandler();
     
    		SocketAcceptorConfig sac = new SocketAcceptorConfig();
    		sac.getSessionConfig().setTcpNoDelay(false);
    		sac.setReuseAddress(true);
    		sac.setBacklog(100);
     
    		throttleFilter = new ConnectionThrottleFilter(Config.CONNECTION_DELAY);
    		sac.getFilterChain().addFirst("throttleFilter", throttleFilter);
    		acceptor.bind(new InetSocketAddress(serverlistenerPort), connectionHandler, sac);
     
    		/**
    		 * Initialise Handlers
    		 */
    		EventManager.initialize();
    		Connection.initialize();
    		//PlayerSaving.initialize();
    		//MysqlManager.createConnection();
     
    		/**
    		 * Server Successfully Loaded 
    		 */
    		System.out.println("Server is Listening on port: 43594");// + serverlistenerPort);
    		/**
    		 * Main Server Tick
    		 */
    		try {
    			while (!Server.shutdownServer) {
    				if (sleepTime >= 0)
    					Thread.sleep(sleepTime);
    				else
    					Thread.sleep(600);
    				engineTimer.reset();
    				itemHandler.process();
    				playerHandler.process();	//line 159
    	            npcHandler.process();
    				shopHandler.process();
    				objectManager.process();
    				fightPits.process();
    				pestControl.process();
     
    				cycleTime = engineTimer.elapsed();
    				sleepTime = cycleRate - cycleTime;
    				totalCycleTime += cycleTime;
    				cycles++;
    				debug();
    				if (System.currentTimeMillis() - lastMassSave > 300000) {
    					for(Player p : PlayerHandler.players) {
    						if(p == null)
    							continue;						
    						PlayerSave.saveGame((Client)p);
    						System.out.println("Saved game for " + p.playerName + ".");
    						lastMassSave = System.currentTimeMillis();
    					}
     
    				}
    			}
    		} catch (Exception ex) {
    			ex.printStackTrace();
    			System.out.println("A fatal exception has been thrown!");
    			for(Player p : PlayerHandler.players) {
    				if(p == null)
    					continue;						
    				PlayerSave.saveGame((Client)p);
    				System.out.println("Saved game for " + p.playerName + ".");
    			}
    		}
    		acceptor = null;
    		connectionHandler = null;
    		sac = null;
    		System.exit(0);
    	}

    Hopefully someone could help me here.
    Last edited by tomthebeast; April 12th, 2012 at 09:01 PM. Reason: Rephrase entire post.


  2. #2
    Junior Member
    Join Date
    Apr 2012
    Location
    Missouri, United States
    Posts
    17
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Default Re: Integer set in void, is being called upon.

    It looks like you've been mixing up the "==" operator with the "=" operator in several of your if loops. Here are all the instances I see:
    public void FinishCast() {
    		if (c.casting = false) { // should be ==, not =
    			return;
    		}
    ....

    public void process() {
    /* ton of irrelevant code */
    if (casting = true) { // should be ==, not =
    			if (castTime > 0) {
    				castTime = castTime - 0.6;
    			}
    			if ((castTime == 0) && (casting = true)) { // should be ==, not =
    				getSpells().FinishCast(); //line 759
    			}
    		}
    /* another 2k lines of irrelevant code */

    Hopefully that might fix the problem.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Integer set in void, is being called upon.

    Quote Originally Posted by Gigggas View Post
    It looks like you've been mixing up the "==" operator with the "=" operator in several of your if loops. Here are all the instances I see:
    public void FinishCast() {
    		if (c.casting = false) { // should be ==, not =
    			return;
    		}
    ....

    public void process() {
    /* ton of irrelevant code */
    if (casting = true) { // should be ==, not =
    			if (castTime > 0) {
    				castTime = castTime - 0.6;
    			}
    			if ((castTime == 0) && (casting = true)) { // should be ==, not =
    				getSpells().FinishCast(); //line 759
    			}
    		}
    /* another 2k lines of irrelevant code */

    Hopefully that might fix the problem.
    Thank you, so much, this was starting to give me a migraine.

Similar Threads

  1. [SOLVED] .show is called in card layout, but the frame didn't update
    By nggdowt in forum AWT / Java Swing
    Replies: 2
    Last Post: November 9th, 2011, 02:16 AM
  2. Replies: 1
    Last Post: November 2nd, 2011, 11:00 AM
  3. Replies: 0
    Last Post: February 22nd, 2010, 01:21 AM
  4. Replies: 0
    Last Post: February 2nd, 2010, 08:20 AM
  5. Calling a void method into a static void main within same class
    By sketch_flygirl in forum Object Oriented Programming
    Replies: 3
    Last Post: November 15th, 2009, 05:24 PM