Stumped with SwingWorker -- code compiles but doesn't run right

Okay, sorry to post a ton of code, but I'm creating a swing gui that will use swing worker to create an object of the followng class, one method that sleeps and returns a random number:
public class BigJob{
     public int doBigJob(){
          try {
          Thread.sleep(15000);
          } catch (InterruptedException e){
          e.printStackTrace();
     int number = (int)(Math.random() * 50);
     return number;
}I can get the gui program below to run without the SwingWorker, but am having trouble getting it to run properly. The code posted below compiles and starts up ok, but when I click the "click to do big job" button, it just doesn't do anything.
I created a runnable in the main method, and invoked the method to build the gui, so that's working.
I have the SwingWorker defined in an inner class that implements ActionListener; I'm guessing that's the problem. I should probably put the SwingWorkder in its own inner class, and invoke it from the first listener class?
here's the code:
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import javax.swing.SwingWorker;
public class WorkerTest{
     private JFrame frame;
     private JButton button1;
     private JButton button2;
     private JButton button3;
     private JPanel topPanel;
     public static void main (String[] args){
     SwingUtilities.invokeLater(new Runnable() {
          public void run(){
          WorkerTest wtest = new WorkerTest();
          wtest.buildGui();
     } // end main
     public void buildGui(){
     frame = new JFrame("frame to test swing worker");
     frame.setSize(700,200);
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     frame.setLayout(new BorderLayout());
     topPanel = new JPanel();
     frame.add(topPanel, BorderLayout.NORTH);
     button1 = new JButton("click to change text");
     button1.addActionListener(new Button1Listener());
     button2 = new JButton("click to do big thing");
     button1.addActionListener(new Button2Listener());
     button3 = new JButton("click to change text");
     button3.addActionListener(new Button3Listener());
     topPanel.add(button1);
     topPanel.add(button2);
     topPanel.add(button3);
     frame.setVisible(true);
// inner classes to add listeners
     class Button1Listener implements ActionListener{
          public void actionPerformed(ActionEvent e){
          button1.setText("i've been clicked");
     class Button2Listener implements ActionListener{
          public void actionPerformed(ActionEvent e){
          // execute job in main thread
          //BigJob job = new BigJob();
          //button2.setText("big job is done: " + job.doBigJob());
          // execute job in its own thread:
          SwingWorker worker = new SwingWorker<BigJob, Void>(){
          BigJob job;
          int resultNum;
               public BigJob doInBackground(){
               job = new BigJob();
               resultNum = job.doBigJob();
               button2.setText("big job done: " + resultNum);
               return job;
     class Button3Listener implements ActionListener{
          public void actionPerformed(ActionEvent e){
          button3.setText("i've been clicked also");
} // end WorkerTestthanks,
bp

badperson wrote:
where in the code should that go, in the listener class?
SwingWorker worker = new SwingWorker<BigJob, Void>() {
    public BigJob doInBackground() {
        // code
     return job;
worker.execute();

Similar Messages

  • SQLJ/JDBC code compiles but doesn't run

    I keep getting a fatal error in the JAVA.EXE module when I try to run an code with SQLJ/JDBC. I've got my class and classpath set up like a oracle support tech told me to do but the code still bombs.
    I noticed java.exe bombs at the same address no matter what SQLJ/JDBC code I compile.
    Could it be conflicting with something on
    a NT 4.0 box.
    Anyone with ideas please respond.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by MSCHWERY ():
    I keep getting a fatal error in the JAVA.EXE module when I try to run an code with SQLJ/JDBC. I've got my class and classpath set up like a oracle support tech told me to do but the code still bombs.
    I noticed java.exe bombs at the same address no matter what SQLJ/JDBC code I compile.
    Could it be conflicting with something on
    a NT 4.0 box.
    Anyone with ideas please respond.<HR></BLOCKQUOTE>
    Can you run a non Oracle Java application. Which version of JDK are you using.. do you have multiple versions of JDK .. if so make sure there is no conflict.. You may try re-installing the JDK if your non Oracle Java application also errors out..

  • PLSQL compiles but doesn't run.. I've declared it everywhere but still..

    PLSQL compiles but doesn’t run.. I’ve declared it everywhere but still..
    Afternoon.. Hopefully a quick one for someone.. I’m trying to run a Concurrent Program in ORACLE Financials using a Data Template derived BI Publisher report.
    Error message received..
    SUBIXCLT module: UofS Expense Claim Tracking Report
    +--------------------------------------------------------------------------
    All Parameters: raisedby=:status=:claimant=:expense_date_from=:expense_date_to=:LP_ORDERED_BY=Expense Report Number
    Data Template Code: SUBIXCLT
    Data Template Application Short Name: PO
    Debug Flag: N
    {raisedby=, claimant=, expense_date_to=, expense_date_from=, status=, LP_ORDERED_BY=Expense Report Number}
    Calling XDO Data Engine...
    [060410_025628319][][STATEMENT] Start process Data
    [060410_025628324][][STATEMENT] Process Data ...
    [060410_025628329][][STATEMENT] Executing data triggers...
    [060410_025628329][][STATEMENT] BEGIN
    SUBIXCLT.claimant := :claimant ;
    SUBIXCLT.expense_date_from := :expense_date_from ;
    SUBIXCLT.expense_date_to := :expense_date_to ;
    SUBIXCLT.raisedby := :raisedby ;
    SUBIXCLT.status := :status ;
    SUBIXCLT.lp_ordered_by := :lp_ordered_by ;
    :XDO_OUT_PARAMETER := 1;
    END;
    l_flag Boolean;
    BEGIN
    l_flag := SUBIXCLT.BEFOREREPORT(L_ORDERED) ;
    if (l_flag) then
    :XDO_OUT_PARAMETER := 1;
    end if;
    end;
    [060410_025628356][][EXCEPTION] SQLException encounter while executing data trigger....
    java.sql.SQLException: ORA-06550: line 4, column 33:
    PLS-00201: identifier 'L_ORDERED' must be declared
    ORA-06550: line 4, column 1:
    PL/SQL: Statement ignoredThe Data Template
    The Data Template
    <?xml version="1.0" encoding="utf-8" ?>
    - <dataTemplate name="UofS_OutstandngExpenses_Report" defaultPackage="SUBIXCLT" dataSourceRef="FINDEV" version="1.0">
    - <properties>
      <property name="xml_tag_case" value="upper" />
      <property name="include_parameters" value="true" />
      <property name="debug_mode" value="on" />
      </properties>
    - <parameters>
      <parameter name="claimant" dataType="character" defaultValue="" />
      <parameter name="expense_date_from" dataType="date" defaultValue="" />
      <parameter name="expense_date_to" dataType="date" defaultValue="" />
      <parameter name="raisedby" dataType="character" defaultValue="" />
      <parameter name="status" dataType="character" defaultValue="" />
      <parameter name="lp_ordered_by" dataType="character" defaultValue="" />
      </parameters>
    - <dataQuery>
      <dataTrigger name="beforeReportTrigger" source="SUBIXCLT.BEFOREREPORT(L_ORDERED)" />
    - <sqlStatement name="Q1">
    - <![CDATA[
    SELECT DISTINCT
    erh.invoice_num,
    pap.full_name EMP_CLAIMING,
    DECODE(NVL(erh.expense_status_code, 'Not yet Submitted (NULL)'), 'CANCELLED', 'CANCELLED',
         'EMPAPPR', 'Pending Individuals Approval',      'ERROR', 'Pending System Administrator Action',
         'HOLD_PENDING_RECEIPTS     ', 'Hold Pending Receipts', 'INPROGRESS', 'In Progress', 'INVOICED', 'Ready for Payment',
         'MGRAPPR', 'Pending Payables Approval', 'MGRPAYAPPR', 'Ready for Invoicing', 'PAID', 'Paid',
         'PARPAID', 'Partially Paid',     'PAYAPPR', 'Payables Approved',     'PENDMGR', 'Pending Manager Approval',
         'PEND_HOLDS_CLEARANCE', 'Pending Payment Verification',     'REJECTED', 'Rejected',     'RESOLUTN',     'Pending Your Resolution',
         'RETURNED',     'Returned',     'SAVED',     'Saved',     'SUBMITTED',     'Submitted',     'UNUSED',     'UNUSED',
         'WITHDRAWN','Withdrawn',     'Not yet Submitted (NULL)') "EXPENSE_STATUS" ,
    NVL(TO_CHAR(erh.report_submitted_date,'dd-MON-yyyy'),'NULL') SUBMIT_DATE,
    NVL(TO_CHAR(erh.expense_last_status_date,'dd-MON-yyyy'),'NULL') LAST_UPDATE,
    erh.override_approver_name ER_Approver,
    fu.description EXP_ADMIN,
    erh.total,
    erh.description 
    FROM
    AP_EXPENSE_REPORT_HEADERS_all erh,
    per_all_people_f pap, fnd_user fu
    WHERE erh.employee_id = pap.person_id
    AND fu.user_id = erh.created_by
    AND NVL(erh.expense_status_code, 'Not yet Submitted') NOT IN  ('MGRAPPR', 'INVOICED', 'PAID', 'PARPAID')
    AND pap.full_name = NVL(:claimant, pap.full_name)
    AND TRUNC(erh.report_submitted_date) BETWEEN NVL(:expense_date_from, '01-JAN-1999') AND NVL(:expense_date_to,'31-DEC-2299')
    AND fu.description = NVL(:raisedby,fu.description)
    AND erh.expense_status_code = NVL(:status,erh.expense_status_code) &LP_ORDERED_BY
      ]]>
      </sqlStatement>
      </dataQuery>
      <dataTrigger name="beforeReportTrigger" source="SUBIXCLT.BEFOREREPORT(L_ORDERED)" />
    - <dataStructure>
    - <group name="G_XP_CLM_TRACKNG" source="Q1">
      <element name="INVOICE_NUM" value="INVOICE_NUM" />
      <element name="EMP_CLAIMING" value="EMP_CLAIMING" />
      <element name="EXPENSE_STATUS" value="EXPENSE_STATUS" />
      <element name="SUBMIT_DATE" value="SUBMIT_DATE" />
      <element name="LAST_UPDATE" value="LAST_UPDATE" />
      <element name="LP_ORDERED_BY" dataType="varchar2" value="SUBIXCLT.LP_ORDERED_BY" />
      </group>
      </dataStructure>
      </dataTemplate>The PL SQL..
    The PL SQL..
    CREATE OR REPLACE PACKAGE Subixclt IS
    L_ORDERED  VARCHAR2(50);
    RAISEDBY VARCHAR2(50);
    STATUS VARCHAR2(50);
    CLAIMANT VARCHAR2(50);
    LP_ORDERED_BY VARCHAR2(50);
    FUNCTION BEFOREREPORT(L_ORDERED IN VARCHAR2) RETURN VARCHAR2;
    EXPENSE_DATE_FROM DATE;
    EXPENSE_DATE_TO DATE;
    --RETURN VARCHAR2;
    END;
    CREATE OR REPLACE PACKAGE BODY Subixclt IS
    FUNCTION BEFOREREPORT(L_ORDERED IN VARCHAR2)RETURN VARCHAR2 IS
    BEGIN
    Fnd_File.PUT_LINE(Fnd_File.LOG,'L_ORDERED'||L_ORDERED);
    DECLARE
    LP_ORDERED_BY VARCHAR2(50);
    L_ORDERED  VARCHAR2(50);
    RAISEDBY VARCHAR2(50);
    STATUS VARCHAR2(50);
    CLAIMANT VARCHAR2(100);
    EXPENSE_DATE_FROM DATE;
    EXPENSE_DATE_TO DATE;
    BEGIN
    IF (LP_ORDERED_BY='Expense Report Number') THEN
         LP_ORDERED_BY :='order by 1 asc;';
      ELSIF (LP_ORDERED_BY='Person Claiming') THEN
         LP_ORDERED_BY :='order by 2 asc;';
      ELSIF (LP_ORDERED_BY='Submit Date') THEN
      LP_ORDERED_BY :='order by 4 asc;';
      END IF;
    RETURN(L_ORDERED);
    --RETURN NULL;
    END;
    END;
    END;Thanks for looking..
    Steven
    Edited by: Mr_Alkan on Jun 4, 2010 3:35 PM

    One has to initialise a session first for use with Oracle Apps if you want to make it run as a concurrent job.
    Any decleration within your package will not be recognised unless initialisation is sucessful.
    Investigate the built-in packages:
    FND_GLOBAL - for initialisation
    FND_SUBMIT - for setting session relevant parameters
    -- function returns true or false depending on whether the initialisation was sucessful or not
    create or replace function is_Init_OK (p_User_Name       in varchar2
                                          ,p_Responsibility  in varchar2
                                          ,p_Language        in varchar2) return boolean as
      b_Set_NLS   boolean;
      b_Set_Mode  boolean;
      r_ISet      fnd_Init := Get_Init_Set(p_User_Name, p_Responsibility);
      begin
        -- 1
        fnd_global.apps_initialize(r_ISet.User_ID, r_ISet.Resp_ID, r_ISet.App_ID);
        -- 2
        b_Set_NLS := fnd_submit.set_nls_options(p_Language);
        -- 3
        b_Set_Mode  := fnd_submit.set_mode (false);
        return (b_Set_Mode and b_Set_NLS and (    (r_ISet.Resp_ID is not null)
                                              and (r_ISet.User_ID is not null)
        exception
          when others then
            return false;
    end is_Init_OK;
    -- for example
    declare
      l_User_ID number = 'IMPORT_POST'; --- import post user
      l_Resp    number =  'Import and Posting responsibility' -- import posting responsibility
      l_Language varchar2(100) := 'AMERICAN';
      b_Init boolean := false;
      INIT_EXCEPTION exception;
    begin
      b_Init := is_Init_OK(l_User_ID, l_Resp, l_Language);
      if (not b_Init) then
        raise INIT_EXCEPTION;
      end if;
      -- conitnue with your processing
      exception 
        when others then
          when INIT_EXECPTION then
          when others then
    end;
    /

  • Compiles, but doesn't run - also objects used like arrays?

    Hello. I am a way newbie at Java, but I like it a lot. I'm using it to write a little final project for an intro CS class I'm taking. The program is a little mileage calcuator. Okay, so here's what I don't get. I started to write out the program and everything was compiling, my output and input were working. Then I started to add some classes and objects. Now it still compiles, but the command line just gives me "hit any key". None of my output or input stuff. What happened?
    While I'm at it, in C++ I would've used a little array to store a bit of data for this app. Can I use multile objects of a class and iterate through them in a for each in the same way?
    Any help much appreciated.
    Here's the code:
    //Joanna Grossman
    //mileage calculator
    //final project SWE 150
    //creates vehicle class
    class vehicle {
         int id;
         String name;
         int mpg;
    //creates different vehicle objects - may need to be changed to array
    class vehicleTypes {
         public static void main(String args[]) {
              vehicle SUV = new vehicle();
              vehicle hybrid = new vehicle();
              vehicle FordTaurus = new vehicle();
              //assigns values for cars
              SUV.id = 1;
              SUV.name = "SUV";
              SUV.mpg = 10;
              hybrid.id = 2;
              hybrid.name = "Honda Civic";
              hybrid.mpg = 50;
              FordTaurus.id = 3;
              FordTaurus.name = "Ford Taurus";
              FordTaurus.mpg = 23;
    //creates location class
    class location {
         int id;
         String name;
         int miles2Loc1;
         int miles2Loc2;
         int miles2Loc3;
    //creates location objects
    class locationObjects {
         public static void main(String args[]) {
              location Burlington = new location();
              location NewYork = new location();
              location Syracuse = new location();
              //assigns values to locations
              Burlington.id = 1;
              NewYork.id=2;
              Syracuse.id = 3;
              Burlington.name = "Burlington";
              Burlington.miles2Loc1 = 0;
              Burlington.miles2Loc2 = 308;
              Burlington.miles2Loc3 = 270;
              NewYork.name = "New York";
              NewYork.miles2Loc1 = 308;
              NewYork.miles2Loc2 = 0;
              NewYork.miles2Loc3 = 246;
              Syracuse.name = "Syracuse";
              Syracuse.miles2Loc1 = 270;
              Syracuse.miles2Loc2 = 246;
              Syracuse.miles2Loc3 = 0;
    //mainline logic
    class mileageCalculator {
         public static void main(String args[])
              throws java.io.IOException {
              char play;
              play='y';
                   System.out.println("Would you like to calculate your mileage?");
                   System.out.println("Please press \"y\" for \'yes\' or \"n\" for \'no\'\nThen Press \"Enter\"");
                   play = (char) System.in.read();
                   System.out.println("Your answer is "+play);
                   System.out.println("What is your destination?");
                   System.out.println("Press press it's number:");
                   System.out.println("1\tBurlington\n2\tNew York\n3\tSyracuse");
    }

    You're probably "running" one of the classes that doesn't produce any output. The main() method is intended to be an application's entry point, not someplace you just cram all your code. You'll want to learn about methods and how objects communicate with each other. Have a look at the following:
    The Java� Tutorial - Trail: Learning the Java Language
    Good luck!
    ~

  • Old C socket program compiles, but doesn't run properly

    I have an old C program that uses sys/ipc.h to listen on ports 6666 and ports 6669 for user requests. I have determined that the
    program gets to the 'accept' call without error. The return from accept(sockfd, (struct sockaddr *) &cli_addr, &cli_addrlen) is zero
    indicating success. Nevertheless, something is wrong, because netstat -a shows nothing listening on either 6666 or 6669, and
    telnet to these two ports fails as well.
    I've compiled and run the program on Sparc 8 and 9. It is the i86pc architecture I am having a problem with. I tried having root
    run it in the global zone in order to eliminate zones as a factor with no success.
    This program also uses threads (thread.h) and rpc (rpc.h). Has anyone seen this problem? Does anyone have a suggestion?
    George

    Hi Darren:
    Thanks for your prompt supply. I saw no alternative but to start pulling the code apart and I believe I have a solution. I think big-endian as opposed to
    little-endian definitely has something to do with it.
    Here's what I had to change to make this work:
    Original Code: serv_addr.sin_port = htonl(port);
    Modified Code: serv_addr.sin_port = htons((short) port);
    Converting the port to a short seems to have fixed things. The original code converted the port to a long.

  • Java 1.5_16 Compiles my programs but doesn't Run?

    I am using Dr Java and I have a lot of old programs that I would like to run.
    I had to start over and re-download the Java JDK. I tried 1.6.7 but I got an error that it couldn't
    locate the source, so I went back to Java 1.5.16, which was the oldest version I could find on java.,
    and now my programs are compiling but when I run them, I get a message in the bottom bar
    "Running Main method of Current Document" and nothing happens (even after a few minutes).
    This is happening on very simple small programs that should run instantly.
    It is happening for all of the old programs that I am able to compile.
    I think I was using JDK 1.5.6 when I first wrote these programs.
    Any suggestions?
    Thanks,
    Jesi

    You're probably "running" one of the classes that doesn't produce any output. The main() method is intended to be an application's entry point, not someplace you just cram all your code. You'll want to learn about methods and how objects communicate with each other. Have a look at the following:
    The Java� Tutorial - Trail: Learning the Java Language
    Good luck!
    ~

  • Code compiles but wont run

    Hi,
    My prgram was working fine until I added some database stuff to it, now it will compile but it wont run, heres my relevent code:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.sql.*;
    public class DisplayController extends JFrame 
         public JTextField txtTime, txtInterest, txtAmount;
         public JLabel lblTotal;
         static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
         static final String DATABASE_URL = "jdbc:mysql://localhost/Money?user=root&password=root";
         private Connection conn;
         private Statement stat;
         public JComboBox accountList;
         Vector vector1 = new Vector();
         ButtonHandler theButtonHandler = new ButtonHandler(txtTime, txtAmount, txtInterest, lblTotal);
       // set up GUI
       public DisplayController()
          super( "Goon Money Manager " );
          JTabbedPane tabbedPane = new JTabbedPane();
              /* sets up the transactions window and adds
                   it to the tabbedPane,this is where all the
                   transactions for all the accouns are displayed.
         try
                   Class.forName(JDBC_DRIVER);
                   conn = DriverManager.getConnection(DATABASE_URL);
                   stat = conn.createStatement();
                   ResultSet rs = stat.executeQuery("SELECT heading1 FROM demo");
                   while(rs.next()) vector1.add(rs.getObject(1));
              catch(SQLException sqlException)
                   System.exit(1);
              catch (ClassNotFoundException classNotFound)
                   System.exit(1);
              }

    thats exactly what I put in... what else can I do so I can see whats going on? Here's the entire code in case you need it:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.sql.*;
    public class DisplayController extends JFrame 
         public JTextField txtTime, txtInterest, txtAmount;
         public JLabel lblTotal;
         static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
         static final String DATABASE_URL = "jdbc:mysql://localhost/Money?user=root&password=root";
         private Connection conn;
         private Statement stat;
         public JComboBox accountList;
         Vector vector1 = new Vector();
         ButtonHandler theButtonHandler = new ButtonHandler(txtTime, txtAmount, txtInterest, lblTotal);
       // set up GUI
       public DisplayController()
          super( "Goon Money Manager " );
          JTabbedPane tabbedPane = new JTabbedPane();
    /* sets up the transactions window and adds
         it to the tabbedPane,this is where all the
         transactions for all the accouns are displayed.
          try
                   Class.forName(JDBC_DRIVER);
                   conn = DriverManager.getConnection(DATABASE_URL);
                   stat = conn.createStatement();
                   ResultSet rs = stat.executeQuery("SELECT accountName FROM Money");
                   while(rs.next()) vector1.add(rs.getObject(1));
              catch(SQLException sqlException)
                   System.exit(1);
                   sqlException.printStackTrace();
              catch (ClassNotFoundException classNotFound)
                   System.exit(1);
                   classNotFound.printStackTrace();
          JTextArea mainWindow = new JTextArea(600,300);
              accountList = new JComboBox(vector1);
              JPanel displayTabPanel = new JPanel(new FlowLayout());
              displayTabPanel.setLayout(new FlowLayout() );
              displayTabPanel.add(accountList);
              displayTabPanel.add(new JScrollPane(mainWindow));
              tabbedPane.addTab("Transactions",null,displayTabPanel,"Transaction List");
              accountList.addListSelectionListener(
              new ListSelectionListener()
                   public void valueChanged(ListSelectionEvent event)
                        try
                             ResultSet resultSet = stat.executeQuery("SELECT * FROM demo");
                             StringBuffer results = new StringBuffer();
                             ResultSetMetaData metaData = resultSet.getMetaData();
                             int numberOfColumns = metaData.getColumnCount();
                             for(int i = 1; i<=numberOfColumns; i++)
                             results.append(metaData.getColumnName(i) + "\t");
                             results.append("\n");
                             while (resultSet.next())
                                  for(int i = 1; i<= numberOfColumns; i++)
                                  results.append(resultSet.getObject(i) + "\t");
                                  results.append("\n");
                        catch(SQLException sqlException)
                             JOptionPane.showMessageDialog(null,sqlException.getMessage(),
                             "Database Error1", JOptionPane.ERROR_MESSAGE);
                             System.exit(1);
         );//end anonymous inner class
    /* sets up a savings planner to
         calculate various saving senarios
          JComboBox weekMonthYear;
              JLabel amount = new JLabel("Amount         ");
              JLabel time = new JLabel("Time               ");
              JLabel interestRate = new JLabel("Interest Rate");
              JLabel total = new JLabel("Total");
              JButton calc = new JButton("Calculate");
              JPanel top, panAmount, panTime, panTotal, panCalculate;
              JPanel panInterest = new JPanel();
              JPanel container1 = new JPanel();
              String comboNames[] = {"Weekly","Monthly","Yearly"};
              container1.setLayout(new BoxLayout(container1, BoxLayout.PAGE_AXIS));
              weekMonthYear = new JComboBox(comboNames);
              top = new JPanel();
              top.setLayout(new FlowLayout());
              top.add(weekMonthYear);
              panAmount = new JPanel();
              panAmount.setLayout(new FlowLayout());
              panAmount.add(amount);
              txtAmount = new JTextField(7);
              panAmount.add(txtAmount);
              panTime = new JPanel();
              panTime.setLayout(new FlowLayout());
              panTime.add(time);
              txtTime = new JTextField(7);
              panTime.add(txtTime);
              panInterest.setLayout(new FlowLayout());
              panInterest.add(interestRate);
              txtInterest = new JTextField(7);
              panInterest.add(txtInterest);
              panTotal = new JPanel();
              panTotal.setLayout(new FlowLayout());
              panTotal.add(total);
              lblTotal = new JLabel();
              panTotal.add(lblTotal);
              panCalculate = new JPanel();
              panCalculate.setLayout(new FlowLayout());
              panCalculate.add(calc);
              container1.add(top);
              container1.add(panAmount);
              container1.add(panTime);
              container1.add(panInterest);
              container1.add(panTotal);
              container1.add(panCalculate);
              tabbedPane.addTab("Savings Planner",null,container1,"Test Savings Senerios");
              JPanel budgetTop, budgetBottom, budgetMain;
              JList budgetList;
              JButton addBudget;
              JTextField txtAddBudget;
              budgetMain = new JPanel();
              budgetList = new JList();
              budgetList.setVisibleRowCount(10);
              budgetTop = new JPanel();
              budgetTop.setLayout(new FlowLayout());
              budgetTop.add(budgetList);
              addBudget = new JButton("Add Budgeted Item");
              txtAddBudget = new JTextField(20);
              budgetBottom = new JPanel();
              budgetBottom.setLayout(new FlowLayout());
              budgetBottom.add(addBudget);
              budgetBottom.add(txtAddBudget);
              budgetMain.setLayout(new GridLayout(2,1));
              budgetMain.add(budgetTop);
              budgetMain.add(budgetBottom);
              tabbedPane.addTab("Budget",null,budgetMain,"View and Edit your Budget");
          getContentPane().add( tabbedPane );
          setSize( 700, 400 );
          setVisible( true );
       } // end constructor
       public static void main( String args[] )
          DisplayController app = new DisplayController();
          app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    } // end class DisplayController

  • I have internet optic fiber connection and I'm trying to configure it with my Airport Express but doesn't works, appears that I have IP and DNS, as I'm a computers dummy , who could help me to configuration it, please?

    I have internet optic fiber connection and I'm trying to configure it with my Airport Express but doesn't works, appears that I have IP and DNS, as I'm a computers dummy , who could help me to configuration it, please?

    You're welcome.
    Voicemail is left at your carrier's server. That will continue to work unless you report your iPhone as lost or stolen with your carrier.
    You may never find it again and you can't if the iPhone remains offline or out of service which means the iPhone is powered off or doesn't have cellular reception.

  • We use one windows machine and two mbp's (post 2012) at home. We have a modem *** router from a  non apple vendor that airport utility finds and connects with absolute ease. But doesn't stay connected. The signal drops often, what can I do?

    We use one windows machine and two mbp's (post 2012) at home. We have a modem *** router from a  non apple vendor that airport utility finds and connects with absolute ease. But doesn't stay connected. The signal drops often, what can I do?

    No, not all network clients -- only the two mac portables and they run together very rarely. The windows machine is hardwired to the modem router combo, and that's always sailing smooth. The mbp that is most used is perhaps 20 feet max from the router - and in another room. But it also happens when I take in into the same room as the router. On occassion, I have noticed while using network diagnostics, that one digit in the IP number sometimes appears to go awry. I then try to set up manually - and it works for a bit but is hugely erratic.
    I rigged a hand me down airport express and set up a separate network for the two macs and it ran beautifully for some weeks, but that little piece is now dead and none of the retailers in my suburb seem to have one in stock. I don't want to be forced to buy an airport extreme and here in India, there's no trustworthy online ordering option.
    The man from the ISP's been here several times and I don;t think it is a modem/dsl issue because the smartphone connects and the macbook drops when both are the same distance from the router? I am truly foxed and intensely irritated! :-(

  • It compiles but can't run it!

    Hi
    I am really new to java. I got this code from net and tried to compile it. Idoes compile but when i run it , i get the messege,
    "java.lang.NoSuchMethodError: main
    Exception in thread "main" .
    Here is me code.Can someone pleaese tell me y i can't run it and how to fix it. Thanks for your time.
    import java.awt.*;
    import java.awt.event.*;
    public class calculator extends java.applet.Applet implements ActionListener {
         TextField txtTotal = new TextField("");
    Button button[] = new Button[10];
         Button divide = new Button("/");
         Button mult = new Button("*");
         Button plus = new Button ("+");
         Button minus = new Button("-");
         Button isequalto = new Button("=");
         Button clear = new Button("CA");
         double num ,numtemp ;
         int counter;
         String strnum = "",strnumtemp = "" ;
         String op = "";
         public void operation() {
         counter ++;
              if (counter == 1) {
              numtemp = num;      
              strnum = "";
              num = 0;
              }else{
              if (op == "+") numtemp += num;
              else if (op == "-") numtemp -= num;
              else if (op == "*") numtemp = numtemp * num;
              else if (op == "/") numtemp = numtemp / num;
              strnumtemp = Double.toString(numtemp);
              txtTotal.setText(strnumtemp);          
              strnum = "";
              num = 0;     
         public void init() {
         setLayout(null);
         plus.setBackground(Color.blue);
         plus.setForeground(Color.white);
    minus.setBackground(Color.blue);
         minus.setForeground(Color.white);
    divide.setBackground(Color.blue);
         divide.setForeground(Color.white);
         isequalto.setBackground(Color.blue);
         isequalto.setForeground(Color.white);
         mult.setBackground(Color.blue);
         mult.setForeground(Color.white);
         clear.setBackground(Color.blue);
         clear.setForeground(Color.red);
         for(int i = 0;i <= 9; i ++) {
              button[i] = new Button(String.valueOf(i));
              button.setBackground(Color.orange);
              button[i].setForeground(Color.blue);
         button[1].setBounds(0,53,67,53);
         button[2].setBounds(67,53,67,53);
         button[3].setBounds(134,53,67,53);
         button[4].setBounds(0,106,67,53);
         button[5].setBounds(67,106,67,53);
         button[6].setBounds(134,106,67,53);
         button[7].setBounds(0,159,67,53);
         button[8].setBounds(67,159,67,53);
         button[9].setBounds(134,159,67,53);
         for (int i = 1;i <= 9; i ++) {
              add(button[i]);
         txtTotal.setBounds(0,0,200,53);
         add(txtTotal);
         plus.setBounds(0,212,67,53);
         add(plus);
         button[0].setBounds(67,212,67,53);
         add(button[0]);
         minus.setBounds(134,212,67,53);
         add(minus);
         divide.setBounds(134,264,67,53);
         add(divide);
         isequalto.setBounds(67,264,67,53);
         add(isequalto);
         mult.setBounds(0,264,67,53);
         add(mult);
         add(clear);
         public void start() {
         for(int i = 0;i <= 9; i ++) {
              button[i].addActionListener(this);
         plus.addActionListener(this);
         minus.addActionListener(this);
         divide.addActionListener(this);
         mult.addActionListener(this);
         isequalto.addActionListener(this);
         clear.addActionListener(this);
         public void stop() {
         for(int i = 0;i <= 9; i ++) {
              button[i].addActionListener(null);
         plus.addActionListener(null);
         minus.addActionListener(null);
         divide.addActionListener(null);
         mult.addActionListener(null);
         isequalto.addActionListener(null);
         clear.addActionListener(null);
         public void actionPerformed(ActionEvent e) {
              for(int i = 0;i <= 9; i++) {
                   if (e.getSource() == button[i]) {
                   play(getCodeBase(),i + ".au");
                   strnum += Integer.toString(i);
                   txtTotal.setText(strnum);
                   num = Double.valueOf(strnum).doubleValue();
    if (e.getSource() == plus) {
              operation();
              op = "+";
              if (e.getSource() == minus) {
              operation();
              op = "-";
              if (e.getSource() == divide) {
              operation();     
              op = "/";
              if (e.getSource() == mult) {
              operation();     
              op = "*";
              if (e.getSource() == isequalto) {
              if (op == "+") numtemp += num;
              else if (op == "-") numtemp -= num;
              else if (op == "*") numtemp = numtemp * num;
              else if (op == "/") numtemp = numtemp / num;
              strnumtemp = Double.toString(numtemp);
              txtTotal.setText(strnumtemp);
              strnumtemp = "";
              numtemp = 0;
              strnum = "";
              num = 0;
              counter = 0;
              if (e.getSource() == clear) {
              txtTotal.setText("0");
              strnumtemp = "";
              numtemp = 0;
              strnum = "";
              num = 0;
              counter = 0;

    Thanks for your reply.
    Ok i used the link that you sent me and saved the following in the same directory where i have "calcultor.class".
    <HTML>
    <HEAD>
    <TITLE> A Simple Program </TITLE>
    </HEAD>
    <BODY>
    <APPLET CODE="calculator.class" WIDTH=150 HEIGHT=25>
    </APPLET>
    </BODY>
    </HTML>
    I saved it with the name "calculator.html".
    Now when in my browser i type calculator.html, nothing happens.
    I am sure i am missing something but i don't know what.Can someone please help me!
    thanks

  • Program compiles, but does not run

    To: XCode Users <[email protected]>
    From: Brigit Ananya <[email protected]>
    Subject: Program compiles, but does not run
    I am trying to port a Java application from the PC to the Mac. I am using XCode and the program compiles, but it does not run.
    When I try to run the ...app, I get the message that the main class is not specified, etc.
    When I try to run the ...jar, I do not get the message that the main class is not specified, but I do get the message that there is no Manifest section for bouncycastle, etc.
    Here are the detailed messages I get in the Console when I try to run the program:
    When I try to run the ...app, I get the following message:
    1/9/09 7:21:17 AM [0x0-0x8c08c].com.AnanyaSystems.AnanyaCurves[2253] [LaunchRunner Error] No main class specified
    1/9/09 7:21:17 AM [0x0-0x8c08c].com.AnanyaSystems.AnanyaCurves[2253] [JavaAppLauncher Error] CallStaticVoidMethod() threw an exception
    1/9/09 7:21:17 AM [0x0-0x8c08c].com.AnanyaSystems.AnanyaCurves[2253] Exception in thread "main" java.lang.NullPointerException
    1/9/09 7:21:17 AM [0x0-0x8c08c].com.AnanyaSystems.AnanyaCurves[2253] at apple.launcher.LaunchRunner.run(LaunchRunner.java:112)
    1/9/09 7:21:17 AM [0x0-0x8c08c].com.AnanyaSystems.AnanyaCurves[2253] at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50)
    1/9/09 7:21:17 AM [0x0-0x8c08c].com.AnanyaSystems.AnanyaCurves[2253] at apple.launcher.JavaApplicationLauncher.launch(JavaApplicationLauncher.java:52)
    When I try to run the ...jar, I do get the following message:
    1/9/09 7:22:43 AM [0x0-0x8d08d].com.apple.JarLauncher[2262] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] Exception in thread "main"
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] java.lang.SecurityException: no manifiest section for signature file entry org/bouncycastle/asn1/DEREnumerated.class
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:377)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:231)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:176)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.util.jar.JarVerifier.processEntry(JarVerifier.java:233)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.util.jar.JarVerifier.update(JarVerifier.java:188)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.util.jar.JarFile.initializeVerifier(JarFile.java:325)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.util.jar.JarFile.getInputStream(JarFile.java:390)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at sun.misc.URLClassPath$JarLoader$1.getInputStream(URLClassPath.java:620)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at sun.misc.Resource.cachedInputStream(Resource.java:58)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at sun.misc.Resource.getByteBuffer(Resource.java:113)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.net.URLClassLoader.defineClass(URLClassLoader.java:249)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.security.AccessController.doPrivileged(Native Method)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    1/9/09 7:28:45 AM [0x0-0x8f08f].com.apple.JarLauncher[2277] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
    I do specify the main class in both, the Manifest file and the Info.plist file, in the correct way, "package.MainClass". Is there another place where I need to specify it?
    Why do I need org/bouncycastle/asn1/DEREnumerated.class, and how would I have to specify it in Manifest?
    I also posted these questions at Mac Programming at forums.macrumors.com and at Xcode-users Mailing List at lists.apple.com/mailman/listinfo, but I did not get any answer.
    Please help! Thanks!

    There was something wrong with my Info.plist file.
    So, here is my corrected Info.plist file:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
         <key>CFBundleDevelopmentRegion</key>
         <string>English</string>
         <key>CFBundleExecutable</key>
         <string>AnanyaCurves</string>
         <key>CFBundleGetInfoString</key>
         <string></string>
         <key>CFBundleIconFile</key>
         <string>AnanyaCurves.icns</string>
         <key>CFBundleIdentifier</key>
         <string>com.AnanyaSystems.AnanyaCurves</string>
         <key>CFBundleInfoDictionaryVersion</key>
         <string>6.0</string>
         <key>CFBundleName</key>
         <string>AnanyaCurves</string>
         <key>CFBundlePackageType</key>
         <string>APPL</string>
         <key>CFBundleShortVersionString</key>
         <string>0.1</string>
         <key>CFBundleSignature</key>
         <string>ac</string>
         <key>CFBundleVersion</key>
         <string>0.1</string>
         <key>Java</key>
         <dict>
              <key>JMVersion<key>
              <string>1.4+</string>
              <key>MainClass</key>
              <string>AnanyaCurves</string>
              <key>VMOptions</key>
              <string>-Xmx512m</string>
              <key>Properties</key>
              <dict>
                   <key>apple.laf.useScreenMenuBar</key>
                   <string>true</string>
                   <key>apple.awt.showGrowBox</key>
          <string>true</string>
              </dict>
         </dict>
    </dict>
    </plist>Ok, so now I can at least run the AnanyaCurves.jar file by double-clicking on it.
    However, I still cannot run the AnanyaCurves.app file. When I double-click on it, I get the following message in the Console:
    1/11/09 5:12:26 PM [0x0-0x67067].com.apple.JarLauncher[1128]  at ananyacurves.AnanyaCurves.main(AnanyaCurves.java:1961)
    1/11/09 5:13:11 PM [0x0-0x6a06a].com.AnanyaSystems.AnanyaCurves[1137] [JavaAppLauncher Error] CFBundleCopyResourceURL() failed loading MRJApp.properties file
    1/11/09 5:13:11 PM [0x0-0x6a06a].com.AnanyaSystems.AnanyaCurves[1137] [LaunchRunner Error] No main class specified
    1/11/09 5:13:11 PM [0x0-0x6a06a].com.AnanyaSystems.AnanyaCurves[1137] [JavaAppLauncher Error] CallStaticVoidMethod() threw an exception
    1/11/09 5:13:11 PM [0x0-0x6a06a].com.AnanyaSystems.AnanyaCurves[1137] Exception in thread "main" java.lang.NullPointerException
    1/11/09 5:13:11 PM [0x0-0x6a06a].com.AnanyaSystems.AnanyaCurves[1137]  at apple.launcher.LaunchRunner.run(LaunchRunner.java:112)
    1/11/09 5:13:11 PM [0x0-0x6a06a].com.AnanyaSystems.AnanyaCurves[1137]  at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50)
    1/11/09 5:13:11 PM [0x0-0x6a06a].com.AnanyaSystems.AnanyaCurves[1137]  at apple.launcher.JavaApplicationLauncher.main(JavaApplicationLauncher.java:61)Why is it looking for the MRJApp.properties file? Isn't this outdated? Shouldn't it look for the Info.plist file? I do not have a MRJApp.properties file.
    Also, in the Run menu of my XCode project, Go, Run, and Debug are disabled, but perhaps this has to do with not being able to run the AnanyaCurves.app file.
    Thanks for your time! I really appreciate any help you can give me!

  • New to VERIZON but doesn't feel right!

    Hey guys...
    IM A new Guy.
    New to VERIZON but doesn't feel right! Although the 1st Gen Droid is truly awesome, it was the rival of the phone I sported way back when the G1 was the current bad boy on the block the NexusOne. I HAD NO OTHER ANDROID devices in stock! SO I selected the Droid. But I desire a DROID X. YES I AM OBSESSED. ...SEARCHING for one...I guess ill have to wait iltill I'm eligible for upgrade. I was thinking I had 30 days to exchange and as soon as they are in swap...but I can't if I have talked more than 30-50min....so that's out.
    If anyone has any suggestions please let me knew thanks

    g3cortez wrote:
    I was thinking I had 30 days to exchange and as soon as they are in swap...but I can't if I have talked more than 30-50min....so that's out.
    What is this...a new rule?  Where did you get this from?  The only restriction on the 30 days is one exchange, as has been previously stated.  As far as I know there is no restriction on the calling minutes used....is there?

  • Program with generics compiles without -source 1.5 but doesn't run.

    This could probably be considered a bug in J2SE1.5 beta 1.
    A program with generics that is compiled with JDK 1.5 beta1 without the "-source 1.5" option behaves oddly: it compiles but sometimes fails to execute. It shouldn't behave like that. It should fail in the compilation, with a complaint about using the wrong version of the language.
    This odd behaviour doesn't always occur! In the small program below, I get that behaviour when using the EnumSet.range method.
    If I only use the basic EnumSet, it does executes.
    -- Lars
    import java.util.EnumSet;
    import java.util.*;
    public class Example {
         public enum Season { WINTER, SPRING, SUMMER, FALL }
         public static EnumSet<Season> warmSeason = EnumSet.range(Season.SPRING, Season.FALL);
         public static void main(String[] args) {
              System.out.println("Season: ");     
              for (Season s : Season.values()) {
              System.out.println(s);
              System.out.println("Cold Season: ");     
              for (Season s : warmSeason) {
              System.out.println(s);

    Example.java:6: warning: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
        public enum Season { WINTER, SPRING, SUMMER, FALL }
               ^
    Example.java:6: ';' expected
        public enum Season { WINTER, SPRING, SUMMER, FALL }
                           ^
    Example.java:12: ';' expected
            for (Season s : Season.values()) {
                          ^
    Example.java:17: illegal start of expression
            for (Season s : warmSeason) {
            ^
    Example.java:20: ';' expected
        ^
    4 errors
    1 warning

  • Finished writing amazing code that compiles but won't run properly

    I finished writing this code for someone and it compiles but it does not run properly. Anyone see any problems? Any help would be gladly appreciated.
    /* Program is for the Coconut Grove Palace Building. This program keeps track of the building occupants and the maintenance for each tenant using a simple menu system. */
    import java.util.Scanner;
    public class Grove {
    private static Scanner keyboard = new Scanner(System.in);
    /* Declaring values that will not change throughout the program. The plus one is so that people don't get confused */
    private static final int TOTAL_BUILDING_MAX = 16 + 1;
    private static final int TOTAL_FLOOR_MAX = 8 + 1;
    private static final int APARTMENT_MAX = 4 + 1;
    public static void main (String[] args) {
    // Declare main variable
         int cocoPalace[][] = new int[2][3];
         char menuChoice;
         int aptNumber = 0;
         int floorNumber = 0;
         int totalFloor = 0;
         int totalBuilding = 0;
    //Fill up the array with the original amount of 2 people per apartment
         for (int dex = 0; dex <3; dex++)
                   cocoPalace[0][dex] = 2;
                   cocoPalace[1][dex] = 2;     
         System.out.println("Welcome to the coconut grove palace");
    //Main part of the program that is essentially the menu screen.     
         do
              //method that calculates the maintenance that will be used several times
              double buildingMaintenance = calculateMaintenance(cocoPalace);
              //Menu System using a switch command with nested for loops and other code.
                   System.out.println("(A)partment, (B)uilding, (P)eople, E(x)it");
                   menuChoice = keyboard.nextLine().charAt(0);
                        switch (menuChoice)     
    //FIRST CASE 'A' ASK FOR THE FLOOR AND APARTMENT NUMBER AND DISPLAYS THE MAINTENANCE COST FOR IT
                   case 'a':
                   //Idiot proof 1
                   System.out.println("Please enter floor number :");
                   floorNumber = keyboard.nextInt();
                   while (floorNumber > 2)
                   System.out.println("Floor number must be between 1 and 2. Try again:");
                   floorNumber = keyboard.nextInt();
                   //Idiot proof 2               
                   System.out.println("Please enter apartmentNumber :");
                   aptNumber = keyboard.nextInt();
                   while (aptNumber > 3)
                   System.out.println("Apartment number must be between 1 and 3. Try again:");
                   aptNumber = keyboard.nextInt();
                   System.out.println("Floor number" + cocoPalace[floorNumber] + "Apartment number" + cocoPalace[floorNumber][aptNumber] + " : " + buildingMaintenance);
                   break;
    //SECOND CASE 'B' REPORTS THE OCCUPANCY AND MAINTENANCE FOR THE WHOLE BUILDING
                   case 'b':
                   for (int dex2 = 0; dex2 < 3; dex2++)
                   System.out.println("Floor number 1 Apartment number " + cocoPalace[0][dex2] + " : " + buildingMaintenance);                    
                   for (int dex3 = 0; dex3 < 2; dex3++)
                   System.out.println("Floor number 2 Apartment number " + cocoPalace[1][dex3] + " : " + buildingMaintenance);                    
                   break;
    /*THIRD CASE 'P' ALLOWS THE USER TO CHANGE THE AMOUNT OF PEOPLE IN AN APARTMENT AND RECALCULATES THE MAINTENACE. IT IS ALSO "IDIOT PROOFED" SO THAT VALUES DO NOT EXCEED THE REGULATIONS OF THE BUILDING IT SELF */
                   case 'p':
                   //Idiot proof 1
                   System.out.println("Please enter floor number : ");
                   floorNumber = keyboard.nextInt();
                   while (floorNumber > 3)
                   System.out.println("Floor number must be between 1 and 2. Try again: ");
                   floorNumber = keyboard.nextInt();
                   //Idiot proof 2               
                   System.out.println("Please enter apartment number : ");
                   aptNumber = keyboard.nextInt();
                   while (aptNumber > 4)
                   System.out.println("Apartment number must be between 1 and 3. Try again: ");
                   aptNumber = keyboard.nextInt();
                   //Idiot proof 3 with the amount of people being added at the same time.
                   System.out.println("How many people will there be : ");
                   int amountPeople = keyboard.nextInt();
                   cocoPalace[floorNumber][aptNumber] = amountPeople;
                   while (amountPeople > APARTMENT_MAX || totalBuilding > TOTAL_BUILDING_MAX || totalFloor > TOTAL_FLOOR_MAX )
              System.out.print("Too many people in building. Please try again : ");
                   amountPeople = keyboard.nextInt();
                        cocoPalace[floorNumber][aptNumber] = amountPeople;
                   break;
         while (menuChoice != 'x'|| menuChoice != 'a' || menuChoice != 'p' || menuChoice != 'b');
    //Method to calculate maintenance.
    private static double calculateMaintenance(int cocoPalace[][])
         int amountPeople = 0;
         for (int dex4 = 0; dex4 < 2; dex4++)
                   amountPeople += cocoPalace[0][dex4];
                   amountPeople += cocoPalace[1][dex4];
                   cocoPalace[0][dex4] = 2;
                   cocoPalace[1][dex4] = 2;     
              double buildingMaintenance = 5000/(amountPeople);
         return(buildingMaintenance);
    }

    ok the array problem is fixed i was having a simple "one off" mistake when accessing the array.
    As for the error that i keep getting. I honestly can't see where the problem with this is in code.
    The it cant be equalt to nothing because this is written so that it has to equal a letter before the program actually runs through everything. Thanks again for the help
    here is the error that i am getting when the program runs.
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:558)
    at Grove.main(Grove.java:46)
    Here is the code with the new corrections.
    /* Program is for the Coconut Grove Palace Building. This program keeps track of the building occupants and the maintenance for each tenant using a simple menu system. */
    import java.util.Scanner;
    public class Grove {
    private static Scanner keyboard = new Scanner(System.in);
    /* Declaring values that will not change throughout the program. The plus one is so that people don't get confused */
    private static final int TOTAL_BUILDING_MAX = 16 + 1;
    private static final int TOTAL_FLOOR_MAX = 8 + 1;
    private static final int APARTMENT_MAX = 4 + 1;
    public static void main (String[] args) {
    // Declare main variable
         int cocoPalace[][] = new int[2][3];
         char menuChoice;
         int totalFloor = 0;
         int totalBuilding = 0;
    //Fill up the array with the original amount of 2 people per apartment
         for (int dex = 0; dex <3; dex++)
                   cocoPalace[0][dex] = 2;
                   cocoPalace[1][dex] = 2;     
         System.out.println("Welcome to the coconut grove palace");
    //Main part of the program that is essentially the menu screen.     
         do
         //Variables intialized
         int aptNumber = 0;
         int floorNumber = 0;
              //method that calculates the maintenance that will be used several times
              double buildingMaintenance = calculateMaintenance(cocoPalace);
              //Menu System using a switch command with nested for loops and other code.
                   System.out.println("(A)partment, (B)uilding, (P)eople, E(x)it");
                   menuChoice = keyboard.nextLine().charAt(0);
                        switch (menuChoice)     
    //FIRST CASE 'A' ASK FOR THE FLOOR AND APARTMENT NUMBER AND DISPLAYS THE MAINTENANCE COST FOR IT
                   case 'a':
                   //Idiot proof 1
                   System.out.println("Please enter floor number     :");
                   floorNumber = keyboard.nextInt();
                   while (floorNumber > 2)
                   System.out.println("Floor number must be between 1 and 2. Try again:");
                   floorNumber = keyboard.nextInt();
                   //Idiot proof 2               
                   System.out.println("Please enter apartmentNumber  :");
                   aptNumber = keyboard.nextInt();
                   while (aptNumber > 3)
                   System.out.println("Apartment number must be between 1 and 3. Try again:");
                   aptNumber = keyboard.nextInt();
                   System.out.println("Floor number" + cocoPalace[floorNumber] + "Apartment number" + cocoPalace[floorNumber - 1][aptNumber - 1] + "  :  " + buildingMaintenance);
                   break;
    //SECOND CASE 'B' REPORTS THE OCCUPANCY AND MAINTENANCE FOR THE WHOLE BUILDING
                   case 'b':
                   for (int dex2 = 0; dex2 < 3; dex2++)
                   System.out.println("Floor number 1 Apartment number  " + cocoPalace[0][dex2] + "  :  " + buildingMaintenance);                    
                   for (int dex3 = 0; dex3 < 2; dex3++)
                   System.out.println("Floor number 2 Apartment number  " + cocoPalace[1][dex3] + "  :  " + buildingMaintenance);                    
                   break;
    /*THIRD CASE 'P' ALLOWS THE USER TO CHANGE THE AMOUNT OF PEOPLE IN AN APARTMENT AND RECALCULATES THE MAINTENACE. IT IS ALSO "IDIOT PROOFED" SO THAT VALUES DO NOT EXCEED THE REGULATIONS OF THE BUILDING IT SELF */
                   case 'p':
                   //Idiot proof 1
                   System.out.println("Please enter floor number     : ");
                   floorNumber = keyboard.nextInt();
                   while (floorNumber > 2)
                   System.out.println("Floor number must be between 1 and 2. Try again: ");
                   floorNumber = keyboard.nextInt();
                   //Idiot proof 2               
                   System.out.println("Please enter apartment number : ");
                   aptNumber = keyboard.nextInt();
                   while (aptNumber > 3)
                   System.out.println("Apartment number must be between 1 and 3. Try again: ");
                   aptNumber = keyboard.nextInt();
                   //Idiot proof 3 with the amount of people being added at the same time.
                   System.out.println("How many people will there be : ");
                   int amountPeople = keyboard.nextInt();
                   cocoPalace[floorNumber - 1][aptNumber - 1] = amountPeople;
                   while (amountPeople > APARTMENT_MAX || totalBuilding > TOTAL_BUILDING_MAX || totalFloor > TOTAL_FLOOR_MAX  )
                          System.out.print("Too many people in building. Please try again : ");
                               amountPeople = keyboard.nextInt();
                        cocoPalace[floorNumber - 1][aptNumber - 1] = amountPeople;
                   break;
         while (menuChoice != 'x'|| menuChoice != 'a' || menuChoice != 'p' || menuChoice != 'b');
    //Method to calculate maintenance.
    private static double calculateMaintenance(int cocoPalace[][])
         int amountPeople = 0;
         for (int dex4 = 0; dex4 < 2; dex4++)
                   amountPeople += cocoPalace[0][dex4];
                   amountPeople += cocoPalace[1][dex4];
                   cocoPalace[0][dex4] = 2;
                   cocoPalace[1][dex4] = 2;     
              double buildingMaintenance = 5000/(amountPeople);
         return(buildingMaintenance);
    }

  • Program compiles but doesn't work

    The folowing program compiles, but it doesn't work, when I type GuessingGame.play(5); into the interactions pane, I get the message
    No 'play' method in 'GuessingGame'. All my brackets line up and I can't see where the problem is. I would definitely apreciate it if you could help!
    /** Allows a user to play a number-guessing game.
    The constructor takes the integer to be guessed. */
    public class GuessingGame {
    int theNumber; //The number to be guessed by the user.
    int guessNumber; //The users guess.
    public void play(int g){
    theNumber=g;
    guessNumber = Integer.parseInt(JOptionPane.showInputDialog("Guess an integer."));
    while(guessNumber!=theNumber){
    if(guessNumber > theNumber){
    JOptionPane.showMessageDialog(null, "Your guess was too high. Guess again.");
    else if(guessNumber < theNumber){
    JOptionPane.showMessageDialog(null, "Your guess was too low. Guess again.");
    JOptionPane.showMessageDialog(null, "You're right!");

    Sorry, it's just that no-one was answering, it took over 2 hours to get a response. I finally got some help now(with the topic as 'Fun to be had by all!'), so you can now just ignore all of them.

Maybe you are looking for