[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Illegal Start of Expression

Posted on 2006-03-22
10
Medium Priority
?
406 Views
Last Modified: 2008-02-01
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();
            }
      }
0
Comment
Question by:redcoder
  • 5
  • 2
  • 2
  • +1
10 Comments
 

Author Comment

by:redcoder
ID: 16263143
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};
0
 
LVL 14

Accepted Solution

by:
StillUnAware earned 1600 total points
ID: 16263312
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;
0
 

Author Comment

by:redcoder
ID: 16263362
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;            
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:StillUnAware
ID: 16263443
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.
0
 

Author Comment

by:redcoder
ID: 16263507
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);
0
 
LVL 92

Expert Comment

by:objects
ID: 16263524
try:

for (int i=0; i<table.length; i++) append(table[i]);
0
 

Author Comment

by:redcoder
ID: 16263544
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)
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 16263613
looks like maybe questNum is invalid id
0
 
LVL 13

Expert Comment

by:Kelvin_King
ID: 16264242
what does your append function look like ?

Or are you using StringBuffer.append ?
0
 

Author Comment

by:redcoder
ID: 16264402
No, I didn't use any stringbuffer..


objects is right.

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

thx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month20 days, 1 hour left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question