Re: Possible Array problem. Applet Compiles but does not run!

From: Andrew Thompson (SeeMySites_at_www.invalid)
Date: 12/16/04


Date: Thu, 16 Dec 2004 14:19:15 GMT

On Thu, 16 Dec 2004 08:42:59 -0500, BladeZ wrote:

> I have this script (sorry its long but its neccessary for me to post it
> all);

SSCCE's[1] are quite welcome here, and an entire post of 126
lines is not unreasonable.
[1] <http://www.physci.org/codes/sscce.jsp>

(snip main code)
> This compiles, however it does not initialise. I Don't really understand
> what the Dos window tells me but I think the problem is in line 29;

Yes, but your line numbers do not correspond with mine.

In any case, the problem is pretty clear.. see this altered fragment

<snippet>
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class MobileShop extends Applet implements ActionListener{
        private Mobile phone[];
     private Button priceListbutton;
           private Button button[];
           public int Decision = 0;
           private int modelNumber = 5;

    public void init() {

       // this only needs to be done once, and 'init'ially.
      phone = new Mobile[modelNumber];
        phone[0] = new Mobile("R2D2", 3, 5, 102,false, 79.95f);
       phone[1] = new Mobile("C3PO", 4, 6, 85, false, 99.95f);
       phone[2] = new Mobile("UB40", 5, 12, 89, false, 129.95f);
       phone[3] = new Mobile("WD40", 10, 10, 91, true, 189.95f);
       phone[4] = new Mobile("RU18", 12,18, 77, true, 219.95f);

       // further, it needs to have created the phones array
       // *before* it gets to here!
       button = new Button[modelNumber];
        for(int i = 0; i < modelNumber; i++)
        {
            button[i] = new Button(phone[i].getmodel());
            add(button[i]);
            button[i].addActionListener(this);
        }
    } // end init

    public void paint(Graphics g) {
       if (Decision == 0){
                    for (int a = 0; a < modelNumber; a ++){
          g.drawString("Name: " + phone[a].getmodel(), 90,70 + 15 * a);
   }
...
</snippet>

HTH

-- 
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane


Relevant Pages

  • Re: reading more data than the record size (RECL)
    ... end snip ... My old compiles also write and read correctly with the subroutine I ... This overhead is there to allow Fortran ...
    (comp.lang.fortran)
  • Re: case labels
    ... snip ... ... The code below is virtually identical to my fragment above and ... compiles and runs with gcc. ...
    (comp.lang.c)
  • Re: CW10 assignment, void*, func ptr warnings...
    ... > know why you're getting a warning. ... >> 3) errors about func signatures; ... The following compiles just fine for me: ...
    (comp.sys.mac.programmer.codewarrior)
  • JDialog not appearing for JWindow under Java 1.5
    ... One of the menu selections is supposed to show a JDialog ... If the program compiles and ... public class DialogTest extends JWindow // works only under 1.4.2 ... help.addActionListener(new ActionListener() { ...
    (comp.lang.java.gui)
  • Re: Need some help with I/O
    ... > My textboox has less than a paragraph on the fgetsfunction ... > compiles and runs ok, it even builds a text file, but when I enter data ...
    (alt.comp.lang.learn.c-cpp)