Home Answers Viewqa Applet Help please, some strange errors

 
 


YasheshRathod
Help please, some strange errors
0 Answer(s)      2 months and 3 days ago
Posted in : Applet

Sorry about this messy formatting. As a beginner in java i got no idea which part of the code is creating this errors so i have posted the whole program here. Here i tried to make the monopoly game of two players with some basic things like moving the player on the game board according to the dice rolled. it even runs and works accurate but after some play the error hits on to the console view. Can someone tell me what in the code is causing that run-time errors? Any kind of help will be helpful to me. and let me know if you want to know more about this because i've not posted the other classes here like Property,Player, main class etc.. I hope i will get some solution here..

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.Timer;


public class Board extends JPanel implements ActionListener 
{
    //timer object would call the method actionPerfored at every 25 mili-seconds
    private Timer timer;
    //Create spaces on the game board  
    Property prop[] = new Property[40];
    //Create Players
    Player p[] = new Player[2];
    //some local helpful variables
    int et,  dice1, dice2, pflag;
    static int k;


    Board ()
    {
        //Initialization of all Spaces on the Game Board
        prop[0] = new Property(632, 637, 0, 0, "Go", 1);
        prop[1] = new Property(557, 580, "Mediterranean Avenue", 60, 2);
        prop[2] = new Property(506, 580, 0, 0, "Community Chest", 1);
        prop[3] = new Property(449, 580, "Baltic Avenue", 60, 4);
        prop[4] = new Property(392, 580, 0, 0, "Income Tax", 1);
        prop[5] = new Property(337, 580, "Reading Railroad", 300, 25);
        prop[6] = new Property(283, 580, "Oriental Avenue", 100, 6);
        prop[7] = new Property(227, 580, 0, 0, "Chance", 1);
        prop[8] = new Property(172, 580, "Vermont Avenue", 100, 6);
        prop[9] = new Property(116, 580, "Connecticut Avenue", 120, 8);
        prop[10] = new Property(13, 668, 58, 624, "Just Visiting", 1);
        prop[11] = new Property(100, 565, "St. Charles Place", 140, 10);
        prop[12] = new Property(100, 509, "Electric Company", 150, 0);
        prop[13] = new Property(100, 455, "States Avenue", 140, 10);
        prop[14] = new Property(100, 398, "Virginia Avenue", 160, 12);
        prop[15] = new Property(100, 348, "Pennsylvania Railroad", 300, 25);
        prop[16] = new Property(100, 286, "St. James Place", 180, 14);
        prop[17] = new Property(100, 231, 0, 0, "Community Chest", 1);
        prop[18] = new Property(100, 176, "Tennessee Avenue", 180, 14);
        prop[19] = new Property(100, 119, "New York Avenue", 200, 16);
        prop[20] = new Property(18, 72, 0, 0, "Free Parking", 1);
        prop[21] = new Property(114, 103, "Kentucky Avenue", 220, 18);
        prop[22] = new Property(167, 103, 0, 0, "Chance", 1);
        prop[23] = new Property(223, 103, "Indiana Avenue", 220, 18);
        prop[24] = new Property(279, 103, "Illinois Avenue", 240, 20);
        prop[25] = new Property(332, 103, "B. & O. Railroad", 300, 25);
        prop[26] = new Property(390, 103, "Atlantic Avenue", 260, 22);
        prop[27] = new Property(447, 103, "Ventnor Avenue", 260, 22);
        prop[28] = new Property( 505, 103, "Water Works", 150, 0);
        prop[29] = new Property(559, 103, "Marvin Gardens", 280, 24);
        prop[30] = new Property(637, 47, 0, 0, "Go to Jail", 1);
        prop[31] = new Property(573, 123, "Pacific Avenue", 300, 26);
        prop[32] = new Property(573, 174, "North Carolina Avenue", 300, 26);
        prop[34] = new Property(573, 285, "Pennsylvania Avenue", 320, 28);
        prop[35] = new Property(573, 340, "Short Line", 300, 25);
        prop[36] = new Property(573, 398, 0, 0, "Chance", 1);
        prop[37] = new Property(573, 452, "Park Place", 350, 35);
        prop[38] = new Property(573, 509, 0, 0, "Luxary Tax", 1);
        prop[39] = new Property(573, 563, "Boardwalk", 400, 50);

        //Initialization of the Players
        p[0] = new Player();
        p[1] = new Player();

        addKeyListener (new Al());
        setFocusable(true);
        timer = new Timer(25,this);
        timer.start();

    }

    public void actionPerformed(ActionEvent e)
    {

        repaint();
    }

    public void paint(Graphics g)
    {
        super.paint(g);

        BufferedImage bgImage = readImage("C:/javagame/m.jpg");
        BufferedImage fgImage1 = readImage("C:/javagame/p1.png");
        BufferedImage fgImage2 = readImage("c:/javagame/p2.png");
        BufferedImage overlayedImage;




        overlayedImage = overlayImages (bgImage, fgImage1, fgImage2, prop[p[0].cur].x, prop[p[0].cur].y, prop[p[1].cur].x, prop[p[1].cur].y);


        g.drawImage(overlayedImage,0,0,null);
        g.drawString(String.valueOf(dice1),700,500);
        g.drawString(String.valueOf(dice2),700,510);


    }

    //Here in this method the player's images will be overlayed over the Game Board's Image
    public static BufferedImage overlayImages(BufferedImage bgImage,BufferedImage fgImage1, BufferedImage fgImage2, int x1, int y1, int x2, int y2)
    {
         Graphics2D g2 = bgImage.createGraphics();
         g2.drawImage(bgImage, 0, 0, null);
         g2.drawImage(fgImage1, x1, y1, null);
         g2.drawImage(fgImage2, x2, y2, null); 
         g2.dispose();
         return bgImage;
    }

     public static BufferedImage readImage(String fileLocation)
     {
         BufferedImage img = null;
         try 
         {
             img = ImageIO.read(new File(fileLocation));
         } 
         catch (IOException e) 
         {
             e.printStackTrace();

         }
            return img;
     }

     //Here the Dice Throw Simulation will take place
     public static int roll()
     {
        if (k == 6)
        {
            k = 0;
        }
        k++;
        return k;
     }

     public class Al extends KeyAdapter
     {
         public void keyPressed (KeyEvent e)
         {
             int kc = e.getKeyCode();

             //if  Player has pressed for the R (Dice throw/roll) then roll the dice and move accordingly on the Game Board
             if (kc == KeyEvent.VK_R && et == 0) 
             {
                 et = 1;

                dice1 = roll();
                dice2 = roll();

                p[pflag].cur = p[pflag].cur + dice1 + dice2;

                //If player's position exceeds the 39th space 
                if (p[pflag].cur > 39)
                {
                    p[pflag].cur = p[pflag].cur - 40;
                }

             }

             //If player has pressed for the E then end the current player's turn and pass the turn to the next player
             else if (kc == KeyEvent.VK_E && et == 1)
             {
                  if (pflag == 0)
                  {

                      et = 0;
                      pflag = 1;
                  }

                  else
                  {

                      et = 0;
                      pflag = 0;
                  }
             }



         }


     }




}

Here are those Non stop errors i get ar run-time

at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Board.paint(Board.java:101)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
View Answers









Related Pages:
Help please, some strange errors
Help please, some strange errors  Sorry about this messy formatting... is causing that run-time errors? Any kind of help will be helpful to me. and let... this errors so i have posted the whole program here. Here i tried to make the monopoly
Strange JVM behaviour
Strange JVM behaviour  hi I'm running a java application that is supposed to process a batch of files through some decisioning module. I need... for some reason the second run is taking almost 4-5 hrs. to do what the first run
need to fix errors please help
need to fix errors please help  it does have 2 errors what should i...; String name2; System.out.println("please enter your name:"); name1= input.readline(); System.out.println("please enter your friend's name:"); name2
Coding errors for printing function, please help
Coding errors for printing function, please help  Hello, We, my.... Can someone please take a look and help me to fix this. Although...; Please visit the following link: http://www.roseindia.net/java/example/java
i am Getting Some errors in Struts - Struts
i am Getting Some errors in Struts   I am Learning Struts Basics,I am Trying examples do in this Site Examples.i am getting lot of errors.Please Help me
Need urgent help with C++ errors!
Need urgent help with C++ errors!  hi, i'm new to C++ programming. this is my code... i'm using Turbo C++. It's showing so many errors!.. I don't know what to do. Please help!! #include<iostream.h> void main
help please
help please  hi i am done with register application using jsps... shwos some url if copy and paste that url even after i logout from my account... file.. Or atleast help me with code here.. I tried checking session alive
PLZ Need some help on the 2nd part of this question...Someone please help !!!!
PLZ Need some help on the 2nd part of this question...Someone please help !!!!  write an application that displays a menue of three items in a restaurant as follows: 1.Cheeseburger 4.99 2.Pepsi 2.00 3.Chips 0.75 prompt the user
Need some help urgently
Need some help urgently  Can someone please help me with this below question. I need to write a class for this. If you roll Y standard six-sided dice... number of possible combinations.   The actual question got some error. Its
Compiler errors in java
Compiler errors in java  Hi, I used GenerateRDF java file. Am getting errors when i run this code. I used command prompt only. getting errors as no package exist. i followed your instructions properly. Please help me out
jsp errors - JSP-Servlet
org.jfree.ui.RefineryUtilities; " Please help me.   Hi friend...jsp errors  Hi I got errors when running a jsp file I am giving.... Now i am getting less errors compared to previous. But I am getting 2 errors
Confusion on Functions. Help Please?!
of rectangle and area of cylinder. Right, I've got some of it, but I'm just not getting anywhere with it really :( Some help please...Confusion on Functions. Help Please?!  Write a program which has
help me please
help me please   Hello I want helping for this question , Please Write a program that reads some friendsââ?¬â?¢ names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
Hi Every One , please give me some idia to opning audio File . please Help ..
Hi Every One , please give me some idia to opning audio File . please Help ..  hi Dear Friend , please give me a program to opening audio file... me .please Help
New to Java Please help
New to Java Please help  Hi I need help, can some one help me with this. I am currently doing a project. drop me an email to my email address. Thanks!   If you are new in java, then you need to learn core java
Java Help Please
Java Help Please  I can't seem to figure out how to make this program, can some one help me please? It is due soon!! 4) Write a program that will take an input (Date object will contain fields for the month, day, and year - all
Please can you help
Please can you help  I have a some code which uses a textarea comment box that will on post return the users text to the same page that they entered...; Please could you change the code so it will do this Please. Many thanks. Colin
Please help with this code
Please help with this code  I need some help getting the Search method below to work with the menu, and I also cannot figure out how to get my bubble sort to work. I've spent a long time on this and think my brain is just fried
help please - Java Beginners
help please  i wrote this program but the function newLine dosnt work with me and i dont know where is exactly the error this is the code i... friend, We check the code having some changes to correct the code
please help in jsp - JSP-Servlet
please help in jsp  i have two Jsp's pages. on main.jsp have some... please help.  Hi Friend, Try... a school home page. in home.jsp have some links like message, vision
Please help need quick!!! Thanks
Please help need quick!!! Thanks  hey i keep getting stupid compile errors and don't understand why. i'm supposed to use abstract to test a boat race...(); ^ 6 errors any help would be appreciated guys. Thanks so
please help me - Java Beginners
please help me   I have some error in this programe //write acomputer programe using java to generate following series : //output: //1,2,3,0,-2,7,-4..... class Series1HW { public static void main(String args
ajax code please help to solve this........
ajax code please help to solve this.  in this i am trying to get data... null; } please help me when i am running this it show an error... and use ajax onchange but when i am trying to do so it show some error
Some Notes on Java Programming Environments
and to help you find certain kinds of errors. Function menu. A pop-up menu... Appendix 2: Some Notes on Java Programming Environments ANYONE WHO...-line environments. All programming environments for Java require some text
please help
please help  please send me the code of dynamic stack in java without using the built in functions
please help//
please help//  Number square cube 1 1 1 3 9 27 5 25 125 7 49 343 9 81 729 total 165 1225 â?? this is the ouput..;;; i
please help//
please help//  Number square cube 1 1 1 3 9 27 5 25 125 7 49 343 9 81 729 total 165 1225 â?? this is the ouput..;;; i
please help//
please help//  Number square cube 1 1 1 3 9 27 5 25 125 7 49 343 9 81 729 total 165 1225 â?? this is the ouput..;;; i
Please Help
Please Help  How do I create an attribute that represents the following: A grayscale 'color' value, that is, an integer between 0 and 255 inclusive, where 0 corresponds to the darkest black and 255 to the brightest white
Please Help
Please Help  How do I create an attribute that represents the following: A grayscale â??colorâ?? value, that is, an integer between 0 and 255 inclusive, where 0 corresponds to the darkest black and 255 to the brightest white
help please?
help please?  Define a class named Circle with the following properties: â?¢ An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both data fields
help please?
help please?  Define a class named Circle with the following properties: List item â?¢ An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
java please please help
java please please help  Dear Friends plz help me to complete this program import java.util.*; public class StringDemo { static...[] to HashMap so that i can seperate key and value using Map.Entry.Please help me!  
compilation errors
() { } } giving errors: 1) WelcomeServlet.java:37: ')' expected..."+"</a>"); ^ please tell me the reason. fast
help please?
help please?  Define a class named Circle with the following properties: ? An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both data fields
please help
please help  public class AllContact extends javax.swing.JFrame { /** Creates new form AllContact */ public AllContact() { initComponents(); try{ Connection1 con =new Connection1(); Connection conobj
java errors
java errors  when i am compiling the java program it is giving that the file can not be read what does it mean.. and what i have to do to remove that error.. please reply me soon   Check for the directory ..if you
getting errors
c[]={}; public static int[] retainPositiveNumbers(int[] a) { /* Please
Struts2 Helloworld problem -Please help - Struts
. Please help me out in resolving this problem and provide me a pointer...Struts2 Helloworld problem -Please help  Hi I am a beginner in Struts2. I tried some HelloWorld example in Struts2, to understand. But due to some
urgent...pleAse help me.....please!
urgent...pleAse help me.....please!  please help me urgent! how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
Servlets errors in same page.
Servlets errors in same page.  How do I display errors list in the same page where a form field exists using servlets...........i.e. without using JSP? Please explain with a simple username password program
some methods not working on firefox and chrome
some methods not working on firefox and chrome  why some of javascript methods are not working on firefox and chrome? ex : createElement(). Please help me to solve this problem. adv thanx
please help me.
please help me.  Please send me a code of template in opencms and its procedure.so i can implement the code. Thanks trinath
please help me.
please help me.  How to read a properties file in java with a suitable example. Please send me. Thanks Trinath   Please visit the following link: Java read properties file
Please Help Now
Please Help Now  i want to put this map in ajax oriented codeigniter website thanks in advance plz help me now plz very urgent
please help me.
please help me.  Please send me the validation of this below link. the link is http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html Thanks Trinath
please help me.
please help me.  How to move the edits.jsp in below link? http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.