Packages non standarts de java
jwidd
Messages postés
30
Date d'inscription
Statut
Membre
Dernière intervention
-
fastspin -
fastspin -
comment peut-on utiliser des packages n'appartenant pas au standart java (com.symbian.*, com.baracoda.*,.... pour ceux qui les connaissent) dans une application développée en java?
sachant que le fait de les importer tout court ne marche pas.est ce que je dois copier les classes contenues dans ce package dans le dossier class de mon projet?
sachant que le fait de les importer tout court ne marche pas.est ce que je dois copier les classes contenues dans ce package dans le dossier class de mon projet?
A voir également:
- Packages non standarts de java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
27 réponses
salut
tu dois en effet avoir une copie de ces classes dans ton projet, sous forme de package par exemple
tu dois en effet avoir une copie de ces classes dans ton projet, sous forme de package par exemple
jte remercie d'abord de m'avoir répondu, désolée j'ai oublié de le faire la dernière fois.
ça ne marche toujours pas,les packages dont je vous ai parlé sont inexistant pour le compilateur.voilà une copie de la première partie de ma classe java:
package com.baracoda.testapp;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.baracoda.*; // Baracoda library import
import javax.bluetooth.*; // Bluetooth JSR82 package
import java.util.Vector;
/** The main midlet class
* @implements BaracodaListener
*/
public class BaracodaManager extends MIDlet
implements CommandListener, BaracodaListener {
private Display mDisplay;
private Command mExitCommand, mFindCommand, mListCommand,
mConnectCommand, mDisconnectCommand;
private TextBox mTextBox;
// Found devices list
private List mList;
// Inquiry object
private BaracodaInquiry inq;
// Connected device
private BaracodaReader dev;
// Last connected device's index in the found devices table
private int lastIndex;
// Last connected device's address
private String lastDevice;
// Found devices' address
private Vector foundAddresses;
...............
tout ce qu'il y a dans le package com.baracoda comme l'attribut BaracodaInquiry , est souligné en rouge.
j'arrive pas à avancer tant que ce problème n'est pas résolu.
ça ne marche toujours pas,les packages dont je vous ai parlé sont inexistant pour le compilateur.voilà une copie de la première partie de ma classe java:
package com.baracoda.testapp;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.baracoda.*; // Baracoda library import
import javax.bluetooth.*; // Bluetooth JSR82 package
import java.util.Vector;
/** The main midlet class
* @implements BaracodaListener
*/
public class BaracodaManager extends MIDlet
implements CommandListener, BaracodaListener {
private Display mDisplay;
private Command mExitCommand, mFindCommand, mListCommand,
mConnectCommand, mDisconnectCommand;
private TextBox mTextBox;
// Found devices list
private List mList;
// Inquiry object
private BaracodaInquiry inq;
// Connected device
private BaracodaReader dev;
// Last connected device's index in the found devices table
private int lastIndex;
// Last connected device's address
private String lastDevice;
// Found devices' address
private Vector foundAddresses;
...............
tout ce qu'il y a dans le package com.baracoda comme l'attribut BaracodaInquiry , est souligné en rouge.
j'arrive pas à avancer tant que ce problème n'est pas résolu.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
C:\WTK25\apps\BaracodaManager\src\com\baracoda\testapp\BaracodaManager.java:34: cannot find symbol
symbol : class BaracodaInquiry
location: class com.baracoda.testapp.BaracodaManager
private BaracodaInquiry inq;
voilà telle est la même erreur donnée par le compilateur pour toutes les variables et les méthodes du package com. baracod, BaracodaInquiry inq en est un exemple.
symbol : class BaracodaInquiry
location: class com.baracoda.testapp.BaracodaManager
private BaracodaInquiry inq;
voilà telle est la même erreur donnée par le compilateur pour toutes les variables et les méthodes du package com. baracod, BaracodaInquiry inq en est un exemple.
alors? choubaka vous en dites koi?
si kelkun a une idée, qu'il n'hésite pas à me répondre,j'en ai vraiment besoin.
merci quand même choubaka, tu es le seul(ou la seule),dslée jsuis pas allée voit ton profil, qui m'aies répondu.je croyais qu'on pourrait vieillir dans ce forum et personne ne viendra à ton secours, et cle cas dans d'autres forums.
si kelkun a une idée, qu'il n'hésite pas à me répondre,j'en ai vraiment besoin.
merci quand même choubaka, tu es le seul(ou la seule),dslée jsuis pas allée voit ton profil, qui m'aies répondu.je croyais qu'on pourrait vieillir dans ce forum et personne ne viendra à ton secours, et cle cas dans d'autres forums.
non je travaille avec netbeans.
bon je crois ke le problème est dans l'enchaînement des actions pour créer un projet java. nous le faisions dans le cours de java il y a une
année et jm'en rappelle plus.
je crains ke jle fais mal.bon je vous dis les étapes ke je fais et corrigez moi si jme trompe.
je crée un nouveau projet, je spécifie le package et les classes java, j'écris les classes.
et puis je vais dans l'emplacement où j'ai créé le projet pour copier les packages externes, j'ai ajouté le fichier.jar dans le classpath(système->avancé->variables d'environnement...) et j'ai même fait addLibrary...., j'ai tout fait mais ça ne marche toujours pas.
est ce qu'il faut aller ajouter les packages avant d'écrire les classes comme ça les packages seront reconnus? non mais au moment de la compilation, le compilateur cherche les classes dans le classpath, donc l'ordre n'est pas un prob, n'est ce pas?
bon s'il vs plaît, énumérez moi les étapes pour créer un projet java, comme ça je saurai si le prob est dans ma façon de créer un projet ou pas.
merci bcp, vous êtes un ange.
bon je crois ke le problème est dans l'enchaînement des actions pour créer un projet java. nous le faisions dans le cours de java il y a une
année et jm'en rappelle plus.
je crains ke jle fais mal.bon je vous dis les étapes ke je fais et corrigez moi si jme trompe.
je crée un nouveau projet, je spécifie le package et les classes java, j'écris les classes.
et puis je vais dans l'emplacement où j'ai créé le projet pour copier les packages externes, j'ai ajouté le fichier.jar dans le classpath(système->avancé->variables d'environnement...) et j'ai même fait addLibrary...., j'ai tout fait mais ça ne marche toujours pas.
est ce qu'il faut aller ajouter les packages avant d'écrire les classes comme ça les packages seront reconnus? non mais au moment de la compilation, le compilateur cherche les classes dans le classpath, donc l'ordre n'est pas un prob, n'est ce pas?
bon s'il vs plaît, énumérez moi les étapes pour créer un projet java, comme ça je saurai si le prob est dans ma façon de créer un projet ou pas.
merci bcp, vous êtes un ange.
c bon, mon problème est résolu, il fallait juste ajouter le fichier baracodalib.jar aux fichiers jar.
ce fichier contient la librairie baracoda, que j'avais téléchargé et que je ne savais pas que faire avec.
maintenant je n'ai plus d'erreurs de compilation et je passe à la seconde partie qui consiste en la recherche d'une api en java qui envoi et reçoit des sms d'un téléphone portable vers un autre.
si tu as la moindre info là dessus n'hésite pas à me la faire communiquer.
merci bcp.
ce fichier contient la librairie baracoda, que j'avais téléchargé et que je ne savais pas que faire avec.
maintenant je n'ai plus d'erreurs de compilation et je passe à la seconde partie qui consiste en la recherche d'une api en java qui envoi et reçoit des sms d'un téléphone portable vers un autre.
si tu as la moindre info là dessus n'hésite pas à me la faire communiquer.
merci bcp.
Oui effectivement, lorsqu'on utilise un IDE pour développer une application Java, il faut avant tout déclarer les packages java non standard de la même manière qu'un librairie externe, à savoir l'ajouter dans la liste des sources externes du projet à compiler.
salut,
j'ai besoin dans une partie de l'application que je suis entrain de développer du code java qui permet l'envoi et la réception des sms d'un téléphone (Nokia 6600) vers un autre téléphone.
j'ai trouvé pas mal de bouts de code mais qui ne marche pas et à chaque fois je suis découragée à l'idée de pouvoir résoudre les erreurs de compilation ou les exceptions génerées.
voilà je vous expose au dessous un bout de code qui se compile parfaitement mais qui génère une exception à l'exécution, j'ai essayé de trouver la cause mais je n'y suis pas arrivée.je soulignerai la ligne où il me signale l'exception qui est :illegalargument..(jnme rappelle plus de la phrase exacte) et en gras le dit argument.
je travaille avec le Netbeans 5.5, si quelqu'un veut bien l'essayer et me dire ce qui cloche si c possible.c'est urgent je n'ai plus qu'une semaine devant moi.
import java.io.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class WMAExample extends MIDlet implements CommandListener, MessageListener, ItemStateListener {
private Command exitCommand;
private Command sendCommand;
private Display display;
private Form form;
private ChoiceGroup cg;
private TextField MessageAddressField;
private TextField TextMessageBodyField;
private StringItem binaryFormText;
private MessageConnection con;
private Alert alert;
private Image thumbUp;
private String MessageAddress;
private String MessageServerPort;
private String TextMessageBody;
private String BinaryMessageBodyFile;
private byte[] BinaryMessageBody;
private void log (String logMessage) {
System.out.println (logMessage);
if (form != null) {
form.append(logMessage);
}
}
private void init () {
// Initialize the address, where the message will be sent to
MessageAddress = getAppProperty (MIDletMessageAddressAttribute);
if (MessageAddress == null) {
MessageAddress = DefaultMIDletMessageAddress;
}
// Initialize the port number, where the MIDlet is listening on.
MessageServerPort = getAppProperty (MIDletServerPortAttribute);
if (MessageServerPort == null) {
MessageServerPort = DefaultMIDletServerPort;
}
// Initialize the message to send
// The message can be either a text message or a binary message
TextMessageBody = getAppProperty (MIDletMessageTextBodyAttribute);
BinaryMessageBodyFile = getAppProperty (MIDletBinaryMessageBodyFileAttribute);
// If there is no message defined in the JAD file, send a text message
if ((TextMessageBody == null) && (BinaryMessageBodyFile == null)) {
TextMessageBody = DefaultMIDletTextMessage;
}
// Read the binary file from the JAR
if (BinaryMessageBodyFile != null) {
log ("Reading resource file: " + BinaryMessageBodyFile);
try
{
InputStream is = getClass().getResourceAsStream(BinaryMessageBodyFile);
if (is == null ) {
// The file name in the JAD file is mistyped or
// the file is not included in the JAR
log ("Resource file " + BinaryMessageBodyFile +
" not found in the JAR file.");
// We do not have a binary message
BinaryMessageBodyFile = null;
} else {
DataInputStream dataStream = new DataInputStream(is);
byte[] tempBuffer = new byte [500];
byte[] data = new byte[1];
int size = 0;
int byteRead = dataStream.read(data, 0, data.length);
while(byteRead >= 0)
{
tempBuffer[size++] = data[0];
byteRead = dataStream.read(data, 0, data.length);
}
dataStream.close();
if (size >0 )
{
BinaryMessageBody = new byte [size];
}
for (int i=0; i<size; i++)
{
BinaryMessageBody[i] = tempBuffer [i];
}
}
} catch(Exception ex)
{
log ("Exception: " + ex.toString());
}
}
}
public WMAExample() {
}
public void startApp() {
// Initialize MIDlet parameters from the JAD file
init ();
// Listen for incomming messages
listen (MessageServerPort);
// Create the commands
exitCommand = new Command("Exit", Command.EXIT, 2);
sendCommand = new Command("Send", Command.OK, 1);
// Create the UI
form = new Form("WMAExample");
//create the choicegroup & add it to the form.
cg = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE);
cg.append("Text",null);
cg.append("Binary",null);
form.append(cg);
//register the itemStateChanged listener.
form.setItemStateListener(this);
// Create a field for the destination address
MessageAddressField = new TextField("Address:", MessageAddress, 20, TextField.PHONENUMBER);
form.append(MessageAddressField);
// Create a field for the message body
TextMessageBodyField = new TextField("Message:", TextMessageBody, 435, TextField.ANY);
form.append(TextMessageBodyField);
// Add commands to the form
form.addCommand(exitCommand);
form.addCommand(sendCommand);
form.setCommandListener(this);
// Set display
display = Display.getDisplay(this);
display.setCurrent(form);
}
/** Handle pausing the MIDlet */
public void pauseApp() {
try
{
con.close();
}
catch (Exception ex)
{
}
}
/** Handle destroying the MIDlet */
public void destroyApp(boolean unconditional) {
try
{
con.close();
}
catch (Exception ex)
{
}
}
public void notifyIncomingMessage(MessageConnection mscon) {
if (con == mscon) {
try {
//TextMessage receivedMessage = (TextMessage)mscon.receive();
Message receivedMessage = mscon.receive();
if (receivedMessage instanceof TextMessage) {
messageReceivedHandler( (TextMessage) receivedMessage);
}
if (receivedMessage instanceof BinaryMessage) {
messageReceivedHandler( (BinaryMessage) receivedMessage);
}
}
catch (Exception ex) {
log("Exception: " + ex.toString());
}
}
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
// Send a text message
if (c == sendCommand && cg.getSelectedIndex() == 0) {
if (TextMessageBody != null) {
String destAddress = MessageAddressField.getString();
String messageBody = TextMessageBodyField.getString();
sendTextMessage(con, destAddress, messageBody);
}
}
// Send a binary message
else if (c == sendCommand && cg.getSelectedIndex() == 1) {
if (BinaryMessageBodyFile != null) {
String destAddress = MessageAddressField.getString();
sendBinaryMessage(con, destAddress, BinaryMessageBody);
}
}
}
public void itemStateChanged(Item item) {
int i; //to use in the search loop
//test whether the item that changed is the ChoiceGroup, else exit.
if(item.equals(cg)){
//if BinaryMessaging selected
if (cg.getSelectedIndex() == 1) {
//search for the TextMessageField Object and then remove it from the form.
//add binaryFormText to the form in its place.
for (i = 0; i < form.size(); ++i) {
if(form.get(i) == TextMessageBodyField) {
form.delete(i);
binaryFormText = new StringItem("Message:","Ready to send /test.bin");
form.append(binaryFormText);
break;
}
}
}
//add the TextMessageBodyField & remove binaryFormText
else if (cg.getSelectedIndex() == 0) {
//first search for and remove the string "str".
for(i=0; i<form.size(); ++i){
if(form.get(i) == binaryFormText){
form.delete(i);
form.append(TextMessageBodyField);
}
}
}//end else if
}//end if(item.equals(cg))
}
public void sendBinaryMessage
(MessageConnection connection, String destAddress, byte[] Body) {
// Construct the message
BinaryMessage Message = (BinaryMessage)connection.newMessage(
MessageConnection.BINARY_MESSAGE,
"sms://" + destAddress + ":7500");
// Set the payload
Message.setPayloadData(Body);
try
{
// Send the message
connection.send(Message);
thumbUp = Image.createImage("/thumbsup.png");
alert = new Alert("Message Sent",
"Binary Message sent: " + Body.length + " bytes.",
thumbUp, AlertType.CONFIRMATION);
alert.setTimeout(3000); //3 seconds
display.setCurrent(alert,form);
//log ("Binary Message sent: " + Body.length + " bytes.");
}
catch (IOException ioex)
{
log("IOException: " + ioex.toString());
}
catch(SecurityException syex)
{
log("SecurityException: " + syex.toString());
}
catch (Exception ex)
{
log("Exception: " + ex.toString());
}
}
public void sendTextMessage
(MessageConnection connection, String destAddress, String Body) {
// Construct the message
TextMessage Message = (TextMessage)connection.newMessage(
MessageConnection.TEXT_MESSAGE,
"sms://" + destAddress +":7500");
// Set the payload
Message.setPayloadText(Body);
try
{
// Send the message
connection.send(Message);
thumbUp = Image.createImage("/thumbsup.png");
alert = new Alert("Message Sent",
"Text Message sent: " + Body,
thumbUp, AlertType.CONFIRMATION);
alert.setTimeout(3000); //3 seconds
display.setCurrent(alert, form);
//log ("Text Message sent: " + Body);
}
catch (IOException ioex)
{
log("IOException: " + ioex.toString());
}
catch(SecurityException syex)
{
log("SecurityException: " + syex.toString());
}
catch (Exception ex)
{
log("Exception: " + ex.toString());
}
}
public void messageReceivedHandler (TextMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
String receivedMessageBody = receivedMessage.getPayloadText();
log ("Text Message received: " + receivedMessageBody);
}
public void messageReceivedHandler (BinaryMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
byte[] receivedMessageBody = receivedMessage.getPayloadData();
log ("Binary Message received: " + receivedMessageBody.length + " bytes.");
}
public void listen (String MessageServerPort) {
try
{
con = (MessageConnection) Connector.open(
"sms://:" + MessageServerPort);
con.setMessageListener(this);
}
catch(Exception ex)
{
log("Exception during listen: " + ex.toString());
}
}
/* Default values, if there is nothing specified in the JAD file */
private static final String DefaultMIDletMessageAddress = "3300001:7500";
private static final String DefaultMIDletServerPort = "7500";
private static final String DefaultMIDletTextMessage = "Test message";
/* Constants */
private static final String MIDletMessageAddressAttribute =
new String ("Message-Address");
private static final String MIDletServerPortAttribute =
new String ("ServerPort");
private static final String MIDletMessageTextBodyAttribute =
new String ("Message-Text-Body");
private static final String MIDletBinaryMessageBodyFileAttribute =
new String ("Binary-Message-Body-File");
}
j'ai besoin dans une partie de l'application que je suis entrain de développer du code java qui permet l'envoi et la réception des sms d'un téléphone (Nokia 6600) vers un autre téléphone.
j'ai trouvé pas mal de bouts de code mais qui ne marche pas et à chaque fois je suis découragée à l'idée de pouvoir résoudre les erreurs de compilation ou les exceptions génerées.
voilà je vous expose au dessous un bout de code qui se compile parfaitement mais qui génère une exception à l'exécution, j'ai essayé de trouver la cause mais je n'y suis pas arrivée.je soulignerai la ligne où il me signale l'exception qui est :illegalargument..(jnme rappelle plus de la phrase exacte) et en gras le dit argument.
je travaille avec le Netbeans 5.5, si quelqu'un veut bien l'essayer et me dire ce qui cloche si c possible.c'est urgent je n'ai plus qu'une semaine devant moi.
import java.io.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class WMAExample extends MIDlet implements CommandListener, MessageListener, ItemStateListener {
private Command exitCommand;
private Command sendCommand;
private Display display;
private Form form;
private ChoiceGroup cg;
private TextField MessageAddressField;
private TextField TextMessageBodyField;
private StringItem binaryFormText;
private MessageConnection con;
private Alert alert;
private Image thumbUp;
private String MessageAddress;
private String MessageServerPort;
private String TextMessageBody;
private String BinaryMessageBodyFile;
private byte[] BinaryMessageBody;
private void log (String logMessage) {
System.out.println (logMessage);
if (form != null) {
form.append(logMessage);
}
}
private void init () {
// Initialize the address, where the message will be sent to
MessageAddress = getAppProperty (MIDletMessageAddressAttribute);
if (MessageAddress == null) {
MessageAddress = DefaultMIDletMessageAddress;
}
// Initialize the port number, where the MIDlet is listening on.
MessageServerPort = getAppProperty (MIDletServerPortAttribute);
if (MessageServerPort == null) {
MessageServerPort = DefaultMIDletServerPort;
}
// Initialize the message to send
// The message can be either a text message or a binary message
TextMessageBody = getAppProperty (MIDletMessageTextBodyAttribute);
BinaryMessageBodyFile = getAppProperty (MIDletBinaryMessageBodyFileAttribute);
// If there is no message defined in the JAD file, send a text message
if ((TextMessageBody == null) && (BinaryMessageBodyFile == null)) {
TextMessageBody = DefaultMIDletTextMessage;
}
// Read the binary file from the JAR
if (BinaryMessageBodyFile != null) {
log ("Reading resource file: " + BinaryMessageBodyFile);
try
{
InputStream is = getClass().getResourceAsStream(BinaryMessageBodyFile);
if (is == null ) {
// The file name in the JAD file is mistyped or
// the file is not included in the JAR
log ("Resource file " + BinaryMessageBodyFile +
" not found in the JAR file.");
// We do not have a binary message
BinaryMessageBodyFile = null;
} else {
DataInputStream dataStream = new DataInputStream(is);
byte[] tempBuffer = new byte [500];
byte[] data = new byte[1];
int size = 0;
int byteRead = dataStream.read(data, 0, data.length);
while(byteRead >= 0)
{
tempBuffer[size++] = data[0];
byteRead = dataStream.read(data, 0, data.length);
}
dataStream.close();
if (size >0 )
{
BinaryMessageBody = new byte [size];
}
for (int i=0; i<size; i++)
{
BinaryMessageBody[i] = tempBuffer [i];
}
}
} catch(Exception ex)
{
log ("Exception: " + ex.toString());
}
}
}
public WMAExample() {
}
public void startApp() {
// Initialize MIDlet parameters from the JAD file
init ();
// Listen for incomming messages
listen (MessageServerPort);
// Create the commands
exitCommand = new Command("Exit", Command.EXIT, 2);
sendCommand = new Command("Send", Command.OK, 1);
// Create the UI
form = new Form("WMAExample");
//create the choicegroup & add it to the form.
cg = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE);
cg.append("Text",null);
cg.append("Binary",null);
form.append(cg);
//register the itemStateChanged listener.
form.setItemStateListener(this);
// Create a field for the destination address
MessageAddressField = new TextField("Address:", MessageAddress, 20, TextField.PHONENUMBER);
form.append(MessageAddressField);
// Create a field for the message body
TextMessageBodyField = new TextField("Message:", TextMessageBody, 435, TextField.ANY);
form.append(TextMessageBodyField);
// Add commands to the form
form.addCommand(exitCommand);
form.addCommand(sendCommand);
form.setCommandListener(this);
// Set display
display = Display.getDisplay(this);
display.setCurrent(form);
}
/** Handle pausing the MIDlet */
public void pauseApp() {
try
{
con.close();
}
catch (Exception ex)
{
}
}
/** Handle destroying the MIDlet */
public void destroyApp(boolean unconditional) {
try
{
con.close();
}
catch (Exception ex)
{
}
}
public void notifyIncomingMessage(MessageConnection mscon) {
if (con == mscon) {
try {
//TextMessage receivedMessage = (TextMessage)mscon.receive();
Message receivedMessage = mscon.receive();
if (receivedMessage instanceof TextMessage) {
messageReceivedHandler( (TextMessage) receivedMessage);
}
if (receivedMessage instanceof BinaryMessage) {
messageReceivedHandler( (BinaryMessage) receivedMessage);
}
}
catch (Exception ex) {
log("Exception: " + ex.toString());
}
}
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
// Send a text message
if (c == sendCommand && cg.getSelectedIndex() == 0) {
if (TextMessageBody != null) {
String destAddress = MessageAddressField.getString();
String messageBody = TextMessageBodyField.getString();
sendTextMessage(con, destAddress, messageBody);
}
}
// Send a binary message
else if (c == sendCommand && cg.getSelectedIndex() == 1) {
if (BinaryMessageBodyFile != null) {
String destAddress = MessageAddressField.getString();
sendBinaryMessage(con, destAddress, BinaryMessageBody);
}
}
}
public void itemStateChanged(Item item) {
int i; //to use in the search loop
//test whether the item that changed is the ChoiceGroup, else exit.
if(item.equals(cg)){
//if BinaryMessaging selected
if (cg.getSelectedIndex() == 1) {
//search for the TextMessageField Object and then remove it from the form.
//add binaryFormText to the form in its place.
for (i = 0; i < form.size(); ++i) {
if(form.get(i) == TextMessageBodyField) {
form.delete(i);
binaryFormText = new StringItem("Message:","Ready to send /test.bin");
form.append(binaryFormText);
break;
}
}
}
//add the TextMessageBodyField & remove binaryFormText
else if (cg.getSelectedIndex() == 0) {
//first search for and remove the string "str".
for(i=0; i<form.size(); ++i){
if(form.get(i) == binaryFormText){
form.delete(i);
form.append(TextMessageBodyField);
}
}
}//end else if
}//end if(item.equals(cg))
}
public void sendBinaryMessage
(MessageConnection connection, String destAddress, byte[] Body) {
// Construct the message
BinaryMessage Message = (BinaryMessage)connection.newMessage(
MessageConnection.BINARY_MESSAGE,
"sms://" + destAddress + ":7500");
// Set the payload
Message.setPayloadData(Body);
try
{
// Send the message
connection.send(Message);
thumbUp = Image.createImage("/thumbsup.png");
alert = new Alert("Message Sent",
"Binary Message sent: " + Body.length + " bytes.",
thumbUp, AlertType.CONFIRMATION);
alert.setTimeout(3000); //3 seconds
display.setCurrent(alert,form);
//log ("Binary Message sent: " + Body.length + " bytes.");
}
catch (IOException ioex)
{
log("IOException: " + ioex.toString());
}
catch(SecurityException syex)
{
log("SecurityException: " + syex.toString());
}
catch (Exception ex)
{
log("Exception: " + ex.toString());
}
}
public void sendTextMessage
(MessageConnection connection, String destAddress, String Body) {
// Construct the message
TextMessage Message = (TextMessage)connection.newMessage(
MessageConnection.TEXT_MESSAGE,
"sms://" + destAddress +":7500");
// Set the payload
Message.setPayloadText(Body);
try
{
// Send the message
connection.send(Message);
thumbUp = Image.createImage("/thumbsup.png");
alert = new Alert("Message Sent",
"Text Message sent: " + Body,
thumbUp, AlertType.CONFIRMATION);
alert.setTimeout(3000); //3 seconds
display.setCurrent(alert, form);
//log ("Text Message sent: " + Body);
}
catch (IOException ioex)
{
log("IOException: " + ioex.toString());
}
catch(SecurityException syex)
{
log("SecurityException: " + syex.toString());
}
catch (Exception ex)
{
log("Exception: " + ex.toString());
}
}
public void messageReceivedHandler (TextMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
String receivedMessageBody = receivedMessage.getPayloadText();
log ("Text Message received: " + receivedMessageBody);
}
public void messageReceivedHandler (BinaryMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
byte[] receivedMessageBody = receivedMessage.getPayloadData();
log ("Binary Message received: " + receivedMessageBody.length + " bytes.");
}
public void listen (String MessageServerPort) {
try
{
con = (MessageConnection) Connector.open(
"sms://:" + MessageServerPort);
con.setMessageListener(this);
}
catch(Exception ex)
{
log("Exception during listen: " + ex.toString());
}
}
/* Default values, if there is nothing specified in the JAD file */
private static final String DefaultMIDletMessageAddress = "3300001:7500";
private static final String DefaultMIDletServerPort = "7500";
private static final String DefaultMIDletTextMessage = "Test message";
/* Constants */
private static final String MIDletMessageAddressAttribute =
new String ("Message-Address");
private static final String MIDletServerPortAttribute =
new String ("ServerPort");
private static final String MIDletMessageTextBodyAttribute =
new String ("Message-Text-Body");
private static final String MIDletBinaryMessageBodyFileAttribute =
new String ("Binary-Message-Body-File");
}
salut
MessageAddressField = new TextField("Address:", MessageAddress, 20, TextField.PHONENUMBER);
est-tu certain(e) que le constructeur de Textfield reçoive bien les arguments de type voulu ???
s'il reçoit une chaîne de caractère alors qu'il attend un entier ?
MessageAddressField = new TextField("Address:", MessageAddress, 20, TextField.PHONENUMBER);
est-tu certain(e) que le constructeur de Textfield reçoive bien les arguments de type voulu ???
s'il reçoit une chaîne de caractère alors qu'il attend un entier ?
Je ne sais pas si tu as essayé de déployer ce code sur netbeans, mais quand je mets TextField., je vois défiler la liste proposée des champs possibles, et PHONENUMBER y est aussi et est de type int.
voilà l'entièreté de l'erreur:
startApp threw an Exception
java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
at javax.microedition.lcdui.TextField.setChars(TextField.java:760)
at javax.microedition.lcdui.TextField.setString(TextField.java:666)
at javax.microedition.lcdui.TextField.<init>(TextField.java:630)
at WMAExample.startApp(WMAExample.java:189)
at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:43)
at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:374)
at com.sun.midp.main.Main.runLocalClass(Main.java:466)
at com.sun.midp.main.Main.main(Main.java:120)
startApp threw an Exception
java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
at javax.microedition.lcdui.TextField.setChars(TextField.java:760)
at javax.microedition.lcdui.TextField.setString(TextField.java:666)
at javax.microedition.lcdui.TextField.<init>(TextField.java:630)
at WMAExample.startApp(WMAExample.java:189)
at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:43)
at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:374)
at com.sun.midp.main.Main.runLocalClass(Main.java:466)
at com.sun.midp.main.Main.main(Main.java:120)
salut
c'est clair, aucun constructeur de Textfield ne correspond à ce que tu demandes
les voici
c'est clair, aucun constructeur de Textfield ne correspond à ce que tu demandes
les voici
TextField() Constructs a new text field. TextField(int columns) Constructs a new empty text field with the specified number of columns. TextField(String text) Constructs a new text field initialized with the specified text. TextField(String text, int columns) Constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the specified number of columns.