Java: creation d'objet impossible
david
-
Adrien -
Adrien -
Bonjour,
je programme en java.
Quand je veux creer le nouvelle objet
ATCommand atc = new ATCommand;
je sors de la méthode ou je suis. pourtant il n'y a pas de message d'erreur.
j'utilise le bon package et je gére les exceptions.
quelqu'un aurait il une idée
merci d'avance
je programme en java.
Quand je veux creer le nouvelle objet
ATCommand atc = new ATCommand;
je sors de la méthode ou je suis. pourtant il n'y a pas de message d'erreur.
j'utilise le bon package et je gére les exceptions.
quelqu'un aurait il une idée
merci d'avance
A voir également:
- Java: creation d'objet impossible
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Eclipse java - Télécharger - Langages
9 réponses
Bonjour!
En java, quand tu utilises le mot clé new, il doit être suivit par un appel à une fonction. Il manque donc les () à la fin:
En java, quand tu utilises le mot clé new, il doit être suivit par un appel à une fonction. Il manque donc les () à la fin:
ATCommand atc = new ATCommand();
excusez moi
mais en faite g bien mis ATCommand atc = new ATCommand (true);
l'erreur ne viens pas de la
mais merci qd meme
mais en faite g bien mis ATCommand atc = new ATCommand (true);
l'erreur ne viens pas de la
mais merci qd meme
voici le code
sachant que das une autre class je fais
Modem modem = new Modem(pin, gprsNameServer, gprsApn, gprsUser, gprsPass);
Et oui ya pas mal de chance que l'erreur vienne de lacar qd je mets des print ca les saute
package example.gprs;
import com.siemens.icm.io.*;
/**
* Modem is a modem.
*/
class Modem
{
/**
* Constructs a modem.
*
* @param pin PIN
* @param nameServer IP address of GPRS name server; may be null
* @param apn GPRS Access Point Name (APN)
* @param user GPRS user name
* @param pass GPRS password
*
* @throws ATCommandFailedException
*/
Modem(String pin, String nameServer, String apn, String user, String pass)
throws ATCommandFailedException
{ System.out.println("debut modem");
ATCommand atc;
atc = new ATCommand(true);
System.out.println("toto");
/* Set pin */
setPin(pin);
/* Setup GPRS */
String command = "AT^SJNET=gprs," + apn + "," + user + "," + pass;
if (nameServer != null)
command += "," + nameServer;
System.out.println("envoi" + command);
//String response = atc.send(command + "\r");
//System.out.println("reponse" + response);
//if (response.indexOf("ERROR") >= 0)
// throw new ATCommandFailedException(command + ": " + response);
}
/**
* Sets PIN.
*
* @throws ATCommandFailedException
*/
private void setPin(String pin) throws ATCommandFailedException
{
String response;
ATCommand atc = new ATCommand(false);
/* Check PIN state */
response = atc.send("AT+CPIN?\r");
System.out.println("reponse" + response);
/* Ready */
if (response.indexOf("+CPIN: READY") >= 0)
return;
/* PIN required */
if (response.indexOf("+CPIN: SIM PIN") >= 0) {
response = atc.send("AT+CPIN=" + pin + "\r");
if (response.indexOf("ERROR") >= 0)
throw new ATCommandFailedException(response);
}
/* PUK required */
else if (response.indexOf("PUK") >= 0)
throw new ATCommandFailedException(response);
/* Probably SIM card missing... */
else
throw new ATCommandFailedException(response +
" SIM card missing ?");
}
}
sachant que das une autre class je fais
Modem modem = new Modem(pin, gprsNameServer, gprsApn, gprsUser, gprsPass);
Et oui ya pas mal de chance que l'erreur vienne de lacar qd je mets des print ca les saute
package example.gprs;
import com.siemens.icm.io.*;
/**
* Modem is a modem.
*/
class Modem
{
/**
* Constructs a modem.
*
* @param pin PIN
* @param nameServer IP address of GPRS name server; may be null
* @param apn GPRS Access Point Name (APN)
* @param user GPRS user name
* @param pass GPRS password
*
* @throws ATCommandFailedException
*/
Modem(String pin, String nameServer, String apn, String user, String pass)
throws ATCommandFailedException
{ System.out.println("debut modem");
ATCommand atc;
atc = new ATCommand(true);
System.out.println("toto");
/* Set pin */
setPin(pin);
/* Setup GPRS */
String command = "AT^SJNET=gprs," + apn + "," + user + "," + pass;
if (nameServer != null)
command += "," + nameServer;
System.out.println("envoi" + command);
//String response = atc.send(command + "\r");
//System.out.println("reponse" + response);
//if (response.indexOf("ERROR") >= 0)
// throw new ATCommandFailedException(command + ": " + response);
}
/**
* Sets PIN.
*
* @throws ATCommandFailedException
*/
private void setPin(String pin) throws ATCommandFailedException
{
String response;
ATCommand atc = new ATCommand(false);
/* Check PIN state */
response = atc.send("AT+CPIN?\r");
System.out.println("reponse" + response);
/* Ready */
if (response.indexOf("+CPIN: READY") >= 0)
return;
/* PIN required */
if (response.indexOf("+CPIN: SIM PIN") >= 0) {
response = atc.send("AT+CPIN=" + pin + "\r");
if (response.indexOf("ERROR") >= 0)
throw new ATCommandFailedException(response);
}
/* PUK required */
else if (response.indexOf("PUK") >= 0)
throw new ATCommandFailedException(response);
/* Probably SIM card missing... */
else
throw new ATCommandFailedException(response +
" SIM card missing ?");
}
}
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Class ATCommand
java.lang.Object
extended bycom.siemens.icm.io.ATCommand
public class ATCommand
extends Object
The ATCommand class supports the execution of AT commands on the same way as it would be done throug a serial interface. It provides a simple way to send strings directly to the device's AT-Interpreters. Because the device might provide more than one AT-Interpreter at the same time instances of this class can be connected to the several AT-Channels of the device. Because the instances of this ATCommand class are connected directly to the different AT parsers inside the module there are only exactly as much instances possible as the module provides AT interpreters. Trying to create more instances of this class will cause the constructor to fail. Because the different AT-Channels of the device might have different capabilities these capabilities can be queried (Fax, Data-Transfers). It might be possible (or better be probable) that there is e.g. only one instance with CSD capabilities available. Additional a callback class for unsolicited AT-Events (URCs) can be registered.
Please be aware that corresponding to the setting made by the "AT+CSCS" command the string parameters of several AT commands has to be passed in the GSM or UCS2 character set and the responses might contain strings in that character set as well. The ATCommand class does no string conversion at all which means that all converting between Java strings and GSM respectively UCS2 strings has to be done by the application itself in both directions. For easy conversion between the different character sets the class ATStringConversion can be used.
To be able to deal with data connections created by this class e.g. by using the ATD command there are member variables for input and output streaming from and to data connections which are accessible via the getDataOutput() and getDataInputStream() functions. If the module is in transparent data mode (a data connection is active) the call of the send functions is forbidden and will cause an IllegalStateException.
For performance reasons there is no synchronization done in this class. If an instance of this class has to be accessed from different threads it has to be ensured that the send() functions, the release() function, the cancelCommand() function and the breakConnection() function are synchronized in the user implementation.
Currently the maximal possible length of AT commands passed via the send() methods is 815 characters, including the line feed.
See Also:
ATCommandListener, ATCommandResponseListener, ATStringConverter
Constructor Summary
ATCommand(boolean csdSupport)
Creates a new instance of the ATCommand class.
Method Summary
void addListener(ATCommandListener listener)
Registers listeners to receive unsolicited AT-Events (URCs).
String breakConnection()
This function switches the module back from transparent data mode to AT command mode.
void cancelCommand()
Cancel a running AT command.
boolean csdSupported()
Get information if the connected AT-Interpreter is able to handle CSD connections.
InputStream getDataInputStream()
This function returns the input stream for data connections.
OutputStream getDataOutputStream()
This function returns the output stream for data connections.
boolean getDCD()
Get the state of the DCD (Data Carrier Detect) signal of the devices AT channel.
boolean getDSR()
Get the state of the DSR (Data Set Ready) signal of the devices AT channel.
boolean getRING()
Get the state of the RING signal of the devices AT channel.
void release()
Release resources locked by the ATCommand class.
void removeListener(ATCommandListener listener)
Removes a listener object which has been previously added from the internal list table of listener objects.
String send(String ATCmd)
Send an AT command to the device.
void send(String ATCmd, ATCommandResponseListener response)
Send an AT command to the device.
void setDTR(boolean SignalState)
Set the state of the DTR (Data Terminal Ready) signal of the devices AT channel.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
ATCommand
public ATCommand(boolean csdSupport)
throws ATCommandFailedException,
IllegalStateException
Creates a new instance of the ATCommand class. If there are no more instances possible or if it is not possible to provide possibly requested CSD support the constructor will fail with an exception.
Please note that the instance of the ATCommand class is opened in the state it was possibly released before. If it was released while it e.g. was waiting for the text of a SMS to be sent it might still be waiting for this SMS text after creation of a new instance.
Parameters:
csdSupport - A flag indicating if the instance of this class should have CSD support or not. It might be possible that there is an instance with CSD support created, even if it wasn't requested if there are only instances with CSD support available. But it can never happen that there is CSD support requested and an instance without created. If CSD support is requested and there is no instance with CSD available an IllegalStateException will be thrown.
Throws:
IllegalStateException - if there isn't any instance of the AT interpreter with the requested capabilities available.
ATCommandFailedException - if the connection to the AT-Interpreter fails because of some internal reasons (e.g. because the virtual COM port cannot be opened in the PC emulator).
See Also:
ATCommandListener
java.lang.Object
extended bycom.siemens.icm.io.ATCommand
public class ATCommand
extends Object
The ATCommand class supports the execution of AT commands on the same way as it would be done throug a serial interface. It provides a simple way to send strings directly to the device's AT-Interpreters. Because the device might provide more than one AT-Interpreter at the same time instances of this class can be connected to the several AT-Channels of the device. Because the instances of this ATCommand class are connected directly to the different AT parsers inside the module there are only exactly as much instances possible as the module provides AT interpreters. Trying to create more instances of this class will cause the constructor to fail. Because the different AT-Channels of the device might have different capabilities these capabilities can be queried (Fax, Data-Transfers). It might be possible (or better be probable) that there is e.g. only one instance with CSD capabilities available. Additional a callback class for unsolicited AT-Events (URCs) can be registered.
Please be aware that corresponding to the setting made by the "AT+CSCS" command the string parameters of several AT commands has to be passed in the GSM or UCS2 character set and the responses might contain strings in that character set as well. The ATCommand class does no string conversion at all which means that all converting between Java strings and GSM respectively UCS2 strings has to be done by the application itself in both directions. For easy conversion between the different character sets the class ATStringConversion can be used.
To be able to deal with data connections created by this class e.g. by using the ATD command there are member variables for input and output streaming from and to data connections which are accessible via the getDataOutput() and getDataInputStream() functions. If the module is in transparent data mode (a data connection is active) the call of the send functions is forbidden and will cause an IllegalStateException.
For performance reasons there is no synchronization done in this class. If an instance of this class has to be accessed from different threads it has to be ensured that the send() functions, the release() function, the cancelCommand() function and the breakConnection() function are synchronized in the user implementation.
Currently the maximal possible length of AT commands passed via the send() methods is 815 characters, including the line feed.
See Also:
ATCommandListener, ATCommandResponseListener, ATStringConverter
Constructor Summary
ATCommand(boolean csdSupport)
Creates a new instance of the ATCommand class.
Method Summary
void addListener(ATCommandListener listener)
Registers listeners to receive unsolicited AT-Events (URCs).
String breakConnection()
This function switches the module back from transparent data mode to AT command mode.
void cancelCommand()
Cancel a running AT command.
boolean csdSupported()
Get information if the connected AT-Interpreter is able to handle CSD connections.
InputStream getDataInputStream()
This function returns the input stream for data connections.
OutputStream getDataOutputStream()
This function returns the output stream for data connections.
boolean getDCD()
Get the state of the DCD (Data Carrier Detect) signal of the devices AT channel.
boolean getDSR()
Get the state of the DSR (Data Set Ready) signal of the devices AT channel.
boolean getRING()
Get the state of the RING signal of the devices AT channel.
void release()
Release resources locked by the ATCommand class.
void removeListener(ATCommandListener listener)
Removes a listener object which has been previously added from the internal list table of listener objects.
String send(String ATCmd)
Send an AT command to the device.
void send(String ATCmd, ATCommandResponseListener response)
Send an AT command to the device.
void setDTR(boolean SignalState)
Set the state of the DTR (Data Terminal Ready) signal of the devices AT channel.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
ATCommand
public ATCommand(boolean csdSupport)
throws ATCommandFailedException,
IllegalStateException
Creates a new instance of the ATCommand class. If there are no more instances possible or if it is not possible to provide possibly requested CSD support the constructor will fail with an exception.
Please note that the instance of the ATCommand class is opened in the state it was possibly released before. If it was released while it e.g. was waiting for the text of a SMS to be sent it might still be waiting for this SMS text after creation of a new instance.
Parameters:
csdSupport - A flag indicating if the instance of this class should have CSD support or not. It might be possible that there is an instance with CSD support created, even if it wasn't requested if there are only instances with CSD support available. But it can never happen that there is CSD support requested and an instance without created. If CSD support is requested and there is no instance with CSD available an IllegalStateException will be thrown.
Throws:
IllegalStateException - if there isn't any instance of the AT interpreter with the requested capabilities available.
ATCommandFailedException - if the connection to the AT-Interpreter fails because of some internal reasons (e.g. because the virtual COM port cannot be opened in the PC emulator).
See Also:
ATCommandListener