Results 1 to 8 of 8
  1. #1
    jamejo is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Post Introduction & A Quick Big Doubt

    Dear All,
    I am new here, i have started learning java directly just since over a week, i got my interest in Java from knowing about applications and things "My Name is James Joseph" and please find below a sample code, i need you guys advice on!

    Java Code:
     public void bind() {
     debug.enter(this, "SMPP.bind()");
            try {
    
                if (bound) {
                    this.unbind();
                    return;
                }
    
                BindRequest request = null;
                BindResponse response = null;
                String syncMode = "a";// (asynchronous ? "a" : "s");
    
                // type of the session
                syncMode = "a";//getParam("Asynchronous/Synchronnous Session? (a/s)", syncMode);
                asynchronous = false;
    
    
                // input values
                bindOption = "t";// getParam("Transmitter/Receiver/Transciever (t/r/tr)", bindOption);
                request = new BindTransciever();
    
                ipAddress = ipAddress;
                port = port;
    
                TCPIPConnection connection = new TCPIPConnection(ipAddress, port);
                connection.setReceiveTimeout(20 * 1000);
                session = new Session(connection);
    
    
                systemId = systemId;
                password = password;
    
                // set values
                request.setSystemId(systemId);
                request.setPassword(password);
                request.setSystemType(systemType);
                request.setInterfaceVersion((byte) 0x34);
                request.setAddressRange(addressRange);
    
    
                // send the request
                System.out.println("Bind request " + request.debugString());
               if (asynchronous) {
                    pduListener = new SMPPTestPDUEventListener(session);
                    response = session.bind(request, pduListener);
                } else {
                    response = session.bind(request);
    
                }
    
                logger.info("Bind response " + response.debugString());
                if (response.getCommandStatus() == Data.ESME_ROK) {
                    bound = true;
                }
    
            } catch (Exception e) {
                event.write(e, "");
                debug.write("Bind operation failed. " + e);
                System.out.println("Bind operation failed. " + e);
               // return "Error-" + e.getMessage();
            } finally {
                debug.exit(this);
            }
        }
    Now the problem is, how do i change it to String the bind function ? and get its response? for a newbie to java this is too big of an advanced problem! would take any positive and negative advice ) i tried a lot but the whole app would give errors :(

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,311
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jamejo View Post
    Now the problem is, how do i change it to String the bind function ? and get its response? for a newbie to java this is too big of an advanced problem! would take any positive and negative advice ) i tried a lot but the whole app would give errors :(
    I don't think I undestand your question; do you want your method to return a (String) value? (the Java jargon is 'method', not 'function' but they are equivalent). Or do you want to pass parameters to your method? Note that a method can return a (a single) value of any type.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    jamejo is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Dear JosAh,

    Exactly what you mentioned "I want this method to return a string" :)

    Thanks for the response...

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,311
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jamejo View Post
    Dear JosAh,

    Exactly what you mentioned "I want this method to return a string" :)

    Thanks for the response...
    Well, you have to specify that your method returns a String:

    Java Code:
    public String bind() {
       // the body of your method here where it somewhere
       // returns a String value
    }
    Is this what you have in mind?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    jamejo is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Well, you have to specify that your method returns a String:

    Java Code:
    public String bind() {
       // the body of your method here where it somewhere
       // returns a String value
    }
    Is this what you have in mind?

    kind regards,

    Jos


    Yes Josah, thats whats on my mind but when i do use public String bind() {

    it gives me an error saying "Missing return statement"

    i tried few things, but no luck..

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,311
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jamejo View Post
    Yes Josah, thats whats on my mind but when i do use public String bind() {

    it gives me an error saying "Missing return statement"

    i tried few things, but no luck..
    The compiler issues that error message when it finds a path in the execution of your method body that doesn't result in a 'return someStringValue;'. Your method was declared to return a String so it always should do so; this is a simple example where the method doesn't always return a String:

    Java Code:
    public String bind() {
       if (a > b)
          return "foo";
    }
    Suppose a <= b, so the body of the if statement isn't executed and nothing is returned by the method. The compiler whines about it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    jamejo is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Jos, i will study this and get back to you on how i succeed at fixing it... :) with your advice...

    Thanks a ton :)

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,311
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jamejo View Post
    Jos, i will study this and get back to you on how i succeed at fixing it... :) with your advice...os

    Thanks a ton :)
    You're welcome of course; Java's compiler messages are as clear as they come, all you have to learn is how to interpret those messages. You'll learn how to do that by making mistakes, reading what the compiler has to say about it and (most important), why the compiler issued the message. Assuming that your code is correct is extremely dangerous and most of the time simply incorrect ;-)

    kind regards,

    J
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Introduction
    By goldhouse in forum Lucene
    Replies: 2
    Last Post: 01-17-2010, 12:56 PM
  2. introduction
    By Rooneyz in forum Introductions
    Replies: 4
    Last Post: 08-11-2008, 02:14 PM
  3. Introduction
    By priyasajesh in forum Introductions
    Replies: 4
    Last Post: 07-30-2008, 01:30 AM
  4. introduction
    By khalandar in forum Introductions
    Replies: 4
    Last Post: 07-09-2008, 07:48 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
  •