Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: error: array dimension missing x 2. Any help?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default error: array dimension missing x 2. Any help?

    Hi there. I'm getting two errors on this code and it won't run.

    Is there anything I'm doing wrong?

    I've highlighted them with arrows.

    import javax.swing.JOptionPane;
    import javax.swing.JTextArea;
     
    public class StorageApp {
     
    	private StorageAppEntry entry[];
        private int counter;
        private String SName;
        private int notfound = 0;
     
        public static void main(String[] args) {
     
        StorageApp a = new StorageApp();
     ---------->       a.entry = new StorageAppEntry[];
            int option = 0;
            try {
                while (option != 5) {
     
                	String content = "Choose an Option\n\n"
                            + "[1] Add an Entry\n"
                            + "[2] Delete an Entry\n"
                            + "[3] Update an Entry\n"
                            + "[4] View all Entries\n"
                            + "[5] View Specific Entry\n"
                            + "[6] Exit";
     
                            option = Integer.parseInt(JOptionPane.showInputDialog(content));
                    switch (option) {
                        case 1:
                            a.addEntry();
                            break;
                        case 2:
                            a.deleteEntry();
                            break;
                        case 3:
                            a.editEntry();
                            break;
                        case 4:
                            a.viewAll();
                            break;
                        case 5:
                            a.searchEntry();
                            break;
                        case 6:
                            System.exit(1);
                            break;
                        default:
                            JOptionPane.showMessageDialog(null, "Invalid Choice!");
                    }
               }
            }catch(NumberFormatException e){
                JOptionPane.showMessageDialog(null, "Please Choose a Number in the displayed Menu");
            }
        }
     
       public void addEntry() {
            entry[counter] = new StorageAppEntry[100];
            entry[counter].setName(JOptionPane.showInputDialog("Enter name: "));
            entry[counter].setUsername(JOptionPane.showInputDialog("Enter username: "));
            entry[counter].setPassword(JOptionPane.showInputDialog("Enter password: "));
            entry[counter].setdescription(JOptionPane.showInputDialog("Enter description: "));
            counter++;
        }
     
        public void viewAll() {
            String addText = "  NAME\tUSERNAME\tPASSWORD\tDESCRIPTION\n\n";
            int nonNull = 0;
            for (int i = 0; i < entry.length; i++) {
                if (entry[i] != null) {
                    addText = addText + entry[i].getInfo() + "\n";
                    nonNull++;
                }
                else if (nonNull == counter) {
                    break;
                }
            }
            JOptionPane.showMessageDialog(null, new JTextArea(addText));
        }
     
     
     
         public void searchEntry() {
            SName = JOptionPane.showInputDialog("Enter Name to find: ");
            searchMethod();
        }
     
         public void searchMethod() {
            for (int i = 0; i < counter; i++) {
                if (entry[i].getName().equals(SName)) {
                    JOptionPane.showMessageDialog(null, entry[i].getInfo2());
                    notfound = 0;
                    break;
                } else {
                    notfound++;
                }
            }
            if (notfound != 0) {
                JOptionPane.showMessageDialog(null, "Name Not Found!");
            }
        }
     
         public void editEntry() {
            SName = JOptionPane.showInputDialog("Enter Name to edit: ");
            for (int i = 0; i < counter; i++) {
                if (entry[i].getName().equals(SName)) {
     ----------->               entry[i] = new StorageAppEntry[];
                    entry[i].setName(JOptionPane.showInputDialog("Enter new name: "));
                    entry[i].setUsername(JOptionPane.showInputDialog("Enter new username: "));
                    entry[i].setDescription(JOptionPane.showInputDialog("Enter new description: "));
                    notfound = 0;
                    break;
                } else {
                    notfound++;
                }
            }
            if (notfound != 0) {
                JOptionPane.showMessageDialog(null, "Name Not Found!");
            }
        }
     
      public void deleteEntry() {
            SName = JOptionPane.showInputDialog("Enter Name to delete: ");
            for (int i = 0; i < counter; i++) {
                if (entry[i].getName().equals(SName)) {
                    JOptionPane.showMessageDialog(null, "Found!");
                    entry[i] = null;
                    break;
                }
            }
        }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,723
    Thanks
    45
    Thanked 1,974 Times in 1,948 Posts

    Default Re: error: array dimension missing x 2. Any help?

    I'm getting two errors on this code
    Please copy and paste here the full text of the error messages.

    You need to tell the compiler the size of the array you are trying to create.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error: array dimension missing x 2. Any help?

    Quote Originally Posted by Norm View Post
    Please copy and paste here the full text of the error messages.
    --------------------Configuration: StorageApp - JDK version 1.7.0_05 <Default> - <Default>--------------------
    C:\Users\OH\Documents\JCreator Pro\MyProjects\passwordOH\StorageApp\src\StorageAp p.java:14: error: array dimension missing
    a.entry = new StorageAppEntry[];
    ^
    C:\Users\OH\Documents\JCreator Pro\MyProjects\passwordOH\StorageApp\src\StorageAp p.java:106: error: array dimension missing
    entry[i] = new StorageAppEntry[];
    ^
    2 errors

    Process completed.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,723
    Thanks
    45
    Thanked 1,974 Times in 1,948 Posts

    Default Re: error: array dimension missing x 2. Any help?

    error: array dimension missing
    That seems a very clear message. You need to tell the compiler the size of the array you are trying to create.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error: array dimension missing x 2. Any help?

    Gotcha.

    I've changed both errors to StorageAppEntry[100].

    But since doing that I have 4 errors:

    --------------------Configuration: StorageApp - JDK version 1.7.0_05 <Default> - <Default>--------------------
    C:\Users\OH\Documents\JCreator Pro\MyProjects\passwordOH\StorageApp\src\StorageAp p.java:6: error: cannot find symbol
    private StorageAppEntry entry[];
    ^
    symbol: class StorageAppEntry
    location: class StorageApp
    C:\Users\OH\Documents\JCreator Pro\MyProjects\passwordOH\StorageApp\src\StorageAp p.java:14: error: cannot find symbol
    a.entry = new StorageAppEntry[100];
    ^
    symbol: class StorageAppEntry
    location: class StorageApp
    C:\Users\OH\Documents\JCreator Pro\MyProjects\passwordOH\StorageApp\src\StorageAp p.java:57: error: cannot find symbol
    entry[counter] = new StorageAppEntry[100];
    ^
    symbol: class StorageAppEntry
    location: class StorageApp
    C:\Users\OH\Documents\JCreator Pro\MyProjects\passwordOH\StorageApp\src\StorageAp p.java:106: error: cannot find symbol
    entry[i] = new StorageAppEntry[100];
    ^
    symbol: class StorageAppEntry
    location: class StorageApp

    4 errors

    Process completed.


  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,723
    Thanks
    45
    Thanked 1,974 Times in 1,948 Posts

    Default Re: error: array dimension missing x 2. Any help?

    error: cannot find symbol
    private StorageAppEntry entry[];
    ^
    symbol: class StorageAppEntry
    Where is the definition for the class: StorageAppEntry? The compiler can not find the class's definition.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error: array dimension missing x 2. Any help?

    I wish I knew where to find that Norm. To me it's a head scratcher...

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,723
    Thanks
    45
    Thanked 1,974 Times in 1,948 Posts

    Default Re: error: array dimension missing x 2. Any help?

    I wish I knew where to find that
    Ask the person that wrote the code why that code is there and if it is needed, where to get the definition for the class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Missing elements in array
    By frozen java in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 10th, 2012, 10:52 PM
  2. [SOLVED] How to declare an object of multi-dimension array?
    By FongChengWeng in forum Collections and Generics
    Replies: 7
    Last Post: January 14th, 2011, 12:17 AM
  3. Multi-dimension ArrayList example
    By adeola in forum Collections and Generics
    Replies: 3
    Last Post: March 26th, 2010, 03:23 AM
  4. Multi-dimension ArrayList example
    By helloworld922 in forum Java Programming Tutorials
    Replies: 1
    Last Post: February 3rd, 2010, 10:01 AM
  5. slicer dimension in MDX
    By retail_deepa in forum Java Servlet
    Replies: 3
    Last Post: August 28th, 2009, 04:01 AM