Results 1 to 3 of 3
  1. #1
    zlloyd1 is offline Member
    Join Date
    Nov 2012
    Posts
    57
    Rep Power
    0

    Question Class expected error with array

    I am doing what should be a simple program in Java to populate a combobox with array values, but it won't compile....
    Here is the code I have so far:
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class Box extends JFrame{
    private JComboBox box;
    private JLabel pic;
    
    int[] stuff = new int[7];
    public static void getvalue(in[] array){
    for (int i = 0; int<array.length; i++){
    array[i] = i;}}
    
    public Box(){
    super("title");
    setLayout(new FlowLayout());
    box = new JComboBox(stuff);}}
    Unfortunately, when I try to compile this in the command prompt I get the following error:
    "arraybox.java:10: error: .class' expected
    for<int i = 0; int<array.length; i++){
    1 erro
    r"
    Can anyone please tell me what I am doing wrong here??

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Class expected error with array

    The error said to you clearly that you have error in line 10, which is the for-loop expression. It should be easy to spot.

  3. #3
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default Re: Class expected error with array

    Please see my comments in the code below:

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    
    public class Box extends JFrame{
    	
    	private JComboBox box;
    	private JLabel pic;
    	
    	private static Integer[] getArray(){ // <<<< change "in" to be "int"
    		Integer[] array = new Integer[7]; // "int" is a primitive.  What you need here is an array of Objects like Integer
    		for (int i = 0; i<array.length; i++){ // <<< change "int" to be "i"
    			array[i] = i;
    		}
    		return array;
    	}
    
    	public Box(){
    		super("title");
    		setLayout(new FlowLayout());
    		box = new JComboBox(getArray()); // <<<< we want to call getArray() and have it return the array with filled in data
    		add(box); // <<<< add box to the window
    		setSize(500,500); // <<<< set the size of the window
    		setVisible(true); // <<<<< you have to make the JFrame visible
    	}
    	
    	public static void main(String[] args) { // <<< you need a main() method
    		new Box();
    	}
    	
    }

Similar Threads

  1. class interface or enum expected Imports java.io.*; error
    By prathamkool in forum New To Java
    Replies: 2
    Last Post: 10-02-2011, 04:53 PM
  2. Error: '.class' expected
    By Jill in forum New To Java
    Replies: 5
    Last Post: 07-18-2011, 01:45 PM
  3. Replies: 2
    Last Post: 10-02-2010, 02:13 AM
  4. Class Expected error
    By Radman23 in forum New To Java
    Replies: 11
    Last Post: 01-14-2009, 04:12 AM

Tags for this Thread

Posting Permissions

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