Results 1 to 5 of 5

Thread: Java Struct

  1. #1
    akl
    akl is offline Member
    Join Date
    Sep 2011
    Posts
    7
    Rep Power
    0

    Default Java Struct

    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
            }
              
    }
    }
    What is wrong with this structure ? why "figure[0].turn[0].matrix=arrowFig1" can't save value?
    Last edited by akl; 09-20-2011 at 05:43 PM.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Java Struct

    Your bracketing is very wrong. Each open bracket, or parentheses should have a closing one.

  3. #3
    akl
    akl is offline Member
    Join Date
    Sep 2011
    Posts
    7
    Rep Power
    0

    Default Re: Java Struct

    Quote Originally Posted by sunde887 View Post
    Your bracketing is very wrong. Each open bracket, or parentheses should have a closing one.
    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)

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default 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.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Java Struct

    You define an array.
    Where do you put any values in the array?

Similar Threads

  1. struct problem
    By amitabh in forum Web Frameworks
    Replies: 1
    Last Post: 09-01-2010, 03:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •