IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java ME Discussion :

JavaME : tester si un objet est null


Sujet :

Java ME

  1. #1
    Membre expert
    Avatar de ®om
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    2 815
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 2 815
    Points : 3 080
    Points
    3 080
    Par défaut JavaME : tester si un objet est null
    Salut,

    Voici un bout de code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    public class TestME extends MIDlet {
        protected void destoryApp(boolean unconditional) throws MIDletStateChangeException {}
        protected void pauseApp() {}
        protected void startApp() throws MIDletStateChangeException {
            Object o = new Object();
            boolean b = o != null;
            //Display.getDisplay(this).setCurrent(new MyCanvas());
        }
    }
    Ce code marche sur mon portable sans problème, mais sur les nokia et les sony ericson, il y a "erreur d'application" au démarrage.
    Si j'enlève le o != null, ça marche sur tous les téléphones.

    Plus généralement, dès que j'ai un boolean "unobjet == unautreobjet" dans mon code, ça fait erreur d'application sur les sony ericson.

    C'est assez génant de pas pouvoir comparer des objets quand même...

    Vous savez d'où ça peut venir?

  2. #2
    Membre expert
    Avatar de ®om
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    2 815
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 2 815
    Points : 3 080
    Points
    3 080
    Par défaut
    Ce comportement n'est présent que si je compile avec javac (par ant), si je compile avec eclipse et que je génère le jar avec ant ça marche (pour cet exemple mais pas pour tous)...

    Voici ma tâche ant de compilation:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <target name="compile" description="Compile the project">
        <mkdir="${build.dir}" />
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath" source="1.4" target="1.4" encoding="utf8" debug="true" />
    </target>

  3. #3
    Membre expert
    Avatar de ®om
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    2 815
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 2 815
    Points : 3 080
    Points
    3 080
    Par défaut
    Pourtant les 2 compilateurs génèrent les mêmes instructions :
    Par eclipse :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    $ javap -c test.TestME
    public class test.TestME extends javax.microedition.midlet.MIDlet{
    public test.TestME();
      Code:
       0:   aload_0
       1:   invokespecial   #8; //Method javax/microedition/midlet/MIDlet."<init>":()V
       4:   return
     
    protected void destroyApp(boolean)   throws javax.microedition.midlet.MIDletStateChangeException;
      Code:
       0:   return
     
    protected void pauseApp();
      Code:
       0:   return
     
    protected void startApp()   throws javax.microedition.midlet.MIDletStateChangeException;
      Code:
       0:   new     #17; //class java/lang/Object
       3:   dup
       4:   invokespecial   #19; //Method java/lang/Object."<init>":()V
       7:   astore_1
       8:   aload_1
       9:   ifnull  16
       12:  iconst_1
       13:  goto    17
       16:  iconst_0
       17:  istore_2
       18:  return
     
    }
    Par javac:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    $ javap -c test.TestME
    public class test.TestME extends javax.microedition.midlet.MIDlet{
    public test.TestME();
      Code:
       0:   aload_0
       1:   invokespecial   #1; //Method javax/microedition/midlet/MIDlet."<init>":()V
       4:   return
     
    protected void destroyApp(boolean)   throws javax.microedition.midlet.MIDletStateChangeException;
      Code:
       0:   return
     
    protected void pauseApp();
      Code:
       0:   return
     
    protected void startApp()   throws javax.microedition.midlet.MIDletStateChangeException;
      Code:
       0:   new     #2; //class java/lang/Object
       3:   dup
       4:   invokespecial   #3; //Method java/lang/Object."<init>":()V
       7:   astore_1
       8:   aload_1
       9:   ifnull  16
       12:  iconst_1
       13:  goto    17
       16:  iconst_0
       17:  istore_2
       18:  return
     
    }
    Et les binaires :
    Compilé avec eclipse:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    $ hexdump -C test/TestME.class
    00000000  ca fe ba be 00 00 00 2e  00 14 07 00 02 01 00 0b  |................|
    00000010  74 65 73 74 2f 54 65 73  74 4d 45 07 00 04 01 00  |test/TestME.....|
    00000020  20 6a 61 76 61 78 2f 6d  69 63 72 6f 65 64 69 74  | javax/microedit|
    00000030  69 6f 6e 2f 6d 69 64 6c  65 74 2f 4d 49 44 6c 65  |ion/midlet/MIDle|
    00000040  74 01 00 06 3c 69 6e 69  74 3e 01 00 03 28 29 56  |t...<init>...()V|
    00000050  01 00 04 43 6f 64 65 0a  00 03 00 09 0c 00 05 00  |...Code.........|
    00000060  06 01 00 0a 64 65 73 74  72 6f 79 41 70 70 01 00  |....destroyApp..|
    00000070  04 28 5a 29 56 01 00 0a  45 78 63 65 70 74 69 6f  |.(Z)V...Exceptio|
    00000080  6e 73 07 00 0e 01 00 34  6a 61 76 61 78 2f 6d 69  |ns.....4javax/mi|
    00000090  63 72 6f 65 64 69 74 69  6f 6e 2f 6d 69 64 6c 65  |croedition/midle|
    000000a0  74 2f 4d 49 44 6c 65 74  53 74 61 74 65 43 68 61  |t/MIDletStateCha|
    000000b0  6e 67 65 45 78 63 65 70  74 69 6f 6e 01 00 08 70  |ngeException...p|
    000000c0  61 75 73 65 41 70 70 01  00 08 73 74 61 72 74 41  |auseApp...startA|
    000000d0  70 70 07 00 12 01 00 10  6a 61 76 61 2f 6c 61 6e  |pp......java/lan|
    000000e0  67 2f 4f 62 6a 65 63 74  0a 00 11 00 09 00 21 00  |g/Object......!.|
    000000f0  01 00 03 00 00 00 00 00  04 00 01 00 05 00 06 00  |................|
    00000100  01 00 07 00 00 00 11 00  01 00 01 00 00 00 05 2a  |...............*|
    00000110  b7 00 08 b1 00 00 00 00  00 04 00 0a 00 0b 00 02  |................|
    00000120  00 0c 00 00 00 04 00 01  00 0d 00 07 00 00 00 0d  |................|
    00000130  00 00 00 02 00 00 00 01  b1 00 00 00 00 00 04 00  |................|
    00000140  0f 00 06 00 01 00 07 00  00 00 0d 00 00 00 01 00  |................|
    00000150  00 00 01 b1 00 00 00 00  00 04 00 10 00 06 00 02  |................|
    00000160  00 0c 00 00 00 04 00 01  00 0d 00 07 00 00 00 1f  |................|
    00000170  00 02 00 03 00 00 00 13  bb 00 11 59 b7 00 13 4c  |...........Y...L|
    00000180  2b c6 00 07 04 a7 00 04  03 3d b1 00 00 00 00 00  |+........=......|
    00000190  00                                                |.|
    00000191
    Compilé avec javac:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    $ hexdump -C test/TestME.class
    00000000  ca fe ba be 00 00 00 30  00 14 0a 00 05 00 0f 07  |.......0........|
    00000010  00 10 0a 00 02 00 0f 07  00 11 07 00 12 01 00 06  |................|
    00000020  3c 69 6e 69 74 3e 01 00  03 28 29 56 01 00 04 43  |<init>...()V...C|
    00000030  6f 64 65 01 00 0a 64 65  73 74 72 6f 79 41 70 70  |ode...destroyApp|
    00000040  01 00 04 28 5a 29 56 01  00 0a 45 78 63 65 70 74  |...(Z)V...Except|
    00000050  69 6f 6e 73 07 00 13 01  00 08 70 61 75 73 65 41  |ions......pauseA|
    00000060  70 70 01 00 08 73 74 61  72 74 41 70 70 0c 00 06  |pp...startApp...|
    00000070  00 07 01 00 10 6a 61 76  61 2f 6c 61 6e 67 2f 4f  |.....java/lang/O|
    00000080  62 6a 65 63 74 01 00 0b  74 65 73 74 2f 54 65 73  |bject...test/Tes|
    00000090  74 4d 45 01 00 20 6a 61  76 61 78 2f 6d 69 63 72  |tME.. javax/micr|
    000000a0  6f 65 64 69 74 69 6f 6e  2f 6d 69 64 6c 65 74 2f  |oedition/midlet/|
    000000b0  4d 49 44 6c 65 74 01 00  34 6a 61 76 61 78 2f 6d  |MIDlet..4javax/m|
    000000c0  69 63 72 6f 65 64 69 74  69 6f 6e 2f 6d 69 64 6c  |icroedition/midl|
    000000d0  65 74 2f 4d 49 44 6c 65  74 53 74 61 74 65 43 68  |et/MIDletStateCh|
    000000e0  61 6e 67 65 45 78 63 65  70 74 69 6f 6e 00 21 00  |angeException.!.|
    000000f0  04 00 05 00 00 00 00 00  04 00 01 00 06 00 07 00  |................|
    00000100  01 00 08 00 00 00 11 00  01 00 01 00 00 00 05 2a  |...............*|
    00000110  b7 00 01 b1 00 00 00 00  00 04 00 09 00 0a 00 02  |................|
    00000120  00 08 00 00 00 0d 00 00  00 02 00 00 00 01 b1 00  |................|
    00000130  00 00 00 00 0b 00 00 00  04 00 01 00 0c 00 04 00  |................|
    00000140  0d 00 07 00 01 00 08 00  00 00 0d 00 00 00 01 00  |................|
    00000150  00 00 01 b1 00 00 00 00  00 04 00 0e 00 07 00 02  |................|
    00000160  00 08 00 00 00 1f 00 02  00 03 00 00 00 13 bb 00  |................|
    00000170  02 59 b7 00 03 4c 2b c6  00 07 04 a7 00 04 03 3d  |.Y...L+........=|
    00000180  b1 00 00 00 00 00 0b 00  00 00 04 00 01 00 0c 00  |................|
    00000190  00                                                |.|
    00000191

  4. #4
    Membre expert
    Avatar de ®om
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    2 815
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 2 815
    Points : 3 080
    Points
    3 080
    Par défaut
    J'ai finalement identifié le problème.
    Certains téléphones veulent que le jar soit "prévérifié", donc j'ai utilisé antenna (un plugin pour ant) pour créer le jar (ce qui est important est preferify="true"):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    	<target name="deploy" description="Deploy the project" depends="compile">
    		<mkdir dir="${dist.dir}" />
    		<wtkjad jadfile="${dist.dir}/${jad.file}" jarfile="${dist.dir}/${jar.file}" name="${midlet.name}" vendor="${midlet.vendor}" version="${midlet.version}">
    			<midlet name="${midlet.name}" icon="${midlet.icon}" class="${midlet.class}" />
    		</wtkjad>
    		<wtkpackage basedir="${build.dir}" jarfile="${dist.dir}/${jar.file}" jadfile="${dist.dir}/${jad.file}" obfuscate="false" preverify="true">
    			<fileset dir="${inside.dir}" includes="**" />
    		</wtkpackage>
    	</target>

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 44
    Points : 49
    Points
    49
    Par défaut
    En fait, normalement ce sont tous les téléphones J2ME avec une configuration CLDC qui doivent exiger que le code soit prévérifié.

    Pour ces fameuses CLDC, la prévérification a été déportée côté poste de développement pour alléger le traitement côté appareil. Il est vrai que maitenant les téléphones sont des bêtes de course...

Discussions similaires

  1. Tester si un objet est "null"
    Par nicodn02 dans le forum Langages de programmation
    Réponses: 2
    Dernier message: 19/12/2011, 16h10
  2. Tester si un objet est null
    Par methodman225 dans le forum JPA
    Réponses: 2
    Dernier message: 04/02/2009, 10h02
  3. Réponses: 1
    Dernier message: 02/10/2007, 10h12
  4. [C#]Question bête : Comment tester si un objet est créer?
    Par ben_ghost dans le forum Windows Forms
    Réponses: 5
    Dernier message: 08/08/2006, 20h50
  5. Tester si un champ est NULL
    Par titititi007 dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 19/06/2003, 10h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo