Results 1 to 6 of 6
  1. #1
    rgeurts is offline Member
    Join Date
    May 2010
    Posts
    15
    Rep Power
    0

    Default Return a value from Method - error

    Hi,

    I am getting the following error message:
    cannot return a value from method whose result type is void
    Can someone please let me know what I'm doing wrong? Has it got something to do with the try-catch statement?

    Thanks

    Java Code:
    package test;
    
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    import com.crystaldecisions.sdk.exception.SDKException;
    import com.crystaldecisions.sdk.framework.*;
    import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
    import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
    import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
    import com.crystaldecisions.sdk.plugin.desktop.user.IUser;
    import com.crystaldecisions.sdk.occa.infostore.*;
    import com.crystaldecisions.sdk.plugin.*;
    import com.crystaldecisions.sdk.properties.*;
    import com.crystaldecisions.sdk.occa.security.*;
    
    public class TraverseSimpleTree extends JPanel {
    
        public TraverseSimpleTree(String[][] Usergroup) {
    
            IEnterpriseSession enterpriseSession;
            enterpriseSession = null;
            IInfoStore infoStore = null;
    
            enterpriseSession = null;
            try {
                System.out.println("Connecting..." + "\n");
    
                enterpriseSession = CrystalEnterprise.getSessionMgr().logon("geurtsr", "burung78", "LONMS10325:6400", "secEnterprise");
    
                System.out.println("The CMS connected to is: " + enterpriseSession.getCMSName() + "\n");
    
    
                infoStore = (IInfoStore) enterpriseSession.getService("InfoStore");
    
                IInfoObjects listOfGroupObjects = (IInfoObjects) infoStore.query("SELECT SI_ FROM CI_SYSTEMOBJECTS WHERE SI_KIND='UserGroup'");
    
                IInfoObject Groupobject;
                String userID;
                String uniqueGroup;
                String[] groupArray = new String[100];
                int useridint;
    
                Iterator groupItt = listOfGroupObjects.iterator();
                ArrayList groupList = new ArrayList();
                ArrayList userList = new ArrayList();
    
                while (groupItt.hasNext()) {
                    Groupobject = (IInfoObject) groupItt.next();
                    uniqueGroup = Groupobject.getTitle();
    
                    //System.out.println(useridint);
                    groupList.add(uniqueGroup);
                } //end while
    
                System.out.println(groupList);
                groupList.toArray(groupArray);
    
                IInfoObjects listOfInfoObjects = (IInfoObjects) infoStore.query("SELECT SI_ FROM CI_SYSTEMOBJECTS WHERE SI_KIND='User'");
    
                IInfoObject infoobject;
                Iterator i = listOfInfoObjects.iterator();
    
    
                while (groupItt.hasNext()) {
                    Groupobject = (IInfoObject) groupItt.next();
                    useridint = Groupobject.getID();
                    userID = ((Integer) useridint).toString();
    
                    IInfoObjects users = infoStore.query("Select TOP 1* From CI_SYSTEMOBJECTS Where SI_ID=" + userID);
                    if (users.size() == 0) {
                        // The query returned a blank collection (no object found).
                        System.out.println("The user account does not exist");
                    } else {
                        // Retrieve the object from the collection.
                        IInfoObject user = (IInfoObject) users.get(0);
    
                        // Check that the object has the correct ProgID
                        // i.e. that the object retrieved is indeed an User object
                        IProperties iObjectProps = user.properties();
                        IProperty iObjectProp = iObjectProps.getProperty(CePropertyID.SI_PROGID);
                        String iObjectPropVal = iObjectProp.getValue().toString();
                        // System.out.println("property value is: " + iObjectPropVal);
    
                        if (iObjectPropVal.equals(CeProgID.USER)) {
                            IUser boxiUser = (IUser) user;
                            // Obtain the set of groupArray which the user belongs to.
                            Object[] memberGroups = boxiUser.getGroups().toArray();
                            String[][] userGroup = new String[memberGroups.length][1];
                            for (int itt = 0; itt < memberGroups.length; itt++) {
    
                                // Retrieve each group from the infoStore.
                                IInfoObjects result = infoStore.query("SELECT SI_NAME FROM "
                                        + "CI_SYSTEMOBJECTS WHERE SI_ID=" + memberGroups[itt]);
                                IInfoObject iObject = (IInfoObject) result.get(0);
    
                                //Lookup the name for each user
                                String userName = user.properties().getProperty("SI_USERFULLNAME").toString();
                                String group = iObject.getTitle();
                                String cleanGroup = group.replaceAll("SecRole \\(", "");
                                String groupName = cleanGroup.replaceAll("\\)", "");
    
                                userGroup[itt][1] = userName;
                                userGroup[itt][0] = group;
    
                            }
    
                        } else {
                            System.out.println("No groups available");
                        }
                    }
    
                } //end while
                [COLOR="Red"]return userGroup;[/COLOR]
            }//end try
            catch (SDKException lException) {
                lException.printStackTrace();
    
            }//end catch
    
        }
    }

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    One of your methods is not declared properly, as an example:

    Java Code:
    public void getString() {
        return myString;
    }

    wont work because you need to set the return type to String like this:

    Java Code:
    public String getString() {
        return myString;
    }

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    In your method definition you didn't specified the return type.The default return type is void.
    Java Code:
     public TraverseSimpleTree(String[][] Usergroup) {

    at the end of this method,you tried to return something
    Java Code:
       } //end while
                return userGroup;
            }//end try
    Please,You should learn a little bit more on methods.


    Regards
    Ujjal

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    ah Ujjal spotted it, i couldn't find the return statement in your method

  5. #5
    rgeurts is offline Member
    Join Date
    May 2010
    Posts
    15
    Rep Power
    0

    Default

    Thanks Ujjal for spotting the error and proposing a fix.

  6. #6
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    Thanks Ujjal for spotting the error and proposing a fix.
    My pleasure.

    If you are satisfied,then you can press REP for me.oh and for ozzyman also.

    Regards
    Ujjal

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 09:05 PM
  2. Method won't return value
    By footyvino in forum New To Java
    Replies: 2
    Last Post: 03-26-2010, 11:49 AM
  3. Replies: 1
    Last Post: 03-10-2010, 02:53 PM
  4. Replies: 5
    Last Post: 01-17-2010, 12:14 AM
  5. Return value of method
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 09:23 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
  •