Results 1 to 3 of 3
  1. #1
    ops2048 is offline Member
    Join Date
    May 2013
    Rep Power

    Question problem, calling a method

    Apologies for the amount of code in this question as I am not too sure as to what may or may not be relevant. I have included two (edited) classes, FleetOps, the main application class and CreateNewPlayer, which is called by the FleetView class, not included, which provides the applications gui.

    My problem lies in line 35 of the CreateNewPlayer class "if (!fleetOpsSession.checkforduplicateplayer(getUsern ame(), getPassword())) {".

    Eclipse insists that "fleetOpsSession cannot be resolved" yet I distinctly believe that I have instantiated an instance of FleetOps in the static main method. I feel that this indicates that I have some simple fundamental misconception. Can anybody point out where I am going wrong?

    Java Code:
    package FleetOpsControl;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.UIManager.*;
    import javax.swing.SwingUtilities;
    import FleetOpsModel.*;
    import FleetOpsView.*;
    public class FleetOps {
        protected String    playerName,
        protected Player    player;
        protected Game     game;
        protected List<Player>    players;
        protected List<Game>     games;
        protected Boolean duplicate;
        public FleetOps()    {
            players = new ArrayList<Player>();
            games = new ArrayList<Game>();
        public boolean checkforduplicateplayer(String username, String password) {
            return duplicate;
        public static void main(String[] args)    {
            FleetOps fleetOpsSession = new FleetOps();
            FleetView fleetOpsViewSession = new FleetView();
    Java Code:
    package FleetOpsView;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import FleetOpsControl.*;
    import FleetOpsModel.*;
    public class CreateNewPlayer    {
        JFrame frame;
        public CreateNewPlayer()    {
            frame = new JFrame();
            CreatePlayerDialog createPlayer = new CreatePlayerDialog(frame);
        public class CreatePlayerDialog extends JDialog {
            private JButton btnCreate;
            public CreatePlayerDialog(Frame parent) {
                super(parent, "Create new player", true);
                btnCreate = new JButton("Create");
                btnCreate.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        if (!fleetOpsSession.checkforduplicateplayer(getUsername(), getPassword())) {
                        } else {
                JPanel bp = new JPanel();
                getContentPane().add(bp, BorderLayout.PAGE_END);
            public String getUsername() {
                 return "";
            public String getPassword() {
                 return "";

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Rep Power

    Default Re: problem, calling a method

    fleetOpsSession is only locally known in FleetOps.main . If you need the instance in other classes, you have to pass it to them.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power

Similar Threads

  1. FileWriter/Method Calling Problem
    By javaNewblet in forum New To Java
    Replies: 8
    Last Post: 11-11-2011, 06:35 AM
  2. Calling method problem
    By jmoutia in forum New To Java
    Replies: 7
    Last Post: 10-24-2010, 09:06 AM
  3. Thread problem, calling method in run method
    By majk in forum Threads and Synchronization
    Replies: 4
    Last Post: 09-27-2010, 11:40 AM
  4. Problem calling a method
    By ToeJam in forum New To Java
    Replies: 5
    Last Post: 12-12-2009, 01:45 AM
  5. Replies: 29
    Last Post: 09-25-2008, 07:55 PM

Posting Permissions

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