Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Applet Help please, some strange errors
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


YasheshRathod
Help please, some strange errors
0 Answer(s)      a year and 7 months 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)

Advertisement
View Answers

Related Tutorials/Questions & Answers:
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
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
Advertisements
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
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
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
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
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  please send me the code of dynamic stack in java without using the built in functions
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!  
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
Please help
Please help  Problem: Write a program that does addition, subtraction, multiplication and division operation on real numbers. The operation started with a user entered 2 numbers and click one of the operation buttons
Please help
Please help  Problem: Write a program that does addition, subtraction, multiplication and division operation on real numbers. The operation started with a user entered 2 numbers and click one of the operation buttons
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
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
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
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
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
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
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
 

 

 

DMCA.com