Getting arrays with Class.getDeclaredFields

I would like someone to tell me how is it possible to change values in an array with the getDeclaredFields() method of class Class. I am able to get all fields of my class but i doesn't work with any kind of array..
here is my Class :
class Objet
int index;
int[] valeurs;
I am able to change the value of index with this code:
private void readObject( java.lang.Object o )
java.lang.reflect.Field f[];
java.lang.Class cl = o.getClass();
f = cl.getDeclaredFields()
try
try
f.setInt( o, 0 );
catch ( java.lang.IllegalAccessException e)
System.out.println("illegal access exception ");
catch ( java.lang.IllegalArgumentException e )
System.out.println("illegal argument exception");
can someone please help me?
thanks

In order to make it work you should add f.setAccessible( true) before settung any value.
You may also need to look at the serialization spec, especailly on storing and retrieving fields. http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/serial-arch.doc7.html#5253

Similar Messages

  • Getting arrays with same types

    Hi,
    I'm writing an application and at a certain point I need to be able to compare constraints of the same type to see if there are any conflicts.
    At first you get an array with all kinds of constraints in it, not sorted and not knowing wich types are in there. I wrote a comparator to sort the array, which works. After sorting I count the different types there are. Now I would like to make a vector for each type and fill these vectors with the constraints, but I'm not sure how I can do this.
    What I have so far is:
    //first the array of preferred constraints is being examined,
    //if there are conflicts: arbitrarily one of both
    //preferred constraints is being eliminated
    Arrays.sort(pref,new ConstraintTypeComparator());
    //conflicts are only possible between constraints of the same
    //type so after sorting, we get vectors of simillar constrainttypes
    for(int i = 0; i < pref.length; i++){
       //count how many different types there are in the array
       int countTypes = 1;
       for (int j = 0; j < pref.length - 1; j++){
        if(! pref[j].getConstraintType().equals(
            pref[j+1].getConstraintType ())) countTypes++;}
    //make vectors with only constraints of the same type in them
    //for each type there is
        for (int k = 0; k < countTypes; k++){                 
            //not sure how to do this
    [\code]
    Is there an easy way/method I can use to create (and fill) these vectors?
    thanks

    Very funny, but doesn't help one bit...
    You don't know in advance how many types there will be, so in your code indeed if you have more than three: panic(); not only you don't know how many types there will; you also don't know which types there will be. The type of a constraint is a string though, so you could get, save and compare them...
    Isn't there a way to do something like:
    for (int i = 0; i < length; i++){
      Vector type+i+ = new Vector;
    //blalba
    [\code]

  • Getting LinkageError with class loader

    I've written a class loader which extends java.net.URLClassLoader. My class is called EntryClassLoader. It only ovverides findClass() so that it will search a user-supplied path for a class. Beloww is the code:
    public Class findClass(String className) throws ClassNotFoundException
    try {
    // First check to see if the user has prepended some
    // directory path
    if (className.indexOf(File.separatorChar) != -1) {
    String path = className.substring(0,
    className.lastIndexOf(File.separatorChar));
    className = className.substring(className.lastIndexOf(File.separatorChar)
    + 1);
    addURL(new File(path).toURL());
    return super.findClass(className);
    catch (MalformedURLException e) {
    e.printStackTrace();
    return null;
    Here's a sample test program I've written:
    public static void main(String args[]) throws Exception {
    EntryClassLoader loader = new EntryClassLoader();
    loader.findClass("TestPlayer");
    loader.findClass("TestPlayer");
    If I comment out the 2nd call to findClass(), the program runs fine, and I know that TestPlayer is successfully loaded. With the code as is however, I get the following error:
    Exception in thread "main" java.lang.LinkageError: duplicate class definition: TestPlayer
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at nirex.EntryClassLoader.findClass(EntryClassLoader.java:33)
    at TestLoader.main(TestLoader.java:8)
    Could someone please explain why I might be getting this error. And I really don't understand why it works if I only call findClass() once. Thanks.
    John

    Check if findLoadedClass(className) is null and load only then. If findLoadedClass() returns a non-null value, the class has already been loaded.

  • Getting problem with DOMImplementation classes method getFeature() method

    hi
    getting problem with DOMImplementation classes method getFeature() method
    Error is cannot find symbol getFeature()
    code snippet is like...
    private void saveXml(Document document, String path) throws IOException {
    DOMImplementation implementation = document.getImplementation();
    DOMImplementationLS implementationLS = (DOMImplementationLS) (implementation.getFeature("LS", "3.0"));
    LSSerializer serializer = implementationLS.createLSSerializer();
    LSOutput output = implementationLS.createLSOutput();
    FileOutputStream stream = new FileOutputStream(path);
    output.setByteStream(stream);
    serializer.write(document, output);
    stream.close();
    problem with getFeature() method

    You are probably using an implementation of DOM which does not implement DOM level-3.

  • Get data with correct array size

    My VI is trying to rearrange the 2D array that I read from test.xls file, so that each function is get separated with there data in it.
    Look over the test.xls file that I have attached. It has 2 columns. Both contains couple functions designated with ) and (. So, ACU_PGM is considered a function. I have rearranged the data so when ACU_PGM (or PGM is selected) the data following it is data for PGM before another function starts, which is KEY and 500 in this case. Same way for all other functions. Each column always ends by );
    )ACU_PGM( )CAB_INP(
    KEY WRITE
    500 50
    )ACU_DIA( 3
    DM1 0
    1010.1 )CAB_CLC(
    0 WRITE
    PROTECT 50
    DM2 3
    101.23 0
    10 NA
    NA )CAB_CRX(
    ); TEMP_1
    3
    0
    The problem with my current design is I am initializing array with 0x0 size, once it gets the 1st function it gets initialized with that same size of that function array for that entire column's fnction, so it want take more elements if 2nd function in same column have more elements like in this case. ACU_DIA has 8 elements but it will only take 2 elements as ACU_PGM has 2 in it.
    Please look over the Get_function.Vi only half portion. I have instructions in text in Vi also. I saw that columns are not lookin good after I submit the question so please open test.xlx file to see actual data Thank you.Message Edited by Amy222000 on 06-02-2005 03:44 PM
    Attachments:
    get_function.zip ‏795 KB
    test.xls ‏14 KB

    Duplicate Post
    E. Sulzer
    Applications Engineer
    National Instruments

  • Problems with getting array length

    I couldn't get array length in the java from the oracle.
    Here is my source.
    Can anybody answer me, I will really appriciate that.
    Thanks.
    public class Test_tb{
    public static double Test (oracle.sql.ARRAY args){
    double ret = 0;
    try {
    Double[] retArr = (Double[]) args.getArray();
    return retArr.length;
    } catch (Exception e){}
    return ret;
    }

    I've rewritten your code to include the display of any exception that might occur. Could you please run it and post any stack trace here? Thanks.
    public class Test_tb{
      public static double Test (oracle.sql.ARRAY args){
      double ret = 0;
      try {
        Double[] retArr = (Double[]) args.getArray();
        return retArr.length;
      } catch (Exception e){}
        e.printStackTrace();
        return ret;
    }

  • Working with Classes and Arrays

    hello to all,
    public class Store
    //private data
    private Person list[];
    private int count;
    private int maxSize;
    //constructor starts
    public Store(int max)
    count = Person.count(); //sets count to 0     
    maxSize = max;//maxSize is equals to max
    Person list[] = new Person[maxSize];
    }//end of store
    //constructor ends
    //accessor starts   
    public int getCount()
    for(int i=0; i<list.length; i++)
    int result = list;
    return result;
    }//returns the number of elements currently in store
    the code above is working with classes and some arrays
    what am trying to do is to display what the array holds
    and then i meet an error saying that
    INCOPATIBLE TYPES - FOUND PERSON BUT EXPECTED INT
    Please note that am new to this!
    Thank you in advanced!
    <img src="file:///C:/Documents%20and%20Settings/fh84/Desktop/untitled.JPG" alt="" />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    public class Store
        //private data
        private Person list[];
        private int count;
        private int maxSize;
    //constructor starts
        public Store(int max)
             count = Person.count(); //sets count to 0     
             maxSize = max;//maxSize is equals to max
            // Person list[] = new Person[maxSize];
             Person list[] = new Person[maxSize]; //set tne
        }//end of store
    //constructor ends
    //accessor starts  
        public int getCount()
            for(int i=0; i<list.length; i++)
                int  result = list;
    return result;
    am sending the code again                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Why does page-break-before get replaced with br class hcp10?

    why does <br style="page-break-before: always;"> get replaced with <br class="hcp10">
    This issue only occurs when generating an HTML Help CHM file.

    An alternative method can be found in Item 23 at http://www.grainge.org/pages/snippets/snippets.htm#content.
    Are you saying the code in the source file gets changed? I suspect you mean target files but how are you identifying the change in a CHM? Is the change causing a problem?
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Get array values from multidim array

    Hello Everyone,
    I am working with a two dim array. double twoDim[] = new double[100][100]. If I want to take "strips" of the array based on the x values I just do this.
    for(int i = 0; i < twoDim.length; i++)
         double a[] = twoDim;
    My question is how do I do a loop that returns a single dimensional array with respect to the y value ?  In effect doing this, (which fails miserably by the way).for(int i = 0; i < twoDim.length; i++)
    double a[] = twoDim[][i];
    Sincerely,
      Chem_E                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    That can't be done. The reason why it works so well with getting separate rows out of the 2d-array is that multi-dimensional arrays in Java are really just arrays of arrays.
    So each row is a separate array, which you can easily handle as a separate Object.
    You could wrap your 2d-array in a custom class (let's call it Matrix) and provide accessors that return views on the rows/columns (you could call them Vectors).

  • Lots of blank space when printing array with only last element printed

    I have a slight problem I have been trying to figure it out for days but can't see where my problem is, its probably staring me in the face but just can't seem to see it.
    I am trying to print out my 2 dimensional array outdie my try block. Inside the trying block I have two for loops in for the arrays. Within the second for loop I have a while to put token from Stringtokeniser into my 2 arrays. When I print my arrays in this while bit it prints fine however when I print outside the try block it only print the last element and lots of blank space before the element.
    Below is the code, hope you guys can see the problem. Thank you in advance
       import java.io.*;
       import java.net.*;
       import java.lang.*;
       import java.util.*;
       import javax.swing.*;
       public class javaflights4
          public static final String MESSAGE_SEPERATOR  = "#";
          public static final String MESSAGE_SEPERATOR1  = "*";
          public static void main(String[] args) throws IOException
             String data = null;
             File file;
             BufferedReader reader = null;
             file = new File("datafile.txt");
             String flights[] [];
                   //String flightdata[];
             flights = new String[21][7];
             int x = 0;
                   //flightdata = new String[7];
             int y = 0;
             try
                reader = new BufferedReader(new FileReader(file));   
                //data = reader.readLine();   
                while((data = reader.readLine())!= null)   
                   data.trim();
                   StringTokenizer tokenised = new StringTokenizer(data, MESSAGE_SEPERATOR1);
                   for(x = 0; x<=flights.length; x++)
                      for(y = 0; y<=flights.length; y++)
                         while(tokenised.hasMoreTokens())
                            //System.out.println(tokenised.nextToken());
                            flights [x] [y] = tokenised.nextToken();
                            //System.out.print("*"+ flights [x] [y]+"&");
                   System.out.println();
                catch(ArrayIndexOutOfBoundsException e1)
                   System.out.println("error at " + e1);
                catch(Exception e)
                finally
                   try
                      reader.close();
                      catch(Exception e)
             int i = 0;
             int j = 0;
             System.out.print(flights [j]);
    //System.out.println();

    A number of problems.
    First, I bet you see a lot of "error at" messages, don't you? You create a 21x7 array, then go through the first array up to 21, going through the second one all the way to 21 as well.
    your second for loop should go to flights[x].length, not flights.length. That will eliminate the need for ArrayIndexOutOfBounds checking, which should have been an indication that you were doing something wrong.
    Second, when you get to flights[0][0] (the very first iteration of the inner loop) you are taking every element from the StringTokenizer and setting flights[0][0] to each, thereby overwriting the previous one. There will be nothing in the StringTokenizer left for any of the other (21x7)-1=146 array elements. At the end of all the loops, the very first element in the array (flights[0][0]) should contain the last token in the file.
    At the end, you only print the first element (i=0, j=0, println(flight[ i][j])) which explains why you see the last element from the file.
    I'm assuming you have a file with 21 lines, each of which has 7 items on the line. Here is some pseudo-code to help you out:
    count the lines
    reset the file
    create a 2d array with the first dimension set to the number of lines.
    int i = 0;
    while (read a line) {
      Tokenize the line;
      count the tokens;
      create an array whose size is the number of tokens;
      stuff the tokens into the array;
      set flights[i++] to this array;
    }

  • How to insert values into an array of class

    Hello everyone,
    I need help in inserting values into an array of class, which i have read from a file.
    Length of the array is 5. I should insert values one by one into that array.
    If the array is full (if count = 5), then I should split the array into 2 arrays
    and adjust the values to left and right with median.
    I'm getting an ArrayBoundException .. can anybody help me out ?
    Thanks in advance
    Here is my code..........
    import java.util.*;
    import java.io.*;
    public class Tree
         static String second;
         static String first;
         static int count = 5;
         public void insert(int f1,int s1, int c)
              if(c!=0)
                   Record[] rec = new Record[4];
                   for (int i = 0; i < 5; i++)
                          rec[i] = new Record(); 
                   for(int i = 0; i<=4;i++)
                        rec.x = f1;
                        rec[i].y = s1;
              else
                   System.out.println("yes");
         public static void main(String[] args)
              Tree t = new Tree();
              try
                   FileReader fr = new FileReader("output.txt");           // open file
                   BufferedReader br = new BufferedReader(fr);
                   String s;
                   while((s = br.readLine()) != null)
                        StringTokenizer st = new StringTokenizer(s);
                        while(st.hasMoreTokens())
                             first = st.nextToken();
                             second = st.nextToken();
                        //     System.out.println("First-->"+first+" "+"Second-->"+second);
                        int fir = Integer.parseInt(first);
                        int sec = Integer.parseInt(second);
                        t.insert(fir, sec, count);                    
                   fr.close(); // close file           
              catch (IOException e)
    System.out.println("Can't read file");
    class Record
         public int x,y;

    Hi qwedwe.
    Record[] rec = new Record[4];
                   for (int i = 0; i < 5; i++)
                          rec[i] = new Record(); 
                     }Here is your error: you have an array of 4 Records, but you create and (try to) insert 5 Record-instances.... try:
    Record[] rec = new Record[c];
                   for (int i = 0; i < c; i++)
                          rec[i] = new Record(); 
                     }Regards,
    Norman

  • Array of class objects

    I was wondering how would you declare an array of class objects. Here is my situation:
    I'm working on a project dealing with bank accounts. Each customer has a specific ID and a balance. I have to handle transactions for each customer at different times, so I was thinking that I need an array of class objects; however, I dont know how to initialize them.
    Here's what I did:
    BankAccount [ ] myAccount = new BankAccount[10];
    // 10 = 10 customers
    How do I initialize the objects?
    Thankz

    I was wondering how would you declare an array of
    class objects. Here is my situation:
    I'm working on a project dealing with bank accounts.
    Each customer has a specific ID and a balance. I have
    to handle transactions for each customer at different
    times, so I was thinking that I need an array of
    class objects; however, I dont know how to initialize
    them.
    Here's what I did:
    BankAccount [ ] myAccount = new BankAccount[10];
    // 10 = 10 customers
    How do I initialize the objects?
    Thankz
    HAI
    Use the hashtable
    and store the classObject of each customer with the corresponding Id in it
    and whenever u want to recover a class match the Id and get the corresponding class
    that is the best way to solve ur problem
    Regards
    kamal

  • Arrays with more than 2^31-1 (2147483647) elements?

    Hi,
    I'm working with very large datasets and would like to be able to process arrays with more than 2^31-1 elements. This limit seems to come about because Java requires a signed integer to be passed as a parameter to an array declaration, e.g.:
    Object bytes = new byte[2147483647]; // works
    Object bytes = new byte[2147483648]; // failsIs there any way to get around this?
    Thanks very much,
    - Davi

    Is there any way to get around this?What about creating a class that aggregatesseveral
    arrays and implements the List API?
    KajUnfortunately, many of the methods in the List
    interface depend on int indexes also. You would
    probably want these methods to use a long index
    instead.True. I should have said that he should mimic the behaviour of the List interface, but not implement it.
    Kaj

  • Getting an abstract class working

    Simply put, something is going wrong with my abstract class, now my assignArray method wont work and my frame wont compile at all anymore.
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    public abstract class bankPresentation extends JFrame implements ActionListener {
         //define the frame properties
         private static final int FRAME_WIDTH = 300;
         private static final int FRAME_HEIGHT = 600;
         private static final int FRAME_X_ORIGIN = 150;
         private static final int FRAME_Y_ORIGIN = 250;
         private static final int BUTTON_WIDTH = 80;
         private static final int BUTTON_HEIGHT = 30;
         //define all the frame elements
         JRadioButton depositRadioButton = new JRadioButton("Deposit");
         JRadioButton withdrawRadioButton = new JRadioButton("Withdraw");
         ButtonGroup bankButtonGroup = new ButtonGroup();
         JLabel amountLabel;
         JTextField amountField;
         JTextArea textArea;
         JScrollPane textBoxScroll;
         JButton newAccountButton;
         JButton summaryButton;
         JButton depositWithdrawButton;
         double initialAmountDouble;
         DecimalFormat formatDecimal = new DecimalFormat("$0.00");
         //create a new array, size is 10
         bankSummary customerList[] = new bankSummary[10];
         public static void main(String[] args) {
              bankPresentation frame = new bankPresentation();
              frame.setVisible(true);
         public bankPresentation() {
              Container contentPane;
              //create the deposit and withdraw radio buttons, put them in a group
              //and add them to the frame
              bankButtonGroup.add(depositRadioButton);
              bankButtonGroup.add(withdrawRadioButton);
              setSize(FRAME_WIDTH, FRAME_HEIGHT);
              setResizable(false);
              setTitle("Ch13 Project");
              setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
              contentPane = getContentPane();
              contentPane.setLayout(new FlowLayout());
              contentPane.add(withdrawRadioButton);
              contentPane.add(depositRadioButton);
              //add a large text area to the pane
              textArea = new JTextArea();
              textArea.setColumns(25);
              textArea.setRows(20);
              textArea.setLineWrap(true);
              textBoxScroll = new JScrollPane(textArea);
              textBoxScroll
                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              textArea.setBorder(BorderFactory.createLineBorder(Color.RED));
              // Set to non edit
              textArea.setEditable(false);
              contentPane.add(textBoxScroll);
              //create new buttons to create accounts, deposit/withdraw with existing ones, and
              //get a statement with existing ones
              newAccountButton = new JButton("Create Account");
              newAccountButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
              contentPane.add(newAccountButton);
              summaryButton = new JButton("Summary");
              summaryButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
              contentPane.add(summaryButton);
              depositWithdrawButton = new JButton("Deposit/Withdraw");
              depositWithdrawButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
              contentPane.add(depositWithdrawButton);
              //add actionlisteners to all buttons
              summaryButton.addActionListener(this);
              newAccountButton.addActionListener(this);
              depositRadioButton.addActionListener(this);
              withdrawRadioButton.addActionListener(this);
              depositWithdrawButton.addActionListener(this);
              //initialize the array with some existing accounts
              assignArray();
          abstract void assignArray() {
              for (int i = 0; i < customerList.length; i++) {
                   customerList[i] = new bankSummary();
              customerList[0].setValues("Bob", "Ghost", "1234", "Savings", 500);
              customerList[1].setValues("Joe", "Shmo", "1333", "Checking", 600);
              customerList[2].setValues("Jack", "Biggs", "9023", "Savings", 200);
         public void actionPerformed(ActionEvent event) {
              int arrayIndexInt = 3;
              // Determine source of event
              Object sourceObject = event.getSource();
              //if a new account is created, ask for first name, last name, pin number, and whether it
              //be a checking or savings account, and the initial amount you're depositing
              if (sourceObject == newAccountButton) {
                   String fNameString = JOptionPane.showInputDialog("First Name: ");
                   String lNameString = JOptionPane.showInputDialog("Last Name: ");
                   String pinString = JOptionPane
                             .showInputDialog("Desired Pin Number: ");
                   String accountType = JOptionPane
                             .showInputDialog("Checking or Savings Account? Enter (Checking or Savings)");
                   String initialAmountStr = JOptionPane
                             .showInputDialog("Initial Deposit Amount: ");
                   double initialAmountDouble = Double.parseDouble(initialAmountStr);
                   customerList[arrayIndexInt].setValues(fNameString, lNameString,
                             pinString, accountType, initialAmountDouble);
                   arrayIndexInt += 1;
                   JOptionPane.showMessageDialog(null, "Account Created!");
              //if the summary button is pressed, ask for the first name on the account
              //then ask for the pin, display the balance for that said account
              if (sourceObject == summaryButton) {
                   String nameVerifyStr = JOptionPane
                             .showInputDialog("Firstname on Account: ");
                   String pinVerifyStr = JOptionPane.showInputDialog("Pin Number: ");
                   if (nameVerifyStr.equals(customerList[0].getFirstName())
                             && pinVerifyStr.equals(customerList[0].getPin())) {
                        textArea.append("Customer: " + customerList[0].getFirstName()
                                  + " " + customerList[0].getLastName() + "\nAccount: "
                                  + customerList[0].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[0].getBalance()));
                   if (nameVerifyStr.equals(customerList[1].getFirstName())
                             && pinVerifyStr.equals(customerList[1].getPin())) {
                        textArea.append("Customer: " + customerList[1].getFirstName()
                                  + " " + customerList[1].getLastName() + "\nAccount: "
                                  + customerList[1].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[1].getBalance()));
                   if (nameVerifyStr.equals(customerList[2].getFirstName())
                             && pinVerifyStr.equals(customerList[2].getPin())) {
                        textArea.append("Customer: " + customerList[2].getFirstName()
                                  + " " + customerList[2].getLastName() + "\nAccount: "
                                  + customerList[2].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[2].getBalance()));
                   if (nameVerifyStr.equals(customerList[3].getFirstName())
                             && pinVerifyStr.equals(customerList[3].getPin())) {
                        textArea.append("Customer: " + customerList[3].getFirstName()
                                  + " " + customerList[3].getLastName() + "\nAccount: "
                                  + customerList[3].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[3].getBalance()));
                   if (nameVerifyStr.equals(customerList[4].getFirstName())
                             && pinVerifyStr.equals(customerList[4].getPin())) {
                        textArea.append("\nCustomer: " + customerList[4].getFirstName()
                                  + " " + customerList[4].getLastName() + "\nAccount: "
                                  + customerList[4].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[4].getBalance()));
                   if (nameVerifyStr.equals(customerList[5].getFirstName())
                             && pinVerifyStr.equals(customerList[5].getPin())) {
                        textArea.append("\nCustomer: " + customerList[5].getFirstName()
                                  + " " + customerList[5].getLastName() + "\nAccount: "
                                  + customerList[5].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[5].getBalance()));
                   if (nameVerifyStr.equals(customerList[6].getFirstName())
                             && pinVerifyStr.equals(customerList[6].getPin())) {
                        textArea.append("\nCustomer: " + customerList[6].getFirstName()
                                  + " " + customerList[6].getLastName() + "\nAccount: "
                                  + customerList[6].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[6].getBalance()));
                   if (nameVerifyStr.equals(customerList[7].getFirstName())
                             && pinVerifyStr.equals(customerList[7].getPin())) {
                        textArea.append("\nCustomer: " + customerList[7].getFirstName()
                                  + " " + customerList[7].getLastName() + "\nAccount: "
                                  + customerList[7].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[7].getBalance()));
                   if (nameVerifyStr.equals(customerList[8].getFirstName())
                             && pinVerifyStr.equals(customerList[8].getPin())) {
                        textArea.append("\nCustomer: " + customerList[8].getFirstName()
                                  + " " + customerList[8].getLastName() + "\nAccount: "
                                  + customerList[8].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[8].getBalance()));
                   if (nameVerifyStr.equals(customerList[9].getFirstName())
                             && pinVerifyStr.equals(customerList[9].getPin())) {
                        textArea.append("\nCustomer: " + customerList[9].getFirstName()
                                  + " " + customerList[9].getLastName() + "\nAccount: "
                                  + customerList[9].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[9].getBalance()));
                   textArea.append("\n===========================");
              //if the deposit/withdraw button is pressed, ask how much to deposit or withdraw
              //depending on which radio button is selected
              //Verify the name and pin on the account
              if (sourceObject == depositWithdrawButton) {
                   String nameVerifyStr = JOptionPane
                             .showInputDialog("Firstname on Account: ");
                   String pinVerifyStr = JOptionPane.showInputDialog("Pin Number: ");
                   if (depositRadioButton.isSelected()) {
                        String depositAmountStr = JOptionPane
                                  .showInputDialog("Deposit Amount: ");
                        double depositAmountDouble = Double
                                  .parseDouble(depositAmountStr);
                        if (nameVerifyStr.equals(customerList[0].getFirstName())
                                  && pinVerifyStr.equals(customerList[0].getPin())) {
                             double balanceDouble = customerList[0].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[0].setValues(customerList[0].getFirstName(),
                                       customerList[0].getLastName(), customerList[0]
                                                 .getPin(),
                                       customerList[0].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[0].getFirstName() + " "
                                       + customerList[0].getLastName() + "\nAccount: "
                                       + customerList[0].getAccountType() + "\nPin: "
                                       + customerList[0].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[1].getFirstName())
                                  && pinVerifyStr.equals(customerList[1].getPin())) {
                             double balanceDouble = customerList[1].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[1].setValues(customerList[1].getFirstName(),
                                       customerList[1].getLastName(), customerList[1]
                                                 .getPin(),
                                       customerList[1].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[1].getFirstName() + " "
                                       + customerList[1].getLastName() + "\nAccount: "
                                       + customerList[1].getAccountType() + "\nPin: "
                                       + customerList[1].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[2].getFirstName())
                                  && pinVerifyStr.equals(customerList[2].getPin())) {
                             double balanceDouble = customerList[2].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[2].setValues(customerList[2].getFirstName(),
                                       customerList[2].getLastName(), customerList[2]
                                                 .getPin(),
                                       customerList[2].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[2].getFirstName() + " "
                                       + customerList[2].getLastName() + "\nAccount: "
                                       + customerList[2].getAccountType() + "\nPin: "
                                       + customerList[2].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[3].getFirstName())
                                  && pinVerifyStr.equals(customerList[3].getPin())) {
                             double balanceDouble = customerList[3].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[3].setValues(customerList[3].getFirstName(),
                                       customerList[3].getLastName(), customerList[3]
                                                 .getPin(),
                                       customerList[3].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[3].getFirstName() + " "
                                       + customerList[3].getLastName() + "\nAccount: "
                                       + customerList[3].getAccountType() + "\nPin: "
                                       + customerList[3].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[4].getFirstName())
                                  && pinVerifyStr.equals(customerList[4].getPin())) {
                             double balanceDouble = customerList[4].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[4].setValues(customerList[4].getFirstName(),
                                       customerList[4].getLastName(), customerList[4]
                                                 .getPin(),
                                       customerList[4].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[4].getFirstName() + " "
                                       + customerList[4].getLastName() + "\nAccount: "
                                       + customerList[4].getAccountType() + "\nPin: "
                                       + customerList[4].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[5].getFirstName())
                                  && pinVerifyStr.equals(customerList[5].getPin())) {
                             double balanceDouble = customerList[5].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[5].setValues(customerList[5].getFirstName(),
                                       customerList[5].getLastName(), customerList[5]
                                                 .getPin(),
                                       customerList[5].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[5].getFirstName() + " "
                                       + customerList[5].getLastName() + "\nAccount: "
                                       + customerList[5].getAccountType() + "\nPin: "
                                       + customerList[5].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[6].getFirstName())
                                  && pinVerifyStr.equals(customerList[6].getPin())) {
                             double balanceDouble = customerList[6].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[6].setValues(customerList[6].getFirstName(),
                                       customerList[6].getLastName(), customerList[6]
                                                 .getPin(),
                                       customerList[6].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[6].getFirstName() + " "
                                       + customerList[6].getLastName() + "\nAccount: "
                                       + customerList[6].getAccountType() + "\nPin: "
                                       + customerList[6].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[7].getFirstName())
                                  && pinVerifyStr.equals(customerList[7].getPin())) {
                             double balanceDouble = customerList[7].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[7].setValues(customerList[7].getFirstName(),
                                       customerList[7].getLastName(), customerList[7]
                                                 .getPin(),
                                       customerList[7].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[7].getFirstName() + " "
                                       + customerList[7].getLastName() + "\nAccount: "
                                       + customerList[7].getAccountType() + "\nPin: "
                                       + customerList[7].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[8].getFirstName())
                                  && pinVerifyStr.equals(customerList[8].getPin())) {
                             double balanceDouble = customerList[8].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[8].setValues(customerList[8].getFirstName(),
                                       customerList[8].getLastName(), customerList[8]
                                                 .getPin(),
                                       customerList[8].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[8].getFirstName() + " "
                                       + customerList[8].getLastName() + "\nAccount: "
                                       + customerList[8].getAccountType() + "\nPin: "
                                       + customerList[8].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[9].getFirstName())
                                  && pinVerifyStr.equals(customerList[9].getPin())) {
                             double balanceDouble = customerList[9].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[9].setValues(customerList[9].getFirstName(),
                                       customerList[9].getLastName(), customerList[9]
                                                 .getPin(),
                                       customerList[9].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[9].getFirstName() + " "
                                       + customerList[9].getLastName() + "\nAccount: "
                                       + customerList[9].getAccountType() + "\nPin: "
                                       + customerList[9].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                   if (withdrawRadioButton.isSelected()) {
                        String withdrawAmountStr = JOptionPane
                                  .showInputDialog("Withdraw Amount: ");
                        double withdrawAmountDouble = Double
                                  .parseDouble(withdrawAmountStr);
                        double chargeDouble;
                        if (withdrawAmountDouble > 2000) {
                             chargeDouble = 0.75;
                        } else if (withdrawAmountDouble > 750) {
                             chargeDouble = 0.50;
                        } else {
                             chargeDouble = 0;
                        if (nameVerifyStr.equals(customerList[0].getFirstName())
                                  && pinVerifyStr.equals(customerList[0].getPin())) {
                             double balanceDouble = customerList[0].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[0].setValues(customerList[0].getFirstName(),
                                       customerList[0].getLastName(), customerList[0]
                                                 .getPin(),
                                       customerList[0].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[0].getFirstName() + " "
                                       + customerList[0].getLastName() + "\nAccount: "
                                       + customerList[0].getAccountType() + "\nPin: "
                                       + customerList[0].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[1].getFirstName())
                                  && pinVerifyStr.equals(customerList[1].getPin())) {
                             double balanceDouble = customerList[1].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[1].setValues(customerList[1].getFirstName(),
                                       customerList[1].getLastName(), customerList[1]
                                                 .getPin(),
                                       customerList[1].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[1].getFirstName() + " "
                                       + customerList[1].getLastName() + "\nAccount: "
                                       + customerList[1].getAccountType() + "\nPin: "
                                       + customerList[1].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[2].getFirstName())
                                  && pinVerifyStr.equals(customerList[2].getPin())) {
                             double balanceDouble = customerList[2].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[2].setValues(customerList[2].getFirstName(),
                                       customerList[2].getLastName(), customerList[2]
                                                 .getPin(),
                                       customerList[2].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[2].getFirstName() + " "
                                       + customerList[2].getLastName() + "\nAccount: "
                                       + customerList[2].getAccountType() + "\nPin: "
                                       + customerList[2].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[3].getFirstName())
                                  && pinVerifyStr.equals(customerList[3].getPin())) {
                             double balanceDouble = customerList[3].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[3].setValues(customerList[3].getFirstName(),
                                       customerList[3].getLastName(), customerList[3]
                                                 .getPin(),
                                       customerList[3].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[3].getFirstName() + " "
                                       + customerList[3].getLastName() + "\nAccount: "
                                       + customerList[3].getAccountType() + "\nPin: "
                                       + customerList[3].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[4].getFirstName())
                                  && pinVerifyStr.equals(customerList[4].getPin())) {
                             double balanceDouble = customerList[4].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[4].setValues(customerList[4].getFirstName(),
                                       customerList[4].getLastName(), customerList[4]
                                                 .getPin(),
                                       customerList[4].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[4].getFirstName() + " "
                                       + customerList[4].getLastName() + "\nAccount: "
                                       + customerList[4].getAccountType() + "\nPin: "
                                       + customerList[4].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[5].getFirstName())
                                  && pinVerifyStr.equals(customerList[5].getPin())) {
                             double balanceDouble = customerList[5].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[5].setValues(customerList[5].getFirstName(),
                                       customerList[5].getLastName(), customerList[5]
                                                 .getPin(),
                                       customerList[5].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[5].getFirstName() + " "
                                       + customerList[5].getLastName() + "\nAccount: "
                                       + customerList[5].getAccountType() + "\nPin: "
                                       + customerList[5].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[6].getFirstName())
                                  && pinVerifyStr.equals(customerList[6].getPin())) {
                             double balanceDouble = customerList[6].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[6].setValues(customerList[6].getFirstName(),
                                       customerList[6].getLastName(), customerList[6]
                                                 .getPin(),
                                       customerList[6].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[6].getFirstName() + " "
                                       + customerList[6].getLastName() + "\nAccount: "
                                       + customerList[6].getAccountType() + "\nPin: "
                                       + customerList[6].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[7].getFirstName())
                                  && pinVerifyStr.equals(customerList[7].getPin())) {
                             double balanceDouble = customerList[7].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[7].setValues(customerList[7].getFirstName(),
                                       customerList[7].getLastName(), customerList[7]
                                                 .getPin(),
                                       customerList[7].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[7].getFirstName() + " "
                                       + customerList[7].getLastName() + "\nAccount: "
                                       + customerList[7].getAccountType() + "\nPin: "
                                       + customerList[7].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[8].getFirstName())
                                  && pinVerifyStr.equals(customerList[8].getPin())) {
                             double balanceDouble = customerList[8].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[8].setValues(customerList[8].getFirstName(),
                                       customerList[8].getLastName(), customerList[8]
                                                 .getPin(),
                                       customerList[8].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[8].getFirstName() + " "
                                       + customerList[8].getLastName() + "\nAccount: "
                                       + customerList[8].getAccountType() + "\nPin: "
                                       + customerList[8].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[9].getFirstName())
                                  && pinVerifyStr.equals(customerList[9].getPin())) {
                             double balanceDouble = customerList[9].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[9].setValues(customerList[9].getFirstName(),
                                       customerList[9].getLastName(), customerList[9]
                                                 .getPin(),
                                       customerList[9].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[9].getFirstName() + " "
                                       + customerList[9].getLastName() + "\nAccount: "
                                       + customerList[9].getAccountType() + "\nPin: "
                                       + customerList[9].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
    }Any suggestions would be much appreciated
    - Thanks - GoOsE

    (1) thanks for the wall of code.
    (2) thanks for providing readers with the compilation errors.
    (3) why are you using camelcase for Class names?
    [*READ THIS*|http://mindprod.com/jgloss/abstract.html]
    the errors seem very straight forward to me:
    bankPresentation.java:34: cannot find symbol
    symbol : class bankSummary
    location: class bankPresentation
         bankSummary customerList[] = new bankSummary[10];
         ^
    bankPresentation.java:34: cannot find symbol
    symbol : class bankSummary
    location: class bankPresentation
         bankSummary customerList[] = new bankSummary[10];
         ^
    bankPresentation.java:38: bankPresentation is abstract; cannot be instantiated
              bankPresentation frame = new bankPresentation();
              ^
    bankPresentation.java:103: abstract methods cannot have a body <---- PAY ATTENTION
         abstract void assignArray() {
         ^
    4 errors
    Tool completed with exit code 1

  • NullPointerException on JVM startup when changing Class.getDeclaredField()

    On any JVM starting with 1.5 and later the included test case causes this exception on startup:
    java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:394)
    at java.lang.System.initProperties(Native Method)
    at java.lang.System.initializeSystemClass(System.java:1072)
    The test case involves overriding Class.getDeclaredField() via -Xbootclasspath/p. Originally the bug came out when using Instrumentation.redefineClasses().
    To run the test case:
    1) Download and unzip from [http://ngra.de/gdm-test.zip]
    2) Run "java -cp asm-all-3.1.jar:gdm.jar Install", this will generate a gdm-boot.jar file.
    3) Run "java -Xbootclasspath/p:gdm.jar:gdm-boot.jar Test", this should produce the error.
    The test cases adds one method call before ARETURN instruction in Class. getDeclaredField(). The call is INVOKESTATIC Test.test()V.
    Does anyone know if it's a known bug and if there are any workarounds for this? The same bug manifests in Instrumentation.redefineClasses() by messing up the constant pool when the getDeclaredField() is changed

    Apparently the problem was that in Java 5+ there is a AtomicReferenceFieldUpdaterImpl, which is accessed from System.initializeClass() on JVM startup and which calls Class.getDeclaredField(). Since at that point the proper classloading is not set up yet, trying to access a class outside rt.jar causes a ClassNoDefFoundError cascading upwards to the NPE we get. The fix is to check the sun.misc.VM.isBooted() flag to be sure that class loading is allowed, otherwise skipping the injected code. Hope this can help someone :)

Maybe you are looking for