I found this java source code for a brick breaker game online. I downloaded it and tried to run it but it gives me a NullPointerException. What is giving this exception and how do I fix it? Thanks.
http://zetcode.com/tutorials/javagamestutorial/breakout/
Here is the stacktrace:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:181)
at Ball.<init>(Ball.java:16)
at Board.gameInit(Board.java:48)
at Board.addNotify(Board.java:43)
at java.awt.Container.addNotify(Container.java:2578)
at javax.swing.JComponent.addNotify(JComponent.java:4685)
at java.awt.Container.addNotify(Container.java:2578)
at javax.swing.JComponent.addNotify(JComponent.java:4685)
at java.awt.Container.addNotify(Container.java:2578)
at javax.swing.JComponent.addNotify(JComponent.java:4685)
at javax.swing.JRootPane.addNotify(JRootPane.java:739)
at java.awt.Container.addNotify(Container.java:2578)
at java.awt.Window.addNotify(Window.java:663)
at java.awt.Frame.addNotify(Frame.java:470)
at java.awt.Window.show(Window.java:859)
at java.awt.Component.show(Component.java:1584)
at java.awt.Component.setVisible(Component.java:1536)
at java.awt.Window.setVisible(Window.java:842)
at Breakout.<init>(Breakout.java:14)
at Breakout.main(Breakout.java:18)
Exception in thread "Timer-0" java.lang.NullPointerException
at Board$ScheduleTask.run(Board.java:110)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Apparently this code is supposed to work, but it isn't.
You probably didn't download the images as well, or at least didn't put them in the right folder. Make sure you put the images here:
Browse to Ball.java, go two folder levels up, create there a folder called images and put there your images.
Related
I'm building a game in LibGDX and have began adding visual aspects of the game such as the logo. Considering that I've been using the default libgdxXXX.png files as placeholders for my logo, and that I'm replacing them with my logo, I didn't feel it had any more purpose in my program. I decide to delete it; but it decide to not compile and come up with this error:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: assets/libgdx128.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:148)
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setupDisplay(LwjglGraphics.java:196)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:142)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: assets/libgdx128.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:145)
... 3 more
Somehow, when I return the files from the Trash (I use Linux), it works again! I have checked my code and found nothing I wrote referred to those files. When I deleted the files 1 by 1, the error changes from libgdx128.png to libgdx64.png to libgdx32.png to libgdx16.png respectively. I have changed all the references from libgdx128.png to my logo.png in my code; yet when I try to delete the libgdx logo and run my program, it fails to compile! Any ideas?
I found out my problem. I forgot all about this code at DesktopLauncher.java:
for (int size : new int[] { 128, 64, 32, 16 }) {
configuration.addIcon("assets/libgdx" + size + ".png", FileType.Internal);
}
I did not know it was referencing to the files I have deleted. The configuration.addIcon(); was the code setting the program icon - similar to how a favicon works. I will be adding my own icon now that I know what the code does.
Hope this helps anyone else confused about the error.
Hi everyone I'm fairly new to biojava and trying to implement this piece of code:
AtomCache cache = new AtomCache();
cache.setPath("/tmp/");
FileParsingParameters params = cache.getFileParsingParams();
params.setLoadChemCompInfo(true);
StructureIO.setAtomCache(cache);
Structure strucuture = StructureIO.getStructure("4HHB");
after executing these lines im getting the following error message:
Exception in thread "main" java.lang.NoSuchFieldError: lineSplit
at org.biojava.bio.structure.align.util.UserConfiguration.(UserConfiguration.java:87)
at org.biojava.bio.structure.align.util.AtomCache.(AtomCache.java:115)
at protein_structure.main(protein_structure.java:27)
Java Result: 1
I cant figure out the reason for this error, I downloaded the pdb files for the proteins that Im working with (in this case "4HHB" in the /tmp/ directory but still the same error is showing up. can anyone tell me how Atomcache function works? Thanks
I'm using iText (in the latest version 5.4.4) for a generic print of user interfaces.
I have a Problem on some UIs, getting a NullPointerException:
23.10.2013 14:53:23.066 - ERROR -Container.doAdd()
com.itextpdf.text.DocumentException: java.lang.NullPointerException
...
Caused by: java.lang.NullPointerException
at com.itextpdf.text.pdf.ColumnText.setSimpleVars(ColumnText.java:312)
at com.itextpdf.text.pdf.ColumnText.setACopy(ColumnText.java:305)
at com.itextpdf.text.pdf.ColumnText.duplicate(ColumnText.java:294)
at com.itextpdf.text.pdf.PdfPCell.<init>(PdfPCell.java:255)
at com.itextpdf.text.pdf.PdfPRow.<init>(PdfPRow.java:131)
at com.itextpdf.text.pdf.PdfPTable.<init>(PdfPTable.java:261)
at com.itextpdf.text.pdf.ColumnText.setSimpleVars(ColumnText.java:347)
at com.itextpdf.text.pdf.ColumnText.setACopy(ColumnText.java:305)
at com.itextpdf.text.pdf.ColumnText.duplicate(ColumnText.java:294)
at com.itextpdf.text.pdf.PdfPCell.getMaxHeight(PdfPCell.java:968)
at com.itextpdf.text.pdf.PdfPRow.calculateHeights(PdfPRow.java:209)
at com.itextpdf.text.pdf.PdfPRow.getMaxHeights(PdfPRow.java:592)
at com.itextpdf.text.pdf.PdfPTable.getRowHeight(PdfPTable.java:990)
at com.itextpdf.text.pdf.PdfPTable.getRowHeight(PdfPTable.java:971)
at com.itextpdf.text.pdf.ColumnText.goComposite(ColumnText.java:1821)
at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:882)
at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:877)
at com.itextpdf.text.pdf.PdfPRow.splitRow(PdfPRow.java:736)
at com.itextpdf.text.pdf.ColumnText.goComposite(ColumnText.java:1662)
at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:882)
at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:877)
at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:866)
at com.itextpdf.text.pdf.PdfDocument.addPTable(PdfDocument.java:2602)
at com.itextpdf.text.pdf.PdfDocument.add(PdfDocument.java:727)
... 24 more
After days of debugging my own code and the code of iText, I think I found the responsible line in class com.itextpdf.text.pdf.PdfPRow line 699:
newCells[k].setColumn(null);
I removed this line in the iText-API and the NullPointer does not appear any more. Then the program generates a PDF again, but there still is a problem that there is to many vertical space, which i couldn't fix yet.
Does anybody have the same Problem? Is it a bug in iText?
Thanks for help!
MaKu
While creating a jfreechart im getting following error and I am not sure whats the reason for it..any help??
Exception in thread "main" java.lang.NoSuchMethodError: org.jfree.ui.RectangleInsets.<init>(DDDD)V
at org.jfree.chart.axis.Axis.<clinit>(Axis.java:146)
at org.jfree.chart.StandardChartTheme.<init>(StandardChartTheme.java:227)
at org.jfree.chart.ChartFactory.<clinit>(ChartFactory.java:229)
at modules.images.Chart.createChart(Chart.java:67)
at modules.images.Chart.<init>(Chart.java:59)
at modules.images.Chart.main(Chart.java:506)
Make sure you have jcommon-1.0.0.jar (or a later version) on your classpath.
I frequently get what appears to be a stackoverflow error ;-) from YUICompressor. The following is the first part of thousands of error lines that come from attempting to compress a 24074 byte css stylesheet (not the "Caused by java.lang.StackOverflowError about 8 lines down):
iMac1:src jas$ min ../style2.min.css style2.css
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)
Caused by: java.lang.StackOverflowError
at java.lang.Character.codePointAt(Character.java:2335)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3344)
at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
... (plus 1021 more error lines)
The errors happen usually after adding a couple of lines to the file getting compressed. The css is fine, and works perfectly in the uncompressed format. I don't see a particular pattern to the types of selectors added to the file that cause the errors. In this case, adding the following selector to a previously compressible file resulted in the errors:
#thisisatest
{
margin-left:87px;
}
I am wondering if there is perhaps a flag to java to enlarge the stack that might help. Or if that is not the problem, what is?
EDIT:
As I was posting this question, it dawned on me that I should check the java command to see if there was a parameter to enlarge the stack. Turns out that it is -Xssn, where "n" is a parameter to indicate the stack size. Its default value is 512k. So I tried 1024k but that still led to the stackoverflow. Trying 2048k works however, and I think this could be the solution.
EDIT 2:
While I no longer use this method for minification any longer, to be more specific here is the full command (which I have set up as a shell alias), showing how the -Xss2048k parameter is used:
java -Xss2048k -jar ~/Documents/RepHunter/Website\ Materials/Code/Third\ Party\ Libraries/YUI\ Compressor/yuicompressor-2.4.8.jar --type css -o
As posted in my edit, the solution was to add the parameters to the java command. The clue was the error line at the 5-th "at" line, as follows:
at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)
Caused by: java.lang.StackOverflowError
Seeing that the issue was a "StackOverlowError" ;-) gave the suggestion to try to increase the stack size. The default is 512k. My first try of 1024k did not work. However increasing it to 2048k did work, and I have had no further issues.