Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9098403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:21:06+00:00 2026-06-17T00:21:06+00:00

This is probably an elementary question. However, I have completed reading the 12th Chapter

  • 0

This is probably an elementary question. However, I have completed reading the 12th Chapter of Java Programming for the Absolute Beginner and have approached some sample code. I get a compiler error when I try to compile this sample code program. I have all the related programs located within the same package, so this is not the problem.

The error occurs at this line:

minefield.addMineFieldListener(this); 

It states:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code 
- Erroneous sym type: MineField.addMineFieldListener at MinePatrol.<init>
(MinePatrol.java:21)

My main question is: Why is this occuring?

Thank you very much for your time and cooperation reagrding this matter.

HERE IS THE CODE FOR MinePatrol.java:

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.net.URL;
import java.net.MalformedURLException;

public class MinePatrol extends GUIFrame
                    implements MineFieldListener, ActionListener {
protected MineField minefield;
protected Button resetButton;
protected Label flagCountLabel;

public MinePatrol() {
super("MinePatrol");
minefield = new MineField(10, 10, 10);
minefield.addMineFieldListener(this);
add(minefield, BorderLayout.CENTER);
MediaTracker mt = new MediaTracker(this);
Image[] imgs = {
  Toolkit.getDefaultToolkit().getImage("flag.gif"),
  Toolkit.getDefaultToolkit().getImage("mine.gif"),
  Toolkit.getDefaultToolkit().getImage("explode.gif") };

for (int i=0; i < imgs.length; i++) {
  mt.addImage(imgs[i], i);
}
try {
  mt.waitForAll();
} catch (InterruptedException e) {}
minefield.setImages(imgs[0], imgs[1], imgs[2]);
try {
  minefield.setAudioClips(
    Applet.newAudioClip(new URL("file:reveal.wav")),
    Applet.newAudioClip(new URL("file:flag.wav")),
    Applet.newAudioClip(new URL("file:unflag.wav")),
    Applet.newAudioClip(new URL("file:explode.wav")));
} catch (MalformedURLException e) {}

flagCountLabel = new Label("Flags: 10", Label.CENTER);
add(flagCountLabel, BorderLayout.NORTH);
resetButton = new Button("Reset");
resetButton.addActionListener(this);
add(resetButton, BorderLayout.SOUTH);
pack();
setVisible(true);
  }

public static void main(String args[]) {
new MinePatrol();
}

public void mineFieldSolved(MineFieldEvent e) {
flagCountLabel.setText("You Win!");
}

 public void mineFieldRandomized(MineFieldEvent e) {
 flagCountLabel.setText("Flags: " + minefield.getMineCount());
}

 public void mineFieldDetonated(MineFieldEvent e) {
 flagCountLabel.setText("You exploded into tiny bits... RIP");
}

 public void mineFieldFlagCountChanged(MineFieldEvent e) {
 flagCountLabel.setText("Flags: "
  + (minefield.getMineCount() - minefield.getFlagCount()));
 }

 public void actionPerformed(ActionEvent e) {
  minefield.randomize();
  }

 }

Here is the code for MineField.java

import java.awt.*;
import java.util.*;
import java.applet.AudioClip;

public class MineField extends Panel 
                    implements MineCellListener {
protected int rows, cols, mines, flagged, revealed;
protected AudioClip  revealClip, flagClip, unflagClip, explodeClip;
protected MineCell[][] cells;
//keeps track of MineCell indices
protected Hashtable pointIndex;
protected Vector listeners;

   public MineField(int nRows, int nCols, int nMines) {
   rows = nRows > 0 ? nRows : 1;
   cols = nCols > 0 ? nCols : 1;
   cells = new MineCell[rows][cols];
   mines = nMines >= 0 && nMines < rows * cols ? nMines : 1;
   pointIndex = new Hashtable(rows * cols);
   setLayout(new GridLayout(rows, cols));
   for (int r=0; r < cells.length; r++) {
       for (int c=0; c < cells[r].length; c++) {
           cells[r][c] = new MineCell();
           cells[r][c].addMineCellListener(this);
           //Points use (x, y) coordinates to x=c and y=r
           pointIndex.put(cells[r][c], new Point(c, r));
           cells[r][c].setSize(25, 25);
           add(cells[r][c]); 
       }
       }
   listeners = new Vector();
   randomizeField(false);
   }

   protected void randomizeField(boolean fireEvent) {
       Random rand = new Random();
       int index;
   //initialize empty
   for (int r=0; r < cells.length; r++) {
       for (int c=0; c < cells[r].length; c++) {
           cells[r][c].resetContents(MineCell.EMPTY);
       }
   }
   //randomly place all mines
   for (int m=0; m < mines; m++) {
      do {
          index = rand.nextInt(rows * cols);
      }
      while (cells[index / cols][index % cols].getContents() != MineCell.EMPTY);
      cells[index / cols][index % cols].resetContents(MineCell.MINE);
   }
   setNumberClues();
   flagged = revealed = 0;
   //does not fire flagCountChanged, only mineFieldRandomized
   if (fireEvent) (new EventThread(new MineFieldEvent(this,
                                MineFieldEvent.RANDOMIZED))).start();
   }

    public void randomize() {
     randomField(true);
    }

    public int getFlagCount() {
    return flagged;
    }

   public int getMineCount() {
       return mines;
   }

  //counts and sets the number of mines surrounding each cell
   protected void setNumberClues() {
   int nMines;
   for (int r=0; r < cells.length; r++) {
       for (int c=0; c < cells[r].length; c++) {
           if (cells[r][c].getContents() != MineCell.MINE) {
               nMines = 0;
               //count the number of mines surrounding this cell
               for (int dr = r - 1; dr <= r + 1; dr++) {
                   //prevent ArrayIndexOutOfBoundsException
                   //continue puts control back to the beginning of the loop
                   if (dr < 0 || dr >= cells.length) continue;
                   for (int dc = c -1; dc <= c + 1; dc++) {
                       if (dc < 0 || dc >= cells[dr].length) continue;
                       if (cells[dr][dc].getContents() == MineCell.MINE) nMines++;
                   }
               }
               cells[r][c].resetContents(nMines);
               }
           }
       }
   }

     public class MineFieldEvent extends java.util.EventObject {
protected int eventID;
//event id constants
public final static int SOLVED = 0,
                            RANDOMIZED = 1,
                            DETONATED = 2,
                            FLAG_COUNT_CHANGED = 3;

    public MineFieldEvent(Object source, int id) {
    super(source);
    eventID = id;
    }

    public int getID() {
        return eventID;
        }
    }
   protected class EventThread extends Thread {
   MineFieldEvent e;
   EventThread(MineFieldEvent mfe) {
       e = mfe;
   }
      public void addMineFieldListener(MineFieldListener mfl) {
   listeners.addElement(mfl);
   }

   public void removeMineFieldListener(MineFieldListener mfl) {
       listeners.removeElement(mfl);
   }

   public void run() {
    switch(e.getID()) {
case MineFieldEvent.SOLVED:
for (int i=0; i < listeners.size(); i++) {
((MineFieldListener)listeners.elementAt(i)).mineFieldSolved(e);
}
break;
case MineFieldEvent.RANDOMIZED:
for (int i=0; i < listeners.size(); i++) {
((MineFieldListener)listeners.elementAt(i)).mineFieldRandomized(e);
}
break;
case MineFieldEvent.DETONATED:
for (int i=0; i < listeners.size(); i++) {
((MineFieldListener)listeners.elementAt(i)).mineFieldDetonated(e);
}
break;
case MineFieldEvent.FLAG_COUNT_CHANGED:
for (int i=0; i < listeners.size(); i++) {
((MineFieldListener)listeners.elementAt(i)).mineFieldFlagCountChanged(e);
}
break;
}
}
}

   public void setImages(Image f, Image m, Image e) {
   MineCell.setImages(f, m, e);
   }

   public void setAudioClips(AudioClip r, AudioClip f, AudioClip u,
                            AudioClip e) {
   revealClip = r; flagClip = f; unflagClip = u; explodeClip = e;
   }

   /* Reveals areas mine-free minecells */
    protected void showSafeArea(MineCell start) {
   //get the point index for the starting cell
   Point p = (Point)pointIndex.get(start);
   for (int r = p.y - 1; r <= p.y + 1; r++) {
       if (r < 0 || r >= cells.length) continue;
       for (int c = p.x - 1; c <= p.x + 1; c++) {
           if (c < 0 || c >= cells[r].length || !cells[r][c].isHidden())
               continue;
           if (cells[r][c].isFlagged()) {
               flagged--;

              (new EventThread(new MineFieldEvent(this, 
                                    MineFieldEvent.FLAG_COUNT_CHANGED))).start();
           }
           cells[r][c].setHidden(false);
           revealed++;
           if(cells[r][c].getContents() == MineCell.EMPTY)
               showSafeArea(cells[r][c]);
            }
       }
   }

   protected void checkIfSolved() {
       if (flagged + revealed == rows * cols) {
       //solved if we get here.
       revealAll();
       (new EventThread(new MineFieldEvent(this,
                                MineFieldEvent.SOLVED))).start();
       }
    }

   public void revealAll() {
       for (int r=0; r < cells.length; r++) {
           for (int c =0; c < cells.length; c++) {
           cells[r][c].setHidden(false);
           }
       }
   }

    public void mineCellRevealed(MineCellEvent e) {
        if (revealClip != null) revealClip.play();
       revealed++;
       if ((MineCell)e.getSource()).getContents() == MineCell.EMPTY)
        showSafeArea((MineCell)e.getSource());
        checkIfSolved();
   }

    public void mineCellDetonated(MineCellEvent e) {
   //game over show all
   if (explodeClip != null) explodeClip.play();
   revealAll();
   (new EventThread(new MineFieldEvent(this, 
                           MineFieldEvent.DETONATED))).start();
    }

    public void mineCellFlagged(MineCellEvent e) {
         if (flagged >= mines) {
          ((MineCell)e.getSource()).getHidden(true);
          return;
   }
   if (flagClip != null) flagClip.play();
   flagged++;
   (new EventThread(new MineFieldEvent(this,
                            MineFieldEvent.FLAG_COUNT_CHANGED))).start();
   checkIfSolved();
   }

   public void mineCellUnflagged(MineCellEvent e) {
   if (unflagClip != null) unflagClip.play();
   flagged--;
   (new EventThread(new MineFieldEvent(this, 
                             MineFieldEvent.FLAG_COUNT_CHANGED))).start();
   }




                   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:21:08+00:00Added an answer on June 17, 2026 at 12:21 am

    This may be the NetBeans bug 199293. It is fixed now but not yet old. If you use NetBeans, check maybe you need to update. The error message Uncompilable source code – Erroneous sym
    type matches
    and I do not see anything in your code to result an error message so wise. Try to build with Eclipse or Ant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably an elementary question. However, I have completed reading the 9th Chapter
This is probably an elementary question. However, I have completed reading the 9th Chapter
This is probably an elementary question. However, I have completed reading the 5th Chapter
I'm fairly new to OO programming specifically with Java. I have a question pertaining
This probably is a dummy question but I cannot find a clear indication. I
Im sorry for this probably dumm question, but I want to simply open modals
This probably sounds like a really dumb question, but here goes....Web Services, what the
This probably is a very very basic question but i can't seem to find
I know this probably is a fairly complicated question but... heres my case: I
I know this is probably elementary to unix people, but I haven't found a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.