Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I couldn't use the Loop Statements in the JComboBox block,why?  RSS feed

 
Ronyn Woods
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String[] ComputerComps;
for (int i=1;i<10 ;i++ )
{
ComputerComps[i] =new Integer(i);
}
JComboBox cbox = new JComboBox(ComputerComps);
then system says:
JComboBox.java:31: Type expected.
for (...)
^
regards,
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off... you are going to have problems if you don't instantiate your array...


Secondly... your loop starts at 1 and ends at 9... arrays are numbered starting at 0... so the first element of your array is going to always be null.

Third... you are assigning an Integer to a String... this can't be done directly... you would have to do something like...


Fourth... it looks like your class file is named JComboBox... at least according to the error message that you posted... it is a bad idea to name your classes after classes that already exist in the Java APIs... name conflicts will occur...

I don't know if this will help you solve the error you are posting about, but hopefully it will help get your code running... in the future, please post all the code to your class unless it is too enourmous, and please use the UBB code tags ( for an explaination of code tags and other UBB tags, just click here for a rundown on them... )

HTH,
-Nate
[This message has been edited by Nathan Pruett (edited June 01, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!