redcoder
asked on
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.getOneRecor d(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();
}
}
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.getOneRecor
// append(recStore);
//retrieve question from record store
question = Millionaire.pd.getQuestion
append(question);
//retrieve choice selection from record store
str1 = Millionaire.pd.getChoice1(
str2 = Millionaire.pd.getChoice2(
str3 = Millionaire.pd.getChoice3(
str4 = Millionaire.pd.getChoice4(
table = {str1,str2,str3,str4};
answerChoices = new ChoiceGroup("AaAa", ChoiceGroup.EXCLUSIVE, table, null);
append(answerChoices);
}
catch (Exception e)
{
e.printStackTrace();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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;
{
choices[i] = str+""+i;
}
I try use for loop but could figure out how to arrange i=1,2,3,4 to str;
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.
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.
ASKER
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);
table[0] = str1;
table[1] = str2;
table[2] = str3;
table[3] = str4;
But I couldn't append the table using :
append(table);
try:
for (int i=0; i<table.length; i++) append(table[i]);
for (int i=0; i<table.length; i++) append(table[i]);
ASKER
Receive this error:
javax.microedition.rms.Inv alidRecord IDExceptio n
at javax.microedition.rms.Rec ordStore.f indRecord( +18)
at javax.microedition.rms.Rec ordStore.g etRecord(+ 22)
at PersistantData.getOneRecor d(+31)
at PlayScreen.<init>(+52)
at Millionaire.commandAction( +31)
at javax.microedition.lcdui.D isplay$Dis playAccess or.command Action(+28 2)
at javax.microedition.lcdui.D isplay$Dis playManage rImpl.comm andAction( +10)
at com.sun.midp.lcdui.Default EventHandl er.command Event(+68)
at com.sun.midp.lcdui.Automat edEventHan dler.comma ndEvent(+4 7)
at com.sun.midp.lcdui.Default EventHandl er$QueuedE ventHandle r.run(+250 )
java.lang.StringIndexOutOf BoundsExce ption: 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.D isplay$Dis playAccess or.command Action(+28 2)
at javax.microedition.lcdui.D isplay$Dis playManage rImpl.comm andAction( +10)
at com.sun.midp.lcdui.Default EventHandl er.command Event(+68)
at com.sun.midp.lcdui.Automat edEventHan dler.comma ndEvent(+4 7)
at com.sun.midp.lcdui.Default EventHandl er$QueuedE ventHandle r.run(+250 )
javax.microedition.rms.Inv
at javax.microedition.rms.Rec
at javax.microedition.rms.Rec
at PersistantData.getOneRecor
at PlayScreen.<init>(+52)
at Millionaire.commandAction(
at javax.microedition.lcdui.D
at javax.microedition.lcdui.D
at com.sun.midp.lcdui.Default
at com.sun.midp.lcdui.Automat
at com.sun.midp.lcdui.Default
java.lang.StringIndexOutOf
at java.lang.String.substring
at PersistantData.parse(+81)
at PersistantData.getQuestion
at PlayScreen.<init>(+66)
at Millionaire.commandAction(
at javax.microedition.lcdui.D
at javax.microedition.lcdui.D
at com.sun.midp.lcdui.Default
at com.sun.midp.lcdui.Automat
at com.sun.midp.lcdui.Default
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what does your append function look like ?
Or are you using StringBuffer.append ?
Or are you using StringBuffer.append ?
ASKER
No, I didn't use any stringbuffer..
objects is right.
The problem comes from questNum.
I have fixed it..
thx
objects is right.
The problem comes from questNum.
I have fixed it..
thx
ASKER
C:\WTK22\apps\Millionaire(
table = {str1,str2,str3,str4};