Results 1 to 5 of 5
Thread: Java Struct
- 09-20-2011, 03:27 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
Java Struct
What is wrong with this structure ? why "figure[0].turn[0].matrix=arrowFig1" can't save value?Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.applet.*; public class sock extends Applet { O_figuros Obj=new O_figuros(); public void init(){ } public class subC{ public int[][] matrix=new int[3][3]; } public class subB { public subC[] turn =new subC[4]; } public class O_figuros{ subB[] figure= new subB[4]; private int[][] arrowFig1=new int[][]{ {0,2,0},{0,2,0}, {0,2,0}}; public O_figuros() { figure[0].turn[0].matrix=arrowFig1; //Exception in thread "main" java.lang.NullPointerException } } }Last edited by akl; 09-20-2011 at 04:43 PM.
- 09-20-2011, 03:32 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Java Struct
Your bracketing is very wrong. Each open bracket, or parentheses should have a closing one.
- 09-20-2011, 06:10 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
Re: Java Struct
If launching program, I have this error.
appletviewer h.html
java.lang.NullPointerException
at sock$O_figuros.<init>(sock.java:32)
at sock.<init>(sock.java:11)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.applet.AppletPanel.createApplet(AppletPanel.ja va:785)
at sun.applet.AppletPanel.runLoader(AppletPanel.java: 714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:662)
- 09-20-2011, 06:39 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Java Struct
Try printing the variables, the one that prints 'null' hasn't been initialized properly. As it stands your code is a bit confusing, you should considering thinking it over and try making it easier to understand.
- 09-20-2011, 06:51 PM #5
Similar Threads
-
struct problem
By amitabh in forum Web FrameworksReplies: 1Last Post: 09-01-2010, 02:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks