Illegal Start of Expression

What is wrong with this code ? It tells me : Illegal Start of Expression..  :-|

import javax.microedition.lcdui.*;
import java.io.IOException;

public class PlayScreen extends Form implements CommandListener
{
      private Command okCommand;
      private String[] myChoice;
      private Display display;
      private String recStore;
      private ChoiceGroup answerChoices ;
      private String question = null;
      private String[] table;
      private String str1,str2,str3,str4;

      
      
      public PlayScreen(int questNum)
      {
            
            super("Millionaire Game");
            try
            {
                  
                  okCommand = new Command("OK", Command.OK,0);
                  
                  //add OK at soft button
                  addCommand(okCommand);
                  
                  setCommandListener(this);
                  
                  
                  //retrieve one record from record store
                  recStore = Millionaire.pd.getOneRecord(questNum);
            //      append(recStore);
                  
                  //retrieve question from record store
                  question = Millionaire.pd.getQuestion(recStore);
                  append(question);
                  
                  //retrieve choice selection from record store
                  str1 = Millionaire.pd.getChoice1(recStore);
                  str2 = Millionaire.pd.getChoice2(recStore);
                  str3 = Millionaire.pd.getChoice3(recStore);
                  str4 = Millionaire.pd.getChoice4(recStore);

                  table = {str1,str2,str3,str4};
                  answerChoices = new ChoiceGroup("AaAa", ChoiceGroup.EXCLUSIVE, table, null);
            append(answerChoices);
                  
                  
                  
            }
            catch (Exception e)
            {
                  e.printStackTrace();
            }
      }
redcoderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

redcoderAuthor Commented:
This is the whole message I got:

C:\WTK22\apps\Millionaire(2)\src\PlayScreen.java:49: illegal start of expression
                  table = {str1,str2,str3,str4};
StillUnAwareCommented:
You could initialize table thst only when declaring it:

String[] table = {str1,str2,str3,str4};

but in this case You'll have to assign every items to its corresponding values:

table[0] = str1;
table[1] = str2;
table[2] = str3;
table[3] = str4;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
redcoderAuthor Commented:
for(int i=1 ; i <=4; i++)
{
choices[i] = str+""+i;
}
      
I try use for loop but could figure out how to arrange i=1,2,3,4 to str;            
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

StillUnAwareCommented:
You can not convert any object to represent local variables name

str+""+1  will never be the variable  str1

You could do something like that:

String arr = {str1,str2,str3,str4};
table = arr;
arr = null;

but this is only unneeded resource usage on the mobile device.
redcoderAuthor Commented:
ALright then i rather use your method above.
table[0] = str1;
table[1] = str2;
table[2] = str3;
table[3] = str4;


But I couldn't append the table using :

append(table);
Mick BarryJava DeveloperCommented:
try:

for (int i=0; i<table.length; i++) append(table[i]);
redcoderAuthor Commented:
Receive this error:

javax.microedition.rms.InvalidRecordIDException
      at javax.microedition.rms.RecordStore.findRecord(+18)
      at javax.microedition.rms.RecordStore.getRecord(+22)
      at PersistantData.getOneRecord(+31)
      at PlayScreen.<init>(+52)
      at Millionaire.commandAction(+31)
      at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
      at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
      at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
      at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
      at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(+45)
      at PersistantData.parse(+81)
      at PersistantData.getQuestion(+5)
      at PlayScreen.<init>(+66)
      at Millionaire.commandAction(+31)
      at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
      at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
      at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
      at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
      at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
Mick BarryJava DeveloperCommented:
looks like maybe questNum is invalid id
Kelvin_KingCommented:
what does your append function look like ?

Or are you using StringBuffer.append ?
redcoderAuthor Commented:
No, I didn't use any stringbuffer..


objects is right.

The problem comes from questNum.  
I have fixed it..

thx
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.