Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run .lang package in J2ME

 
umm-e- laila
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code is here...


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.lang.*;
public class QuizMaster extends MIDlet implements CommandListener
{
int a,b,choice;
int[] arr=new int[11];
private Display display;
private List list;
private Ticker ticker;
private Command exit;
private Command submit;
public QuizMaster()
{
display=Display.getDisplay(this);

exit=new Command("Exit",Command.SCREEN,1);
submit=new Command("Submit",Command.SCREEN,1);

ticker=new Ticker("QUIZ MASTER");

list=new List("ANSWER",Choice.IMPLICIT);
list.append("FAHAD",null);
list.append("FBI",null);
list.addCommand(exit);
list.setCommandListener(this);
list.setTicker(ticker);
}

public void startApp()
{
display.setCurrent(list);

for(a=1;a<=10
{
choice=(Math.random()*14+1);

for(b=1;b<=10;b++)
{
if(choice==arr[b])
{
break;
}
}

if(b==11)
{
arr[a]=choice;//switch

a++;
}
else
{
continue;
}
}
}

public void pauseApp()
{
}

public void destroyApp(boolean unconditional)
{
}

public void commandAction(Command c,Displayable s)
{
if(c==exit)
{
destroyApp(true);
notifyDestroyed();
}
}
}

i m getting this error

Project settings saved

Building "Qm"

C:\WTK21\apps\Qm\src\QuizMaster.java:37: cannot resolve symbol

symbol : method random ()

location: class java.lang.Math

choice=(Math.random()*14+1);

^

1 error

com.sun.kvem.ktools.ExecutionException

Build failed


if somebody knows how can i run it then plz reply me as soon as possible.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The .lang classes for J2ME is a smaller subset of the full J2SE. The Math class is one of them, since MIDP 1.0 did not have support for floating points, methods of the Math classes were removed. random() was one such method. I think it might be back in for MIDP 2.0, but I don't have the API completely memorized.

Nope, just checked Mr. Knudsen's book and there is no random method in the Math class for J2ME. Sorry.

Mark
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
I think WTK 2.1 supports MIDP 2.0 and the original poster is using WTK 2.1... So it should be able to compile... Or is he choosing MIDP 1.0 as its profile, when he created the project?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic