This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Product and Other Certifications and the fly likes How to run .lang package in J2ME Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "How to run .lang package in J2ME" Watch "How to run .lang package in J2ME" New topic
Author

How to run .lang package in J2ME

umm-e- laila
Greenhorn

Joined: Apr 28, 2004
Posts: 1
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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?


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
 
Don't get me started about those stupid light bulbs.
 
subject: How to run .lang package in J2ME