System.getProperty( "com.nokia.mid.imei" ) return null ?!?!
hello guys,
i intend to get the IMEI No. i wrote the following code:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class IMEIDemo extends MIDlet
Display display;
private Form mainForm;
String imeiNokia = "";
public void startApp()
display = Display.getDisplay( this );
mainForm = new Form( "IMEI Demo" );
imeiNokia = System.getProperty( "com.nokia.mid.imei" );
if( imeiNokia.compareTo( "" ) == 0 )
System.out.println( "NULL..." );
else
mainForm.append( imeiNokia );
display.setCurrent( mainForm );
public void pauseApp()
public void destroyApp( boolean b )
destroyApp( false );
notifyDestroyed();
} // IMEIDemoi am using WTK2.2, MIDP2, CLDC1.1
when i run this code in emulator (WToolKit), i got the following Exception:
startApp threw an Exception
java.lang.NullPointerException
java.lang.NullPointerException
at IMEIDemo.startApp(+36)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
at com.sun.midp.midlet.Scheduler.schedule(+270)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+116)
would u pls suggest me how can i overcome this problem or any effective openion?
thanx in advance.
take care all.
bye.
hi
i tried this program using J2ME to retireve IMEI number
* IMEINO.java
* Created on February 19, 2007, 3:50 PM
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
* @author Administrator
* @version
public class IMEINO extends MIDlet implements CommandListener{
public TextField t1,t2,t3;
public Form form;
public String s1,s2,s3,n=null;
public Display disp;
public Command ok,exit;
public IMEINO()
form = new Form("IMEI");
t1 = new TextField("imei1","",50,TextField.ANY);
t2 = new TextField("imei2","",50,TextField.ANY);
t3 = new TextField("imei3","",50,TextField.ANY);
ok = new Command("ok",Command.OK,1);
exit = new Command("exit",Command.EXIT,2);
public void startApp() {
form.addCommand(ok);
form.setCommandListener(this);
form.addCommand(exit);
form.setCommandListener(this);
form.append(t1);
form.append(t2);
form.append(t3);
Display disp = Display.getDisplay(this);
try
s1 = System.getProperty("com.nokia.mid.imei");
s2 = System.getProperty("phone.imei");
s3 = System.getProperty("com.nokia.IMEI");
if(s1.compareTo("") == 0 || s2.compareTo("")==0 || s3.compareTo("")==0 )
t1.setString(null);
else
t1.setString(s1);
t2.setString(s2);
t3.setString(s3);
catch(Exception e)
t1.setString("error"+ e.getMessage());
t2.setString(s2);
t3.setString(s3);
disp.setCurrent(form);
public void commandAction(Command c,Displayable d)
if(c==ok)
destroyApp(true);
notifyDestroyed();
if(c == exit)
destroyApp(true);
notifyDestroyed();
public void pauseApp() {
public void destroyApp(boolean unconditional) {
i tried this program , when i run in the netbeans environment , it shows null (system.out.println(imei)),when i installed the jar file into nokia 3230 mobile,the textfield is null , it shows nothing,can anyone give me any suggestion , whether i have to change my phone settings
Message was edited by:
scorpianalways
Similar Messages
-
Hello everybody,
I'm using JCAPS 6 but I have to follow a guideline of projects implemented with JCAPS 5.1.3.
The project for example, has written for the logs-directory in method user initialize this code:
// JCAPS uses JVM version 1.5
logger.info( "--- BEGIN ------ JCAPS userInitialize" );
String currRoot = System.getProperty( "com.stc.application.dataroot" );
String log4j_props = currRoot + "/../../NameDirectory/" + collabContext.getProjectPath() + "/" +
collabContext.getCollaborationName() + "_log4j.properties";
With JCAPS 6 I don't know how to substitute "System.getProperty( "com.stc.application.dataroot" );" because with it don't function.
Somebody can help me?
Thanx!
FabrizioThis is the correct code:
// JCAPS uses JVM version 1.5
logger.info( "--- BEGIN ------ JCAPS userInitialize" );
String currRoot = System.getProperty( "com.stc.application.dataroot" );
String log4j_props = currRoot + "/../../NoemaLife/" + collabContext.getProjectPath() + "/" + collabContext.getCollaborationName() + "_log4j.properties";
but I have the same problem... -
Dear frnds
I am very new to java. I trieds to turn off my back light using setLights function. But in my Netbeans IDE 4.1 (with mobility 1.4.2 and nokia sdk 2.0) I am not able to import the class com.nokia.mid.ui.DeviceControl. Even I don't know from where netbeans include its classes. From 2 days I checked everything and even moved some libs(zip files) to another place. but still netbeans is compiling MIDP helloworld example. I am trying to import DeviceControl class in midp helloworldplus example. But IDE's error "com.nokia.mid.ui package not found" is irritating me.
Please HElp
SunnyDear frnds
I am very new to java. I trieds to turn off my back light using setLights function. But in my Netbeans IDE 4.1 (with mobility 1.4.2 and nokia sdk 2.0) I am not able to import the class com.nokia.mid.ui.DeviceControl. Even I don't know from where netbeans include its classes. From 2 days I checked everything and even moved some libs(zip files) to another place. but still netbeans is compiling MIDP helloworld example. I am trying to import DeviceControl class in midp helloworldplus example. But IDE's error "com.nokia.mid.ui package not found" is irritating me.
Please HElp
Sunny -
System.getProperty("os.arch") in webstart returns "x86" on amd64 machine
Hello,
I am really in big trouble. I want to detect the architecture so that I can load the correct library. When I am running from the command line the architecture is detected properly but in webstart it always return x86 even though I am running from amd64 or ia64.
I hope someone can help. Or, if you have any ways to detect the architecture is also fine.Problem is that currently there is no 64 bit implementation of Java Web Start, so you can't run any application in 64 bit mode, since you can't mix 32 and 64 bit binaries in the same process.
When 64 bit support is finally added, it will return seperate os.arch values depending on if you are running a 32 or 64 bit process, and seperate os.arch attributes in the jnlp file will allow you to load seperate libraries depending on what processor mode you are running.
/Andy -
Getting cell id in java me using System.getProperty
Hi all
I wish to get the cell id of the cell (I know it had been asked for more than a million times) that my nokia phone is currently connected to with the api listed here
[http://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME|http://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME]
As stated,
System.getProperty("com.nokia.mid.cellid") works on S60 3rd Ed
System.getProperty("Cell-ID") works on S40 3rd Ed
However, I am unable to do so on N82, anyone have any idea why is that so?
Or is there any kind soul with N95 can tell me whether it works on N95?yes.. I saw that thread before I posted this.. but the piece of code mentioned in the thread does not make use of the api listed in the wiki right?
In fact, I'm not very clear as to what that mentioned code is doing.
Moreover, my point would be, how come the api is listed in the wiki in that case.. that is, if it does not work.. :/ -
System.getProperty(String key) keys.
HI All
Anyone can tell me, what key I must use for getting devise IMEI on Nokia 7610 or any other Nokia, I have tried evry combinations on my phone, like "com.nokia.mid.imei", "com.nokia.phone.imei" etc..
Please help me
Thank you.
P.S.
If there are any other ways to know about my question please write me.have you search on nokia forums and in this forum(use top right field to search)?
i'm sure that it has been ever asked and answered... -
Java 7 u45 System.getProperty returns null
After upgrade to u45, our web launch application stopped working. it failed at System.getProperty("myproperty").
"myproperty" is defined as a
<resources>
<j2se version="1.6+" initial-heap-size="64m" max-heap-size="256m"/>
<jar href="nms_wsclient.jar" download="eager" main="true"/>
<jar href="commons-httpclient.jar" download="eager"/>
<jar href="commons-codec.jar" download="eager"/>
<jar href="commons-logging.jar" download="eager"/>
<jar href="log4j.jar" download="eager"/>
<property name="myproperty" value="http://138.120.128.94:8085/"/>
</resources>
with older version java ,System.getProperty("myproperty") works fine to return the value, but with u45 it returned null.
Does anyone have the same problem? any idea how to fix it or work around it?
Thanks,
ZhongyaoSo did you succeed with the jnlp template ?
After frustrating hours of that information useless JNLPSigningException trial & error, It seems that as :
1. You can't make the j2se version variable
2. You can't have your own variable property/values
I've opened a bug report...
The documentation is atrocious, with a vague "we reserve the right to blacklist variable elements, but we will never say which ones".
The JNLP example in the various example is a joke - Its a hello world jnlp, not a real world one.
The JNLPSigningException must have been written my the same guys at Microsoft that did the "An Unknown Error As Occurred".
I've had to clear the cache at every test, seems that the JNLP Template check didn't get the new updated JNLP from the web server.
/rant over
I think I'll try to bypass that JNLP property mess and get javaws to download my own "jnlp name".xml.config... -
FrameGrabbingControl returns null
In my code i want to grab a frame from a video and displey it in another window.But the problem is that " FrameGrabbingControl fgc =(FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");" returns null.Please help me by pionting out the error. Thanks in advance.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.lang.Thread;
import java.util.*;
import java.lang.*;
import java.lang.String;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import java.util.Properties;
import javax.media.*;
import java.applet.*;
import javax.swing. *;
import javax.swing.border. *;
import javax.media.datasink. *;
import javax.media.format. *;
import javax.media.protocol. *;
import javax.media.util. *;
import javax.media.control. *;
import java.awt.image. *;
import com.sun.image.codec.jpeg. *;
import com.sun.media.protocol.vfw.VFWCapture;
import java.io.*;
import javax.media.control.FrameGrabbingControl;
//import com.sun.media.util.JMFSecurity;
* This is a Java Applet that demonstrates how to create a simple
* media player with a media event listener. It will play the
* media clip right away and continuously loop.
* <!-- Sample HTML
* <applet code=SimplePlayerApplet width=320 height=300>
* <param name=file value="sun.avi">
* </applet>
* -->
public class grabframe extends Applet implements ControllerListener,ActionListener
static int shotCounter = 1;
Button button;
// media Player
Player player = null;
// component in which video is playing
Component visualComponent = null;
// controls gain, position, start, stop
Component controlComponent = null;
// displays progress during download
Component progressBar = null;
boolean firstTime = true;
long CachingSize = 0L;
Panel panel = null;
int controlPanelHeight = 0;
int videoWidth = 0;
int videoHeight = 0;
* Read the applet file parameter and create the media
* player.
public void init()
setLayout(new BorderLayout());
setBackground(Color.white);
panel = new Panel();
//panel.setLayout( null );
add(panel,BorderLayout.SOUTH);
panel.setBounds(0, 0, 320, 240);
button=new Button("GRAB FRAME");
panel.add(button);
button.addActionListener(this);
// input file name from html param
String mediaFile = null;
// URL for our media file
MediaLocator mrl = null;//MediaLocator describes the location of the media content while
URL url = null;//URL specify the location of the media
// Get the media filename info.
// The applet tag should contain the path to the
// source media file, relative to the html page.
if ((mediaFile = getParameter("file")) == null)
Fatal("Invalid media file parameter");
//System.out.println("mediafile :"+mediaFile);
try
url = new URL(getDocumentBase(), mediaFile);//return a new URL using an existing URL as reference
// System.out.println("url :"+url);
mediaFile = url.toExternalForm();//return a string representation of the URL
// System.out.println("mediafile :"+mediaFile);
catch (MalformedURLException mue)
try
// Create a media locator from the file name
if ((mrl = new MediaLocator(mediaFile)) == null)
Fatal("Can't build URL for " + mediaFile);
// Create an instance of a player for this media
try
player = Manager.createPlayer(mrl);
catch (NoPlayerException e)
System.out.println(e);
Fatal("Could not create player for " + mrl);
/* catch (CannotRealizeException e)
System.out.println(e);
Fatal("Could not create player for " + mrl);
// Add ourselves as a listener for a player's events
player.addControllerListener(this);
catch (MalformedURLException e)
Fatal("Invalid media file URL!");
catch (IOException e)
Fatal("IO exception creating player for " + mrl);
// This applet assumes that its start() calls
// player.start(). This causes the player to become
// realized. Once realized, the applet will get
// the visual and control panel components and add
// them to the Applet. These components are not added
// during init() because they are long operations that
// would make us appear unresposive to the user.
}//end of init
* Start media file playback. This function is called the
* first time that the Applet runs and every
* time the user re-enters the page.
public void start()
//$ System.out.println("Applet.start() is called");
// Call start() to prefetch and start the player.
if (player != null)
player.start();
* Stop media file playback and release resource before
* leaving the page.
public void stop()
//$ System.out.println("Applet.stop() is called");
if (player != null)
player.stop();
player.deallocate();
public void destroy()
//$ System.out.println("Applet.destroy() is called");
player.close();
* This controllerUpdate function must be defined in order to
* implement a ControllerListener interface. This
* function will be called whenever there is a media event
public synchronized void controllerUpdate(ControllerEvent event)
// If we're getting messages from a dead player,
// just leave
if (player == null)
return;
// When the player is Realized, get the visual
// and control components and add them to the Applet
if (event instanceof RealizeCompleteEvent)
if (progressBar != null)
panel.remove(progressBar);
progressBar = null;
int width = 320;
int height = 0;
if (controlComponent == null)
if (( controlComponent = player.getControlPanelComponent()) != null)
//controlPanelComponent provides the default user interface for controlling the player
controlPanelHeight = controlComponent.getPreferredSize().height;
panel.add(controlComponent);
height += controlPanelHeight;
if (visualComponent == null)
if (( visualComponent = player.getVisualComponent())!= null)
//visualComponent provides display component(where the visual media is recorded) of the player
panel.add(visualComponent,BorderLayout.CENTER);
Dimension videoSize = visualComponent.getPreferredSize();
videoWidth = videoSize.width;
videoHeight = videoSize.height;
width = videoWidth;
height += videoHeight;
visualComponent.setBounds(0, 0, videoWidth, videoHeight);
panel.setBounds(0, 0, width, height);
if (controlComponent != null)
controlComponent.setBounds(0, videoHeight,width, controlPanelHeight);
controlComponent.invalidate();
} //end of RearizedCompleteEvent
else if (event instanceof CachingControlEvent)
if (player.getState() > Controller.Realizing)
return;
// Put a progress bar up when downloading starts,
// take it down when downloading ends.
CachingControlEvent e = (CachingControlEvent) event;
CachingControl cc = e.getCachingControl();
// Add the bar if not already there ...
if (progressBar == null)
if ((progressBar = cc.getControlComponent()) != null)
panel.add(progressBar);
panel.setSize(progressBar.getPreferredSize());
validate();
} //end of CashingControlEvent
else if (event instanceof EndOfMediaEvent)
// We've reached the end of the media; rewind and
// start over
player.setMediaTime(new Time(0));
player.start();
} //end of EndOfMediaEvent
else if (event instanceof ControllerErrorEvent)
// Tell TypicalPlayerApplet.start() to call it a day
player = null;
Fatal(((ControllerErrorEvent)event).getMessage());
}//end of ControllerErrorEvent
else if (event instanceof ControllerClosedEvent)
panel.removeAll();
}//end of ControllerClosedEnent
}//end of controller update
void Fatal (String s)
// Applications will make various choices about what
// to do here. We print a message
System.err.println("FATAL ERROR: " + s);
throw new Error(s); // Invoke the uncaught exception
// handler System.exit() is another
// choice.
public void actionPerformed(ActionEvent ae)
Dimension imageSize = null;
String str=ae.getActionCommand();
if(str.equals ("GRAB FRAME"))
Image photo = grabFrameImage();
if (photo != null)
MySnapshot snapshot = new MySnapshot(photo, new Dimension(imageSize));
else
System.err.println("Errore : Impossibile grabbare il frame");
repaint();
* Grabba un frame dalla webcam @restituisce il frame in un buffer
public Buffer grabFrameBuffer()
if (player != null)
FrameGrabbingControl fgc =(FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
System.out.println(fgc );
if (fgc != null)
return (fgc.grabFrame());
else
System.err.println("Errore : FrameGrabbingControl non disponibile");
return (null);
else
System.err.println("Errore nel Player");
return (null);
* Converte il buffer frame in un'immagine
public Image grabFrameImage()
Buffer buffer = grabFrameBuffer();
if (buffer != null)
BufferToImage btoi = new BufferToImage((VideoFormat) buffer.getFormat());
if (btoi != null)
Image image = btoi.createImage(buffer);
if (image != null)
return (image);
else
System.err.println("Errore di conversione Buffer - BufferToImage");
return (null);
else
System.err.println("Errore nella creazione di BufferToImage");
return (null);
else
System.out.println("Errore: buffer vuoto");
return (null);
class MySnapshot extends JFrame
protected Image photo = null;
protected int shotNumber;
public MySnapshot(Image grabbedFrame, Dimension imageSize)
super();
shotNumber = shotCounter++;
setTitle("Immagine" + shotNumber);
photo = grabbedFrame;
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int imageHeight = photo.getWidth(this);
int imageWidth = photo.getHeight(this);
setSize(imageSize.width, imageSize.height);
final FileDialog saveDialog = new FileDialog(this,"Salva immagine", FileDialog.SAVE);
final JFrame thisCopy = this;
saveDialog.setFile("Immagine" + shotNumber);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
saveDialog.show();
String filename = saveDialog.getFile();
if (filename != null)
if (saveJPEG(filename))
JOptionPane.showMessageDialog(thisCopy,"Salvata immagine " + filename);
setVisible(false);
dispose();
else
JOptionPane.showMessageDialog(thisCopy,"Errore nel salvataggio di " + filename);
else
setVisible(false);
dispose();
setVisible(true);
public void paint(Graphics g)
g.drawImage(photo, 0, 0, getWidth(), getHeight(), this);
public boolean saveJPEG(String filename)
boolean saved = false;
BufferedImage bi = new BufferedImage(photo.getWidth(null), photo.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(photo, null, null);
FileOutputStream out = null;
try
out = new FileOutputStream(filename);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(bi);
out.close();
saved = true;
catch (Exception ex)
System.out.println("Errore salvataggio JPEG: "+ ex.getMessage());
return (saved);
}//end of class SimplePlayerAppletHmm....
some of that looks very familiar to me :-)
http://forum.java.sun.com/thread.jspa?forumID=28&threadID=570463
1. post your code wrapped in code tags and it'll display it nicely.
2. post to the Java Media Framework topic,
I haven't tried JMF within an applet.
Have you tried getting it working in an application first ?
That should simplify your debugging to start with.
I suspect the Player hasn't started yet, or isn't in a realised state.
regards,
Owen -
Problem with System.getProperty
Hi,
I am using the method System.getProperty
("DNSproxyclient.HOME");
I have set the path for HOME environmental variable in the unix system. I am using korn Shell but i am unable to get the value in the java program.
Can Someone help me out.
Regards,
VivekThis is the correct code:
// JCAPS uses JVM version 1.5
logger.info( "--- BEGIN ------ JCAPS userInitialize" );
String currRoot = System.getProperty( "com.stc.application.dataroot" );
String log4j_props = currRoot + "/../../NoemaLife/" + collabContext.getProjectPath() + "/" + collabContext.getCollaborationName() + "_log4j.properties";
but I have the same problem... -
System.getProperty("user.dir") returns "/home/user" on Linux
Has anyone else had the error when launching a jar from Linux (just by clicking it), System.getProperty("user.dir") returns the "/home/user" (or "~") value instead of the folder that the jar is in? Essentially, it returns "user.home" instead of "user.dir".
This does not happen when I start the application from command line.
(I know its not swing, but I wasn't sure where to post it)
Is this just a simple Linux setting that isn't enabled by default? Ubuntu already made the file association after using apt-get to install Java 6.
Cheers.
-FBLBecause, semmingly, the command is being set off as
java -jar relative/pat/to/file.jarwhen you double click it, rather than
cd relative/path/to
java -jar file.jarIf you don't like this, I would say to find a Linux, preferably Ubuntu, forum and ask there if it is possible to change that handling, and if not, request that a cahnge be made to the code to change that handling. But, in any case, I doubt you are going to get an answer here about it. -
System.getproperty("Var Name") gives null in RedHatLinux5
Please provide some solution for this strange problem. I am able to get the system property value from terminal but when I use System.getproperty() I am getting null.
Ex:
echo $client
ans: /home/naveen/client/classes
from java program
System.getproperty("client"); it gives nulluse getenv(), instead of getProperty()
-
Hello,
Based on the user's requirements, I implemented authentication based on the results of the System.getProperty(user.name) feature. The audit group has some concerns on where the user.name value is coming from.
Does anyone have any idea where this property is coming from, and if it is coming from a file, whether it is stored as text.Environment variable that is read internally by the JRE. If you go to dos (in windows) and type "set" and hit return, you'll see Username=whatever your login name is. If course, someone with the right credentials can change this.
Unix has a similar feature. -
GetConnectionURL returns null in Bluetooth Application
Hi,
I am trying to make my first steps with the JSR-82 API on mobile phones
(Nokia 6680 and Sony Ericsson W800i). I have written a simple program
(see code below), which is supposed to discover near-by devices, search
for a given service (UUID) on a chosen (previously discovered) device
(=server) and then to connect to the server and send a byte (n) to it. The
server should then in turn send n+1 back. All this should be done using
RFCOMM.
The code works fine in the emulator as well as on two Nokia phones and
on two SE phones. It further works, when using a Nokia phone as the
server and a SE phone as the client. However, when using a SE as the
client and a Nokia as the server, the call to getConnectionURL() returns
null instead of a valid URL that can be used to set up the connection
(you can find this piece of code in the ClientThread class). Can somebody
explain me what I am doing wrong?
Thanks,
Michael
P.S.:At first I thought it might be a compatibility problem, but in the
BluetoothDemo program that comes with WTK2.2 the correct URL ist
returned by getConnectionURL() (have other problems with this example
though, when it comes to download images, in particular...).
import java.io.IOException;
import java.util.Vector;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DataElement;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;
import javax.microedition.io.StreamConnectionNotifier;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MessageTest2 extends MIDlet
implements CommandListener, DiscoveryListener {
private final int START = 0;
private final int SERVER_IDLE = 1;
private final int CLIENT_START = 2;
private final int CLIENT_DEVICES_DISCOVERED = 3;
private final int CLIENT_SERVICES_DISCOVERED = 4;
private final String MY_UUID = "F0E0D0C0B0A000908070605040302010";
private final Command EXIT_CMD = new Command("Exit", Command.EXIT, 1);
private final Command OK_CMD = new Command("Ok", Command.OK, 1);
private List startList = new List("Select Type", List.IMPLICIT);
private List deviceList = null;
private List serviceList = null;
private Form mainForm = new Form("Message Test 2");
private int state;
private ServerThread serverThread = null;
private LocalDevice local = null;
private DiscoveryAgent agent = null;
StreamConnectionNotifier server = null;
private Vector devicesFound = null;
private ServiceRecord[] servicesFound = null;
public MessageTest2() {
super();
mainForm.addCommand(EXIT_CMD);
mainForm.addCommand(OK_CMD);
mainForm.setCommandListener(this);
startList.addCommand(EXIT_CMD);
startList.addCommand(OK_CMD);
startList.append("Server", null);
startList.append("Client", null);
startList.setCommandListener(this);
protected void startApp() throws MIDletStateChangeException {
state = START;
Display.getDisplay(this).setCurrent(startList);
protected void pauseApp() {
// TODO Auto-generated method stub
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
public void commandAction(Command c, Displayable d) {
if (c == EXIT_CMD) {
if (server != null) {
try {
server.close();
} catch (IOException e) {
notifyDestroyed();
if (c == OK_CMD) {
if (state == START) {
if (startList.getSelectedIndex() == 0) {
startServer();
} else {
startClient();
} else if (state == CLIENT_START) {
doDeviceDiscovery();
} else if (state == CLIENT_DEVICES_DISCOVERED) {
doServiceDiscovery();
} else if (state == CLIENT_SERVICES_DISCOVERED) {
communicate();
public void deviceDiscovered(RemoteDevice dev, DeviceClass devClass) {
devicesFound.addElement(dev);
public void servicesDiscovered(int transID, ServiceRecord[] serviceRecs) {
servicesFound = serviceRecs;
public void serviceSearchCompleted(int transID, int respCode) {
switch(respCode) {
case DiscoveryListener.SERVICE_SEARCH_COMPLETED:
showServices();
break;
case DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE:
System.err.println("Device not reachable");
break;
case DiscoveryListener.SERVICE_SEARCH_ERROR:
System.err.println("Service search error");
break;
case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS:
System.err.println("No records");
break;
case DiscoveryListener.SERVICE_SEARCH_TERMINATED:
System.err.println("Service search terminated (cancelled)");
break;
public void inquiryCompleted(int param) {
switch (param) {
case DiscoveryListener.INQUIRY_COMPLETED:
showDevices();
break;
case DiscoveryListener.INQUIRY_ERROR:
System.err.println("Inquiry error");
Display.getDisplay(this).setCurrent(mainForm);
break;
case DiscoveryListener.INQUIRY_TERMINATED:
System.err.println("Inquiry terminated (cancelled)");
Display.getDisplay(this).setCurrent(mainForm);
break;
public void setServer(StreamConnectionNotifier server) {
this.server = server;
private void startServer() {
state = SERVER_IDLE;
mainForm.deleteAll();
mainForm.append("Server");
Display.getDisplay(this).setCurrent(mainForm);
String connectionURL = "btspp://localhost:" + MY_UUID + ";"
+ "authenticate=false;encrypt=false;name=RFCOMM Server";
try {
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
} catch (BluetoothStateException e) {
System.err.println(e);
serverThread = new ServerThread(this, connectionURL);
serverThread.start();
System.out.println("Server thread started");
private void startClient() {
state = CLIENT_START;
mainForm.deleteAll();
mainForm.append("Discover?");
Display.getDisplay(this).setCurrent(mainForm);
private void doDeviceDiscovery() {
Form discoveringForm = new Form("discovering");
try {
local = LocalDevice.getLocalDevice();
} catch (BluetoothStateException e) {
System.err.println(e);
agent = local.getDiscoveryAgent();
devicesFound = new Vector();
try {
if (!agent.startInquiry(DiscoveryAgent.GIAC, this)) {
System.err.println("Inquiry not started...");
} catch (BluetoothStateException e) {
System.err.println(e);
Display.getDisplay(this).setCurrent(discoveringForm);
private void doServiceDiscovery() {
if (devicesFound.size() <= 0) return;
int[] attributes = {0x100, 0x101, 0x102};
UUID[] uuids = new UUID[1];
uuids[0] = new UUID(MY_UUID, false);
int index = deviceList.getSelectedIndex();
RemoteDevice rd = (RemoteDevice)devicesFound.elementAt(index);
try {
agent.searchServices(attributes, uuids, rd, this);
} catch (BluetoothStateException e) {
System.err.println(e);
private void showDevices() {
state = CLIENT_DEVICES_DISCOVERED;
deviceList = new List("Discovered Devices", List.IMPLICIT);
deviceList.addCommand(EXIT_CMD);
deviceList.addCommand(OK_CMD);
deviceList.setCommandListener(this);
for (int i = 0; i < devicesFound.size(); i++) {
RemoteDevice rd = (RemoteDevice)devicesFound.elementAt(i);
String str = rd.getBluetoothAddress();
try {
str = str + " " + rd.getFriendlyName(false);
} catch (IOException e) {
deviceList.append(str, null);
Display.getDisplay(this).setCurrent(deviceList);
private void showServices() {
state = CLIENT_SERVICES_DISCOVERED;
if (servicesFound.length <= 0) {
mainForm.deleteAll();
mainForm.append("no services found");
mainForm.append("discover devices?");
state = CLIENT_START;
Display.getDisplay(this).setCurrent(mainForm);
return;
serviceList = new List("Services Found", List.IMPLICIT);
serviceList.addCommand(EXIT_CMD);
serviceList.addCommand(OK_CMD);
serviceList.setCommandListener(this);
for (int i = 0; i < servicesFound.length; i++) {
String str;
ServiceRecord sr = (ServiceRecord)servicesFound;
DataElement de = sr.getAttributeValue(0x100);
str = (String)de.getValue();
serviceList.append(str, null);
Display.getDisplay(this).setCurrent(serviceList);
private void communicate() {
int index = serviceList.getSelectedIndex();
ServiceRecord sr = (ServiceRecord)servicesFound[index];
ClientThread clientThread = new ClientThread(this, sr);
clientThread.start();
public void showResult(int n) {
Form resultForm = new Form("End");
resultForm.addCommand(EXIT_CMD);
resultForm.setCommandListener(this);
resultForm.append("Received: " + n);
Display.getDisplay(this).setCurrent(resultForm);
public void showMessage(String msg) {
Displayable d = Display.getDisplay(this).getCurrent();
Alert al = new Alert("Info", msg, null, AlertType.INFO);
al.setTimeout(Alert.FOREVER);
Display.getDisplay(this).setCurrent(al, d);
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;
public class ServerThread extends Thread {
private MessageTest2 parent;
private StreamConnectionNotifier server;
private String connectionURL = null;
public ServerThread(MessageTest2 parent, String connectionURL) {
this.parent = parent;
this.connectionURL = connectionURL;
public void run() {
StreamConnection conn = null;
try {
server = (StreamConnectionNotifier) Connector.open(connectionURL);
} catch (IOException e) {
System.err.println(e);
parent.setServer(server);
try {
conn = server.acceptAndOpen();
} catch (IOException e) {
System.err.println(e);
InputStream in = null;
int n = -1;
try {
in = conn.openInputStream();
n = in.read();
} catch (IOException e) {
System.err.println(e);
if (in != null) {
try {
in.close();
} catch (IOException e) {
System.err.println(e);
try {
OutputStream out;
out = conn.openOutputStream();
out.write(n + 1);
out.flush();
} catch (IOException e) {
System.err.println(e);
try {
conn.close();
} catch (IOException e) {
System.out.println(e);
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.bluetooth.ServiceRecord;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
public class ClientThread extends Thread {
private MessageTest2 parent;
private ServiceRecord sr;
public ClientThread(MessageTest2 parent, ServiceRecord sr) {
this.parent = parent;
this.sr = sr;
public void run() {
StreamConnection conn = null;
String url = null;
int n = 0;
try {
url = sr.getConnectionURL(
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
if (url == null) {
parent.showMessage("URL null");
return;
conn = (StreamConnection) Connector.open(url);
} catch (IOException e) {
System.err.println("Note: can't connect to: " + url);
try {
OutputStream out = conn.openOutputStream();
out.write(n);
out.flush();
out.close();
InputStream in = conn.openInputStream();
n = in.read();
} catch (IOException e) {
System.err.println("Can't write to server for: " + url);
try {
conn.close();
} catch (IOException ee) {
System.err.println(ee);
parent.showResult(n);Hi:
How did you compile and build the package using WSDL2JAVA. I tried under UCM 6.1 environment but receiving error message on 2 of the classes that, too large object.
axisbuild:
compiling 1007 source files
/generatedaxisclient/com/cisco/www/AXLAPLService/AXLAPIBindingStub.java:4026:code too large
public AXLAPIBindingStub(javax.xml.rpc.Service service)throws org.apache.axis.AxisFault {
Error
/generatedaxisclient/com/cisco/www/AXLAPLService/AXLAPIBindingStub.java:18:code too large
public AXLAPIBindingStub(javax.xml.rpc.Service service)throws org.apache.axis.AxisFault {
static {
Error
2 Errors
Please let me know if you have any thoughts on this.
Thank You
Ramesh Vasudevan -
Alternative to System.getProperty("microedition.hostname")
Hey is there any other alternative for 'System.getProperty("microedition.hostname")' to get the ip address of the device running the j2me midlet ??
When you run the midlet on the emulator, System.getProperty("microedition.hostname") returns the PC's Name, but on a Nokia series 40(3rd E) device, it returns null.
So is there an alternative to this to select the device's ip address ?First this is a pretty specific question which applies to a specific device rather than to reflection/reference. You might want to look for a forum that addresses the specific device.
Second, you can print the system properties normally. Whether you can do that on the device depends on the device. If you succeed you might find an alternative.
Third normally one uses the java.net.IpAddress to get a device IP. Does that not work for that device? -
System.getProperty doesnot work
Hi,
I have a piece of code where I try to get a env variable VTNAME in my java application. Code snippet below
//this function creates a session.
public void setSession(configParams params) throws Exception {
boolean done = false;
int retryCount = 0;
mVTName = params.getFactoryName();
System.out.println(System.getProperty("VTNAME"));
It returns me null. And when i do
:/home/santsat > echo $VTNAME
dbusd1.srv.uk.deuba.com:8092/tcp:
Any thoughts o what is wrong in the code?
Thanks
Message was edited by:
chabhiJava's system property is not the same as environment variable.
To get environment variable, use System.getenv().
If you start your java app with -DVTNAME= then you can use System.getProperty().
Budyanto
Maybe you are looking for
-
I dropped my phone into the bath last night and it was working perfectly fine the hole day, I went to put it on charge and now it won't charge or even turn on what do I do
-
My iphone is fully charged but it will not turn on unless plugged into a charger
my iphone is fully charged but it will not turn on unless plugged into the charger in the wall, it wont even turn on when connected to the computer!!!!!!!
-
Does out.flush() work in a JSP page without buffering?
All: I am using WLS 4.51 and have found that it is not possible to flush the contents of the ServletOutputStream. I have seen this behavior in JSPs and Servlets. What I am trying to achieve is a simple status m
-
Crm plugin issue when updating parent account field in account.
Hi , In my CRM Application ( CRM 2011) we have accounts and contacts. when account parent account is updated their contacts owner id will be updated in crm db server and external server using notification service which is called by pulgin. so in one
-
I can't make a connection from JDeveloper 10g (9.0.5.0.0) to WebLogic 8.1 When I click "Test connection" JDeveloper 10g writes the following: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory Have somebody ever established a connection