Classnotfound Exception when Embedding jar with HTML

user4464506

I have created a simple Minesweeper game using Java in Eclipse. I have used a normal jar (not a runnable jar) to create the jar file.

I did not use init() or any such functions.

Here is the entire code:

import java.applet.Applet; 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class Minesweeperapplet extends Applet implements ActionListener {

/**
 * 
 */
private static final long serialVersionUID = 1L;

JFrame frame= new JFrame("Minesweeper von Junaid Aslam");

JButton reset = new JButton("Reset");   //declaring reset button - deklaration des 'reset' button

JButton [][]buttons= new JButton[20][20]; //declaring jbuttons for the game - declaring echt buttons fur das spiel

Container grid= new Container(); //container for the grid - Container fur das grid

boolean [][] zero= new boolean[20][20]; //to keep track of all uncovered zeros - um darauf die aufgedeckten zeros zu markieren

int[][] counts = new int[20][20]; //holds the integer count of all neighbouring mines - das Feld beeinhaltet die Informationen uber die Nummer der angrenzenden Minen

final int mine=10; //Final value set for a mine - diese 'final' Variable representiert eine Mine  

int minesSetForGame = 35;//Number of mines in the game - Bestimmung uber die Anzahl der Minen

public Minesweeperapplet(){


    frame.setSize(1000,700);
    frame.setLayout(new BorderLayout());
    frame.add(reset, BorderLayout.NORTH); //inserting reset button in the borderLayout - Hinzufugen des reset buttons zum borderlayout


    reset.addActionListener(this);


    //setting up grid - stellen die Grid ein
    grid.setLayout(new GridLayout(20,20));

    //initialize button grid - initialisierung des button grid
    for(int a=0;a<buttons.length;a++)
    {
        for(int b=0; b<buttons[0].length;b++)
        {
            buttons[a][b]= new JButton();
            buttons[a][b].addActionListener(this);    //listener for left click - Zuhoren auf 'Left Click'
            buttons[a][b].addMouseListener(new Mouse());//listener for right click - Zuhoren auf 'Right Click'
            grid.add(buttons[a][b]);   //adding buttons to the grid - Hinzufugen der buttons zum grid

        }

    }

    frame.add(grid, BorderLayout.CENTER);  //adding the grid to layout -  etablieren des grids in der Mitte
    creatRandomMines(); //creating random mines - Erstellen zufalliger Minen
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}



public void creatRandomMines(){  //Creating random mines - Erstellen zufalliger Minen

    ArrayList<Integer> list= new ArrayList<Integer>();

    //initialize list of random pairs
    for(int x=0; x < counts.length; x++)
    {
        for(int y=0; y < counts[0].length; y++)
        {
            list.add(x*100+y);

        }
    }

    //reset count and pick 30 mines
    counts= new int[20][20];//for reset

    for(int a=0; a<minesSetForGame; a++){

        int choice= (int)(Math.random()*list.size());//Math.random()*list.size() picks out number from 0 to 399(400=list.size())
        counts[list.get(choice)/100][list.get(choice)%100]= mine;
        list.remove(choice);//removing the choice we have made for the mine
    }

    //initializing count for counting neighbouring mines- Initialliesieren der Berechnung von den Minen in den Nachbarfeldern
    for(int x=0;x<counts.length;x++)
    {
        for(int y=0; y<counts.length; y++)
        {
            if(counts[x][y]!=mine)
            {
            int neighborcount=0;
            if(x>0 && y>0 && counts[x-1][y-1]==mine)//Oben links button
            {
                neighborcount++;
            }
            if(y>0 && counts[x][y-1]==mine)//Links button
            {
                neighborcount++;
            }
            if( y<(counts[0].length-1) && counts[x][y+1]==mine) //rechts button
            {
                neighborcount++;
            }
            if( x>0 && y<(counts[0].length-1) && counts[x-1][y+1]==mine)//Oben rechts
            {
                neighborcount++;
            }
            if(x>0 && counts[x-1][y]==mine)//Oben
            {
                neighborcount++;
            }
            if(x<(counts.length-1) && y<(counts[0].length-1) && counts[x+1][y+1]==mine)//unten rechts
            {
                neighborcount++;
            }
            if(x<(counts.length-1)&& y>0 && counts[x+1][y-1]==mine)//unten links
            {
                neighborcount++;
            }
            if(x<(counts.length-1) && counts[x+1][y]==mine)//unten
            {
                neighborcount++;
            }

            counts[x][y]=neighborcount;
            }
        }
    }

}

public void lost(){//in case we lose the game - Wenn das Spiel verloren ist, zeige alle Buttons

    for(int x=0;x<buttons.length;x++)
    {
        for(int y=0;y<buttons[0].length;y++)
        {
            if(counts[x][y]!=mine)
            {
            buttons[x][y].setText(counts[x][y]+"");
            buttons[x][y].setEnabled(false); //Machen setEnabled=false fur alle nicht Minen buttons
            }
            else{
                buttons[x][y].setBackground(Color.ORANGE);//Markiere alle immer noch zugedeckten Minen orange
                buttons[x][y].setText("X");//Markiere alle immer noch zugedeckten Minen mit "X" String


            }
        }
    }
}

public void zero(int x, int y){ //decke alle angrenzenden zeros auf


     if(zero[x][y]==false)
     {
            buttons[x][y].setEnabled(false);
            buttons[x][y].setText(counts[x][y]+"");
            zero[x][y]=true;   //alle aufgedeckten zeros werden 'true' gemacht

            //aufdecken der felder bis zum 'non-zero'(zahlen) button

            if(x<(counts.length-1)){
            buttons[x+1][y].setText(counts[x+1][y]+""); //fur unten buttons so that they keep opening until the number is not 0
            buttons[x+1][y].setEnabled(false);}

            if(x>0)
            {buttons[x-1][y].setText(counts[x-1][y]+"");//oben
            buttons[x-1][y].setEnabled(false);}

            if(y>0){
            buttons[x][y-1].setText(counts[x][y-1]+"");//links
            buttons[x][y-1].setEnabled(false);}

            if(y>0 && x>0){
            buttons[x-1][y-1].setText(counts[x-1][y-1]+"");//links oben
            buttons[x-1][y-1].setEnabled(false);}

            if( x>0 && y<(counts[0].length-1)){
            buttons[x-1][y+1].setText(counts[x-1][y+1]+"");//rechts oben
            buttons[x-1][y+1].setEnabled(false);}

            if(y<(counts[0].length-1)){
            buttons[x][y+1].setText(counts[x][y+1]+"");//rechts button
            buttons[x][y+1].setEnabled(false);}

            if(x<(counts.length-1) && y>0){
            buttons[x+1][y-1].setText(counts[x+1][y-1]+"");//links unten
            buttons[x+1][y-1].setEnabled(false);}

            if(x<counts.length-1 && y<counts[0].length-1){
            buttons[x+1][y+1].setText(counts[x+1][y+1]+"");//rechts unten
            buttons[x+1][y+1].setEnabled(false);}

            //to clear out all zeros adjacent to zeros already cleared out
            //um alle zeros aufzudecken, die an bereits auf gedeckte zeros angrenzen

            if(x>0 && counts[x-1][y]==0)//oben - Upper button
            {
                zero(x-1,y);
            }
            if(x<(counts.length-1) && counts[x+1][y]==0)//unten - Lower button
            {
                zero(x+1,y);
            }
            if(y>0 && counts[x][y-1]==0)//links - Left button
            {
                zero(x,y-1);
            }
            if(y>0 && x>0 && counts[x-1][y-1]==0)//links oben - upper left button
            {
                zero(x-1,y-1);
            }
            if( x>0 && y<(counts[0].length-1) && counts[x-1][y+1]==0)//rechts oben - right button
            {
                zero(x-1,y+1);
            }
            if(y<(counts[0].length-1) && counts[x][y+1]==0)//rechts - right button
            {
                zero(x,y+1);
            }
            if(x<(counts.length-1) && y>0 && counts[x+1][y-1]==0 )//links unten - lower left
            {
                zero(x+1,y-1);
            }
            if(x<counts.length-1 && y<counts[0].length-1 && counts[x+1][y+1]==0)//rechts unten - lower right
            {
                zero(x+1,y+1);
            }
     }
}


     public void checkforwin() //um zu Kontrollieren ob spieler gewonnen hast
                               //to check if player has won
      {
         int minecounter=0,nonminecounter=0;

         for(int x=0;x<buttons.length;x++) 
            {
                for(int y=0;y<buttons[0].length;y++)
                {

                    if(counts[x][y]==mine)
                    {

                    if(buttons[x][y].isEnabled())
                    {
                        minecounter++; //Wird alle Minen zahlen, die noch nicht angeklickt wurden
                    }                   //will count all mines which have not been clicked on
                    }
                    else if(counts[x][y]!=mine)
                    {
                        if(!buttons[x][y].isEnabled())

                            nonminecounter++; // will count all buttons other than mines which have been shown to the player or clicked on
                                              //Wird alle buttons zahlen, die aufgedeckt sind und keine minen sind 
                    }
                }

                if(minecounter==minesSetForGame && nonminecounter==((counts.length*counts[0].length)-minecounter))
                {//checks if all mines are isEnabled(not clicked on) and all other buttons are !isEnabled()(they are disabled)
                    JOptionPane.showMessageDialog(new JFrame(), "Sie haben Gewonnen.");
                }

     }

}

@Override
public void actionPerformed(ActionEvent event) {

    if(event.getSource().equals(reset)){


        for(int x=0;x<buttons.length;x++) //resets all buttons[x][y]
        {                                   
            for(int y=0;y<buttons[0].length;y++)
            {
                buttons[x][y].setEnabled(true);
                buttons[x][y].setBackground(null);//sets all button background color to default
                buttons[x][y].setForeground(null);
                buttons[x][y].setText("");
            }
    }
        creatRandomMines();//creates mines for restart - erstellt Minen fur den Neustart
        zero=new boolean[20][20]; //machen alle zero zu false noch mal

    }else{

        for(int x=0; x<buttons.length; x++)//ob der Spieler druckt ein andere button
        {
            for(int y=0; y<buttons[0].length; y++)
            {
                if(event.getSource().equals(buttons[x][y]))
                {
                    if(buttons[x][y].getBackground().equals(Color.red) || buttons[x][y].getBackground().equals(Color.ORANGE))
                    {
                        //if the button is flagged or has orange background (after losing) do nothing
                        //Wenn der button 'flagged' ist, konnen wir nichts machen
                    }
                    else if(counts[x][y]==mine)      // if the button is a mine - wenn der angeklickte Button eine Mine ist
                    {
                        lost();//calling lost method because game is lost - das spiel ist verloren
                        buttons[x][y].setForeground(Color.red);
                        buttons[x][y].setText("X");



                    }else if(counts[x][y]==0)// if the clicked button is zero
                    {                       //wenn der angeklickte button zero ist
                        int i=x,j=y;
                        zero(i,j);  //calling zero method
                    }               //rufen zero method


                    else{
                    buttons[x][y].setText(counts[x][y]+"");//sets the clicked button to count[x][y]- einsetzen der nummer bei einem eingeklickten button zu count[x][y]
                    buttons[x][y].setEnabled(false); //disables the button after the click - 'disable' button nach dem Klick
                    checkforwin();//checking for winner after a non-mine button is clicked - prufen der gewinner

                    }
                }
            }
        }
    }

}

public class Mouse extends MouseAdapter { //for right click functionality
                                            // fur rechten Klick Funktionalitat

    @Override
    public void mousePressed(MouseEvent event){
        if(event.isMetaDown())
        {
            for(int x=0;x<buttons.length;x++) 
            {
                for(int y=0;y<buttons[0].length;y++)
                {
                    if(event.getSource().equals(buttons[x][y]))
                    {
                        if(!buttons[x][y].getBackground().equals(Color.red))// if the button is not yet flagged - wenn die button noch nicht 'flagged' ist
                        {
                            if(buttons[x][y].isEnabled()) //to make sure the button is still enabled - um zu prufen dass der button isEnabled() ist
                            {
                                buttons[x][y].setBackground(Color.red);//set color to red if clicked once - stelle die Background farbe Rot ein bei einem Klick

                            }

                        }
                        else{
                            buttons[x][y].setBackground(null);//set color to default if clicked again - stelle die farbe zu Default bei noch einem klick
                            }

                    }
                }
        }


        }
    }


}

}

Here is my complete HTML code:

  <!DOCTYPE html>
  <html>
  <head>
 <title>Minesweeper100</title>


 </head>

 <body>


    <applet code = "Minesweeperapplet.class" archive="Minesweeperapplet.jar"    width=1000 height=700></applet>

 </body>

</html>

Now I am using Filezilla server to upload and run it on Firefox. It says "ClassNotFoundException Minesweeperapplet.class"... everytime I run it.

The .jar:

I have been stuck on it for 2 days. I have read all such questions here but my problem does not seem to go away. The HTML and jar are in the same folder; all file names have been checked and re-checked zillion times. I even had a dream about this error.

PLEASE HELP!!!!!

nitind

Use the classname not the name of the class' file for the code value: Minesweeperapplet

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

ClassNotFound Exception when running java from CentOS 7 terminal

분류에서Dev

PHP function giving me exception when trying to display on HTML

분류에서Dev

Android ClassNotFound

분류에서Dev

Android ClassNotFound

분류에서Dev

명령 줄을 통해 jar 실행 : 하나의 데스크톱에서 classnotfound 예외

분류에서Dev

Compiler error when throwing exception

분류에서Dev

unreported exception when using Unsafe

분류에서Dev

Mapping Exception when indexing in Elasticsearch

분류에서Dev

Exception thrown when calling getFriends

분류에서Dev

Exception errors when using strcpy

분류에서Dev

Nullpointer Exception when using RecyclerView

분류에서Dev

issue when embedding the both Youtube video url and Vimeo video url from json response in angular js

분류에서Dev

When embedding cover art as a tag to audio files, is the same image copied to each file?

분류에서Dev

aws AmazonDynamoDBSessionManagerForTomcat ClassNotFound 문제

분류에서Dev

Android의 ClassNotFound 예외

분류에서Dev

Android에서 LibGDX ClassNotFound

분류에서Dev

How to I make exception in exception when catching errors in python?

분류에서Dev

HTML5 NAV Hover Exception

분류에서Dev

Throwing exception when inserting data in C#

분류에서Dev

Encountered a runtime exception when running code

분류에서Dev

Unhandled Exception when converting const char to char

분류에서Dev

Exception when make object from Skype in .NET?

분류에서Dev

Exception when running simple code on iOS

분류에서Dev

Exception when trying to refresh Clojure code in cider

분류에서Dev

Required attribute triggers exception when attribute nullable

분류에서Dev

Null Pointer Exception when using LayoutInflator()?

분류에서Dev

Exception when removing items from an ArrayList

분류에서Dev

When does an istreambuf_iterator throw an exception?

분류에서Dev

Javax validation exception when migrating to Wildfly 8.1

Related 관련 기사

  1. 1

    ClassNotFound Exception when running java from CentOS 7 terminal

  2. 2

    PHP function giving me exception when trying to display on HTML

  3. 3

    Android ClassNotFound

  4. 4

    Android ClassNotFound

  5. 5

    명령 줄을 통해 jar 실행 : 하나의 데스크톱에서 classnotfound 예외

  6. 6

    Compiler error when throwing exception

  7. 7

    unreported exception when using Unsafe

  8. 8

    Mapping Exception when indexing in Elasticsearch

  9. 9

    Exception thrown when calling getFriends

  10. 10

    Exception errors when using strcpy

  11. 11

    Nullpointer Exception when using RecyclerView

  12. 12

    issue when embedding the both Youtube video url and Vimeo video url from json response in angular js

  13. 13

    When embedding cover art as a tag to audio files, is the same image copied to each file?

  14. 14

    aws AmazonDynamoDBSessionManagerForTomcat ClassNotFound 문제

  15. 15

    Android의 ClassNotFound 예외

  16. 16

    Android에서 LibGDX ClassNotFound

  17. 17

    How to I make exception in exception when catching errors in python?

  18. 18

    HTML5 NAV Hover Exception

  19. 19

    Throwing exception when inserting data in C#

  20. 20

    Encountered a runtime exception when running code

  21. 21

    Unhandled Exception when converting const char to char

  22. 22

    Exception when make object from Skype in .NET?

  23. 23

    Exception when running simple code on iOS

  24. 24

    Exception when trying to refresh Clojure code in cider

  25. 25

    Required attribute triggers exception when attribute nullable

  26. 26

    Null Pointer Exception when using LayoutInflator()?

  27. 27

    Exception when removing items from an ArrayList

  28. 28

    When does an istreambuf_iterator throw an exception?

  29. 29

    Javax validation exception when migrating to Wildfly 8.1

뜨겁다태그

보관