Swing/AWT/SWT :: Changing Canvas Returns With NullPointerException

Jun 22, 2014

I'm currently having trouble with a Breakout clone that I'm working on when I want to change the scenes of the game. When I start out with the main menu and I hit play, the main menu calls for the StateManager to remove the MainMenu and then to add the GameState to start playing through the levels. But, whenever this is done it just gives a NullPointerException and freezes the game. I know the code for initially starting a State is fine because that is the same way the MainMenu is loaded but there seems to be an issue with changing from one to another...

This is the StateManager class that adds and removes the States/Canvases to and from the JFrame/Main class:
package com.pathtocreating.Breakout_V2.state;

import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.JFrame;
public class StateManager {
private ArrayList<State> states;

[Code] ....

The code that calls the change of state in MainMenuState is called in the update method:

if(inputController.isMouseClicked("LeftClick")) {
if(playHover) {
soundManager.playSound("ButtonClick");
BreakoutMain.sm.changeStates("GameState");

[Code] ....

Here is the full stack trace when clicking the area to change states:

Exception in thread "Thread-2" java.lang.NullPointerException
at sun.java2d.SunGraphics2D.validateColor(Unknown Source)
at sun.java2d.SunGraphics2D.<init>(Unknown Source)
at sun.awt.image.SunVolatileImage.createGraphics(Unknown Source)

[Code] ...

It gives that same value both before and after clicking on the region.

Printing out b after the State is changed to GameState gives the following:

java.awt.Component$BltSubRegionBufferStrategy@66116674

I've tried messing around with the order of which things are added/loading from the StateManager but am just failing to see what I did wrong.

View Replies


ADVERTISEMENT

Changing Canvas Returns With NullPointerException

Jun 21, 2014

I'm currently having trouble with a Breakout clone that I'm working on when I want to change the scenes of the game. When I start out with the main menu and I hit play, the main menu calls for the StateManager to remove the MainMenu and then to add the GameState to start playing through the levels. But, whenever this is done it just gives a NullPointerException and freezes the game. I know the code for initially starting a State is fine because that is the same way the MainMenu is loaded but there seems to be an issue with changing from one to another...

This is the StateManager class that adds and removes the States/Canvases to and from the JFrame/Main class:

public class StateManager
{
private ArrayList<State> states;
private int currentState;
private JFrame gameFrame;
public StateManager(JFrame gameFrame)
{
this.gameFrame = gameFrame;
states = new ArrayList<State>();

[Code] ....

I've tried messing around with the order of which things are added/loading from the StateManager but am just failing to see what I did wrong.

View Replies View Related

Enterprise JavaBeans :: Calling Singleton Bean From Session Bean Returns NullPointerException

Feb 23, 2013

I am doing this

@Startup
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Lock(LockType.READ)
public class ResourceBean {

[Code] ....

And I call this singleton bean from a stateless session bean like this

@Stateless
public class ClientBean {
@EJB
ResourceBean resource;

public String create(String r)
{
String res=resource.returnString(r);
return res;
}
}

But resource.returnString(r); gives a org.apache.jasper.JasperException: java.lang.NullPointerException I started the glassfish server in debug mode and found out that "resource" was null. but @PostConstruct in singleton does print which means singleton bean exists.

Can we call singleton beans with no interface in such a way form a session bean? I actually want to acquire instance of singleton bean when a client invokes method in Client bean...

View Replies View Related

Swing/AWT/SWT :: JFileChooser Is Throwing NullPointerException

Nov 20, 2014

I have a swing application that is using JFileChooser. When I click the Open menu item from File menu it should show the File dialog box where user can select the file.This application is running in my machine but encounters problem in another machine. File dialog box is not showing and stack trace shows that NullPointerException is thrown by JFileChooser..My machine is a 64 bit Windows 7 while the other machine is Windows 7 32 bit. Both machine are using java 1.6..To verify if its because of the 32-bit, I tried in another Windows 7 32-bit and the same application is working.

I came across this article [URL] .... which identified it as bug but already fix in 1.4.2_04. Though I am using 1.6, just to make sure I also tried the suggested work around.I put System.setProperty("swing.disableFileChooserSpeedFix", "true"); in my code but still not working...I also tried to add java -Dswing.disableFileChooserSpeedFix=true to the batch file that is launching the application and still not working

Code Sample:

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
public class FileChooserTester{
public Boolean loadMDBFile() {
System.setProperty("swing.disableFileChooserSpeedFix", "true");
JFileChooser fc = new JFileChooser();

[code]...

View Replies View Related

Swing/AWT/SWT :: GetGraphics Method Returns Null

Aug 23, 2007

The getGraphics() method in my constructor is returning a nullPointerException and I can't figure out why. This class is extending a JPanel and I thought calling super() would fix it because it makes sense that the JPanel would initialize its graphics object in the constructor, but that didn't fix it. The line that produces the error is in bold. I've narrowed it down to the getGraphics() method is returning null, so the next line that calls the graphics object is actually the one that produces the error.

int leftMargin = 2, rightMargin = 2, topMargin = 2, bottomMargin = 2;
int lineSpacing = 1;
int currentX = leftMargin, currentY = topMargin;
Font defaultFont, customFont;
public HTMLFrame(){
super();

[Code] ....

print(String) is a method I made that draws lines of text on the graphics object, similar to System.out.println(String) in the command prompt.

View Replies View Related

Swing/AWT/SWT :: Color Is Not Changing

Jan 29, 2015

Color only changes, when resizng frame with mouse, not when clicking.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SimpleGui1 implements ActionListener {
JFrame frame;
MyDrawnPanel drawnPanel;

[Code] .....

View Replies View Related

Simulated OS With Canvas

May 5, 2015

I have to build a simulated OS for my college class. I'm making it pretty simple, nothing too fancy and am using HTML5 Canvas. So far I have the icons on a black background and have made them draggable. I want to know how I can make it so when you click on an icon a box appears (just like a real OS) and then closes by clicking on the 'x'. I also want to be able to drag any icon into the trash bin and it disappears. I understand there are click/mouse events, but I don't know how to implement them into the code I have setup. Here's the code:

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div id="canvas"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/kineticjs/5.2.0/kinetic.js"></script>
<script defer="defer">
var stage = new Kinetic.Stage({
container: 'canvas',
width: 1910,
height: 995,

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Label Font Not Changing?

Feb 19, 2015

It's very simple, I've added an AWT component/control (specifically a Choice object to a Frame. It's a pop-up menu by any other name.

Above the pop-up, there's a label. I'm trying to change its font to no success.

* I create Label object called label1: Label label1 = new Label("This is a pop-up")
* I create a Font object called f: Font f = new Font("Times New Roman, Font.BOLD, 18)
* I apply the new font to the label: (in AFrame's constructor) label1,setFont(f)

When displayed the label's font seems to be stuck on Arialor something similar. Changing the point size however does have an effect.

import java.awt.Choice;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
* Defines a 'pop-up' AWT control that will be added to AFrame.
* It extends Choice - I may need extra functionality later.
*/

public class APopUp extends Choice implements ItemListener {
// instance variables
int noi; // no of items
String selected; // item selected from choice

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Changing Rectangle Color With MouseListener

Mar 2, 2014

I'm trying to build a program which sets a fill color for a rectangle. Each time the mouse is clicked the fill color changes according to the position of the mouse's X and Y. I succeeded to create a JFrame with a changing background according to the Mouse's position, but I can't seem to change the color of the rectangle (defined in MyPanel class).

This is the current code,

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;

[Code]...

View Replies View Related

Swing/AWT/SWT :: Changing Color Of JList Item

Oct 23, 2014

is there a good way to change the color of a JList item that isn't selected? I'm throwing my hand at building a client/server chat app and on the client side, I need to highlight the name of the person (which is in a JList) who has sent a message to the client GUI.

View Replies View Related

Swing/AWT/SWT :: Changing Text Of JLabel From Another Class

May 26, 2014

Create a dnd (dungeons and dragons) character creator and back ground generator, have it display and run on a gui, to start with i decided to creator the gui as i go so i can see the progress, first i tried eclipse and windows builder, well after 1 day of reinstalling windows builder in about 5 different ways from multiple guides and sometimes getting it to partly work ...

After doing some more research I have figured out how to get the main program to display the gui . Heres what i have:

package com.mrgreaper;
import javax.swing.*;
public class MainWindow {
private JPanel mainWindow;
private JLabel playerlbl;
private JLabel playerNamelbl;

[Code] .....

Now this works fine and the gui displays when the program is run but I can't change the text of any of the jlabels or textfield. If I try to do it in the main class i need to change them from private to public static but then in the form builder it says "cannot bind to static field *name of field*" but if i take static off then i cant change its value!

From what i understand this is because the window is an instance, so how to i change the value in that instance? I could put all my code in the one class, the one that creates the gui, but i really want it seperate, i would like the gui to update as the code runs... So how do i do it, how do i change the contents of jlabels on the fly, read the contents of text boxes on the fly etc....

I tried adding a getter setter

public void setCharFirst(JLabel charFirst) {
this.charFirst = charFirst;
}
in the MainWindow.class

Then i tried to set it from my main function

MainWindow.setCharFirst("test");

but it cant access it as my main function is static and it is not now can i make it static...

View Replies View Related

Java 2D Game - Use Canvas Without Extending It

Apr 10, 2014

Java Code:

public class Game extends Canvas implements Runnable, KeyListener {
private static final long serialVersionUID = 1L;

public Game() {
setMinimumSize(new Dimension(width, height));
setMaximumSize(new Dimension(width, height));
setPreferredSize(new Dimension(width, height));
}

[code]...

I want to remove the extends Canvas from the top line and when I use JFrame to add canvas, I don't do add.(this, but instead I do add a canvas variable I make. So instead of extending I want to make a variable. But then how would I do the start, stop and run?I want to use Graphics, Canvas (Not Jpanel because I want to use BufferedImage) & JFrame. I don't want to extend Canvas, how could I use Canvas identically to shown above but instead of extending using it as a variable? or, how could I do this?

View Replies View Related

Swing/AWT/SWT :: Changing Text Of JLabel By Pressing A Button?

Sep 20, 2014

I don't get what I missed in the code. I used the example of changing the text of a button by clicking on it, but instead I also added a JLabel and tried to make the button change its text instead, but it didn't work. What did I do wrong?

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class Buttone implements ActionListener{
JLabel label;
JButton button;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Changing Panel In Jframe On Click Of A Button

Jun 22, 2014

I want to switch panel on click of a button and code for switching panels is written in update method (Which gets called from notify observer of another class as part of Observer pattern.

unoGameController.playGame(playerFirst.getText(), playerSecond.getText());

playGame in Panel 1 of class 1 calls another class (class 2)and data comes in update method of class 1(Observer interface).

Now for switching panels code is in gameControllerDataProcessing . I am not able to switch the panels when this functionality runs.

However if i dont call the unoGameController.playGame(playerFirst.getText(), playerSecond.getText() and directly call the update method or directly write the switching panel code . then it works fine.

btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if((!(playerFirst.getText().equalsIgnoreCase("") ||playerSecond.getText().equalsIgnoreCase(""))&&(!playerFirst.getText().equalsIgnoreCase(playerSecond.getText())) ) ){
unoGameController.playGame(playerFirst.getText(), playerSecond.getText());

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Changing Color Of Jtable Base On A Row Of Cell Value In One Column

Feb 10, 2014

My code is

Double qty = 0.0;
for ( int i = 0; i < ingTable.getRowCount(); i++){
qty = (Double) ingTable.getValueAt(i,2);
if( qty < 30.0){
ingTable.setBackground(Color.red);
} else {
ingTable.setBackground(Color.white);
}
}

View Replies View Related

Swing/AWT/SWT :: Mini Paint Program - Changing Size Of Shapes

Jun 4, 2014

I am currently writing a small drawing program and I am having trouble with changing the size of the shapes. To do this, I have to access the arraylist shapes, check whether pressedX/pressedY is on any of the shapes in the arraylist using the findShape() method and then when released, uses moveBy() in the Rectangle/Oval/Line class and moveShape() in the miniDraw class to move the shape and draw it in the newreleasedX/releasedY position.

So far I think I have pin pointed the problem to being the method in all the shapes classes, that checks whether the pressedX/pressedY which is the on() method, and the findShape() method in the miniDraw class.

This is the minidraw class

import ecs100.*;
import java.awt.Color;
import java.io.*;
import java.util.*;
import javax.swing.JColorChooser;

[Code] .....

View Replies View Related

JavaFX 2.0 :: How To Create Off Screen Images By Canvas In Multi-thread Environment

Feb 25, 2015

I want to create off-screen images by Canvases in multi-thread environment.
 
I know that I use methods of GraphicsContext2D to draw on Canvas. Can I do this on Canvas which is not added to Scene ?
 
How can I get an image from a canvas after I invoke GraphicsContext2D methods? Can I get images in multi-thread environment ?

View Replies View Related

Why Is There A NullPointerException

Apr 21, 2015

I am doing a project for my Java class but I ran into a snag with my code.

package lesson13;
import java.io.FileNotFoundException;
import java.util.LinkedHashSet;
import java.util.Set;

public class CharCountingStudy {
public static void main(String[] args) throws FileNotFoundException{
Set<FileExaminer> examiners = new LinkedHashSet<>();
examiners.add(new FileExaminer("raven.txt"));
examiners.add(new FileExaminer("jabberwocky.txt"));

[Code] ....

I keep getting a NullPointerException at the "examiners.add(new FileExaminer("raven.txt"));", the "calculateCharCountAlpha();", and the "if (charCountAlpha.containsKey(w)){"and I don't know why it is doing that.

View Replies View Related

Getting A NullPointerException Error?

Oct 23, 2014

I am getting a NullPointerException Error and I cannot seem to figure out what is causing it. I am reading in a grades1.dat text file and putting the values into a 2D array. The error is occuring in my addGrade method, but I am not sure what the error is. Here are the values for my grades1.dat that I am running in through Run Arguments in JGRASP.

Student1
5
a Activities 0.05
q Quizzes 0.10
p Projects 0.25
e Exams 0.30
f Final 0.30
a100 a95 a100 a100 a100
q90 q80 q100 q80 q80 r90
p100 p95 p100 p85 p100
e77.5 e88
f92

Here are the errors that I am getting.

Exception in thread "main" java.lang.NullPointerException
at GradeBook.addGrade(GradeBook.java:114)
at GradeBookApp.main(GradeBookApp.java:55)
import java.util.Arrays;
/**
* Stores students name, a char array of category codes, a String array of categories, a double array of category weights, and a two dimensional double array of grades where each row contains all the grades in a particular category.

[code]....

View Replies View Related

How To Avoid NullPointerException

May 3, 2014

I have been playing around with my code, but how to avoid NullPointerexception.. So my program's point is simple, use Jsoup to scrape html of certain webpage, then i search the things i want and print them out. Problem is, when scraped html doesnt contain even 1 thing on my search list, i get NullPointerException... i understand why, Heres part of my code:

Java Code:

//Things i need to search from html
String[] MySearchArray = new String[]{"138","146","474"};
//Search things contained in MySearchArray and print them out
for (String Ml : MySearchArray) {
Element flights = doc.select(String.format("tr:contains(%s)", Ml)).first();
Elements flights2 = flights.select("td");
System.out.println(flights2.get(4).text() + " " + flights2.get(0).text()+ " " + flights2.get(3).text());
} mh_sh_highlight_all('java');

View Replies View Related

NullPointerException Under IF Statement Which Should Be Skipped

Feb 10, 2015

/**
* This method displays all winner names for a given year.
* @param year is the integer parameter asked of the user.
*/
public void displayAllWinnersForYear (int year) {
if (year >= 1993 || year <= 2009) {
String[] winnersForTheYear = nobelPrizeWinners.get(year);
for (int i = 0; i < winnersForTheYear.length; i++) {

[Code] ....

When year is outside the 1993-2009 range, I get a NullPointerException from line 10. Shouldn't it be skipped entirely since the conditions of its parent IF statement (line 7) is not met?

View Replies View Related

Programme Producing NullPointerException

Mar 18, 2014

Am new to programming and am trying to create a system that is similar to a train timetable system.I want the user to be able to enter the stops between two stations ( from a preset list of 5 stations ) and this be saved as an array list, and this array list be saved accordingly within a 2D array so if they were to look in [1][2] there would be an arraylist of stops between station 1 and 2.I used this to initialise the array of arraylists (in a class i created called stops)

ArrayList<String>[][] stopsArray= (ArrayList<String>[][])new ArrayList[5][5];
 
public void stops(){
for (int i = 0; i<5; i++){
for (int j=0; j<5; j++){
stopsArray[i][j]= new ArrayList<String>();
}
}
}

Then I use this code to set the stops

public void setNoStops(int stopsNo){
noOfStops = stopsNo;
}
 
[code]...

The bottom written line of code is mentioned in the null pointer error I recieve. Then.Then in my main programme I declare the new object and use these methods the method options displays the list of five stations with a number reference

System.out.println("Please choose a start station :");
options();
place1 = scanner.nextInt();
System.out.println();
 
System.out.println("Please choose an end station :");
options();
place2 = scanner.nextInt();
System.out.println();

[code]...

mystops is the object I created to store the information.

when compiling I recieve no errors.when I run the program it runs smoothly, asks for the number of stops, allows the user to enter a number, then says enter stop 1, I enter a word and the program crashes giving the error java.lang.NullPointerException

View Replies View Related

NullPointerException With Hashtable Object

Mar 1, 2014

I am having some problems with some code and I need an extra set of eyes. It appears I've missed something. I am getting a NullPointerException with a Hashtable object, which I can clearly see I've created. So I'm not quite sure why it is happening. I am pretty sure it is do with the code I've posted because I've tested everything else involved.Here is the code where it happens,

Java Code:

public void siteGen(String user, String site)
throws ExcGenDatabad, ExcSiteNodomain, Exception {
System.out.println("calling siteGen, user: " + user + ", site: " + site);
String nginx_template;
String fpm_template;

[code]....

View Replies View Related

EJB / EE :: Java JAX-WS Client NullPointerException

Aug 26, 2014

I'm new to web services. Right now i'm trying to consume JAX-WS web service on IBM WebSphere Application Server 7. Sending SOAP message with security header[username, password] parameters. Getting NullPointerException..

Exception :

javax.xml.ws.WebServiceException: java.lang.NullPointerException
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
at org.apache.axis2.jaxws.marshaller.impl.alt.DocLitBareMinimalMethod
Marshaller.demarshalFaultResponse(DocLitBareMinimalMethodMarshaller.java:443)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.getFaultResponse(JAXWSProxyHandler.java:559)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.createResponse(JAXWSProxyHandler.java:497)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:404)

[code]....

View Replies View Related

Type Name And Get Histogram - Getting NullPointerException

Dec 10, 2014

I recently switched some of code around to restructure how some things were working but now when I run the program I am getting a NullPointerException in multiple areas. I suspect it may have something to do with a constructor. I am very new to "object" - ish based programming.

I figured I should give a little background on the program, this program is reading from a text file of names and decade numbers(for each name) and storing each line into an object array. From there, there are menus and based on the users decision they can type a name and get a histogram, compare names with histograms, ect. Below this main method, I have provided the area where I have gotten the null pointer exception.

Here is the main method for the Client "nameApp"

Also excuse the formatting and curly braces for now!

public class NameApp{

private static boolean validInput;
private static boolean done = false;
private static boolean validDecade;
private static boolean validName;

[Code] ....

And here is the method in the same Client that is getting the null pointer exception:

The pointer exception is on line 6 which is:

if (nameInput.equalsIgnoreCase(list[i].getName())){
private static int checkListArray(String nameInput, Name[] list){
int nameLocation = -1;
int listLength = list.length;

[Code] ....

View Replies View Related

Static Error And NullPointerException With Array

Nov 7, 2014

I have an arraylist, list, that I need to take the size to declare an array, arr3, in another class. Problem 1: the size is giving me an error of "can not make static reference to non-static method getListSize() from the type FindItemInfo". I tried to change getListSize() to static and it gives me and error another place. I try to then fix that, and I get a new error... and so on.

I am using arr3 to store items the user can not afford. I have this next problem even when I input an integer for the arr3 size. I am getting a NullPointerException, and I can't figure out why the arr3[] is not loading. I tried debugging but can not figure out where I went wrong, especially since this code was working in the last assignment before I changed list[] to an arrayList. It always breaks at line 64, but I believe it has to be somewhere in the cashOut() method.

Relevant code is:

public class FindItemInfo implements InterfacePrint{
ArrayList <ItemAttribute> list = new ArrayList<ItemAttribute>();
//does stuff
public void printPriority(){
TransactionCalc finish = new TransactionCalc();

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved