Results 1 to 10 of 10
  1. #1
    Dom
    Dom is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default getIp Function finding wrong type

    Java Code:
    public String getIP(int channel) {
            return channelServer.get(channel);
        }
    Java Code:
    C:\Users\Dan\Desktop\Source\src\net\login\LoginServer.java:81: incompatible types
    found   : java.util.Map<java.lang.Integer,java.lang.String>
    required: java.lang.String
            return channelServer.get(channel);
    1 error
    BUILD FAILED (total time: 3 seconds)
    What is wrong? If you need any whole files, please post so.
    Last edited by Dom; 06-29-2010 at 12:48 AM.

  2. #2
    Spike_CT is offline Member
    Join Date
    Jan 2010
    Posts
    14
    Rep Power
    0

    Default

    Most likely:

    the function channelServer.get() returns a map of Integers to Strings instead of one single String. Because getIP wants to return a String and you are returning an map of Intgers to strings ( channelServer.get() ) it will complain about a mismatch.

  3. #3
    Dom
    Dom is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    I figured it out, I had it so instead of just channel, it needed to find the world as well.

    Fixed Function:
    Java Code:
    public String getIP(int world, int channel) {
            return channelServer.get(world).get(channel);
        }
    But now I have another problem, this file is giving errors cause the 2 lines don't include world, only channel. Can you explain what I need to add to the lines?
    Java Code:
    package net.login.handler;
    
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    
    import client.MapleClient;
    import net.AbstractMaplePacketHandler;
    import net.login.LoginServer;
    import tools.MaplePacketCreator;
    import tools.data.input.SeekableLittleEndianAccessor;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class CharSelectedWithPicHandler extends AbstractMaplePacketHandler {
    	private static Logger log = LoggerFactory.getLogger(CharSelectedWithPicHandler.class);
    	@Override
    	public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    
            String pic = slea.readMapleAsciiString();
    		int charId = slea.readInt();
    		String macs = slea.readMapleAsciiString();
    		c.updateMacs(macs);
    
    		if (c.checkPic(pic)) {
    
    		if (c.hasBannedMac()) {
    			c.getSession().close(true);
    			return;
    		}
    		try {
    			if (c.getIdleTask() != null) {
    				c.getIdleTask().cancel(true);
    			}
    			//c.getSession().write(MaplePacketCreator.getServerIP(InetAddress.getByName("127.0.0.1"), 7575, charId));
    			c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
    
    			String channelServerIP = MapleClient.getChannelServerIPFromSubnet(c.getSession().getRemoteAddress().toString().replace("/", "").split(":")[0], c.getChannel());
    			if(channelServerIP.equals("0.0.0.0")) {
    				[B]String[] socket = LoginServer.getInstance().getIP(c.getChannel()).split(":");[/B]
    				c.getSession().write(MaplePacketCreator.getServerIP(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]), charId));
    			} else {
    				[B]String[] socket = LoginServer.getInstance().getIP(c.getChannel()).split(":");[/B]
    				c.getSession().write(MaplePacketCreator.getServerIP(InetAddress.getByName(channelServerIP), Integer.parseInt(socket[1]), charId));
    			}
    		} catch (UnknownHostException e) {
    			log.error("Host not found", e);
    		}
    
                    } else {
    
                c.getSession().write(MaplePacketCreator.wrongPic());
                }
            }
    }
    I bolded the 2 lines.

    I would think it would be something like this, but its not because it says "int can not be deferenced"
    String[] socket = LoginServer.getInstance().getIP(c.getWorld().getCh annel()).split(":");
    Last edited by Dom; 06-29-2010 at 12:59 AM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default

    this file is giving errors
    Please copy and paste the FULL text of the error messages here.

  5. #5
    Dom
    Dom is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Java Code:
    init:
    deps-clean:
    Deleting directory C:\Users\Dan\Desktop\Source\build
    clean:
    init:
    deps-jar:
    Created dir: C:\Users\Dan\Desktop\Source\build\classes
    Compiling 433 source files to C:\Users\Dan\Desktop\Source\build\classes
    C:\Users\Dan\Desktop\Source\src\net\login\handler\CharSelectedWithPicHandler.java:42: int cannot be dereferenced
                        String[] socket = LoginServer.getInstance().getIP(c.getWorld().getChannel()).split(":");
    C:\Users\Dan\Desktop\Source\src\net\login\handler\CharSelectedWithPicHandler.java:45: int cannot be dereferenced
                        String[] socket = LoginServer.getInstance().getIP(c.getWorld().getChannel()).split(":");
    C:\Users\Dan\Desktop\Source\src\net\login\handler\RegisterPicHandler.java:39: int cannot be dereferenced
                        String[] socket = LoginServer.getInstance().getIP(c.getWorld().getChannel()).split(":");
    C:\Users\Dan\Desktop\Source\src\net\login\handler\RegisterPicHandler.java:42: int cannot be dereferenced
                        String[] socket = LoginServer.getInstance().getIP(c.getWorld().getChannel()).split(":");
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    4 errors
    BUILD FAILED (total time: 2 seconds)
    This Line:
    Java Code:
    String[] socket = LoginServer.getInstance().getIP(c.getWorld().getChannel()).split(":");
    needs to work for this function:
    Java Code:
    public String getIP(int world, int channel) {
            return channelServer.get(world).get(channel);
        }

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default

    int cannot be dereferenced
    The error message says you are using an int for a reference.
    For example:
    int notObject = 1;
    notObject.toString(); // int can't be used here

    Check what ALL the methods return in your long chain. One must return an int.

  7. #7
    Dom
    Dom is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    yea...

    Java Code:
    public int channel = 1;
    Java Code:
    private int world;
    So how do i fix the fact I cant reference an int?
    Last edited by Dom; 06-29-2010 at 02:25 AM.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default

    So how do i fix the fact I cant reference an int
    An interesting question for a programmer!
    Use the int to index an array of objects.

    You can only reference objects. An int is an int. It has no members or methods. Only a value.

  9. #9
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by Dom View Post
    Java Code:
    public String getIP(int channel) {
            return channelServer.get(channel);
        }
    Java Code:
    C:\Users\Dan\Desktop\Source\src\net\login\LoginServer.java:81: incompatible types
    found   : java.util.Map<java.lang.Integer,java.lang.String>
    required: java.lang.String
            return channelServer.get(channel);
    1 error
    BUILD FAILED (total time: 3 seconds)
    What is wrong? If you need any whole files, please post so.
    Nice, compiling odinMS

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default

    Presumbaly getWorld returns an int...
    So just pass that in for the world parameter.
    And presumably you also have a getChannel on MapleClient, so use that to pass the channel through.

Similar Threads

  1. Replies: 3
    Last Post: 12-04-2009, 04:08 PM
  2. Error if someone enters the wrong data type
    By lithium002 in forum New To Java
    Replies: 43
    Last Post: 11-16-2009, 05:41 PM
  3. Replies: 4
    Last Post: 07-23-2009, 10:45 PM
  4. Replies: 1
    Last Post: 11-11-2008, 09:18 PM
  5. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •