Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default getImplementationVersion() returns null

    Dear All.

    How to get version (major.minor.rivision)?

    I tried codes below.. but it returns null..

    Java Code:
    private String getAppVersion() {
             Package p = this.getClass().getPackage();
             return p.getImplementationVersion();
    }

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    I am no expert but from my basic java skills I am thinking
    Java Code:
    ImplementationVersion();
    was never set to anything

  3. #3
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    The API on getImplementationVersion should tell you why it's returning null. You will probably want to add in your code a case where this is null and return a custom value instead.

    Oddly, some versions of Java seem to have a bug in them; you can read more from my Google search here.

    PS: One of these two links should help in the case that you are just searching for the Java version.

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    null is returned if it is not known.

    is Package implemented correctly?

  5. #5
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    His method should work. However, he could loop through all known packages instead...
    Java Code:
    Package[] localPackages = Package.getPackages();
    for (int i = 0; i < localPackages.length; i++) {
        // ...
    }

  6. #6
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    Q: is Package implemented correctly?

    A: I am not sure with the question..

    I just run it from NetBeans (6.9) IDE..

    my project -> Source Packages -> (default package)

  7. #7
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    Hi Zack,

    What I meant here is my application version (major.minor.revision) ..

  8. #8
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Try the loop in my second post, checking localPackages[i] for its implementation version. I'm not sure exactly how you've set your application version in the package itself.

  9. #9
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    Did not find my application package name

  10. #10
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    What's your output if you run this?
    Java Code:
    	Package[] localPackages = Package.getPackages();
    	String[] packageNames = new String[localPackages.length];
    	for (int i = 0; i < localPackages.length; i++) {
    		packageNames[i] = localPackages[i].toString();
    	}
    	Arrays.sort(packageNames);
    	for (int i = 0; i < packageNames.length; i++) {
    		if (!packageNames[i].contains("Java Platform API"))
    			System.out.println(packageNames[i]);
    	}
    PS: How are you setting the version number?
    Last edited by Zack; 09-11-2010 at 04:29 AM.

  11. #11
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    it only returns:

    package com.mysql.jdbc
    package com.mysql.jdbc.exceptions
    package com.mysql.jdbc.log
    package com.mysql.jdbc.util
    package com.sun.mail.util, JavaMail(TM) API Design Specification, version 1.4
    package gnu.io
    package javax.mail, JavaMail(TM) API Design Specification, version 1.4
    package javax.mail.internet, JavaMail(TM) API Design Specification, version 1.4
    package org.netbeans.lib.awtextra

  12. #12
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    It's not even finding your package at all...

    Alright, let's take a look at something else. How are you setting the version number that you want to appear?

  13. #13
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    Hi.. I didnot find manifest.mf file.. does it cause this problem?

    My NetBeans 6.9 .. does not automatically generate it when it rebuilt

  14. #14
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Are you sure there's no manifest.mf file? Where are you looking?

  15. #15
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    yes, I did not find manifest.mf file ..
    I look into \dist folder..

    Netbeans does not automatically generate it..
    any idea?

  16. #16
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    The manifest.mf file won't be in the \dist\ directory. It should be the one above it, the one that is named after your project. (The folder that contains build, dist, src, and so on.)

  17. #17
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    yes, I also have searched in \src \build\ .. and I did not find it..

  18. #18
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    I think I'd best let Norm or Fubarable or another senior member take this thread over from me. If there's no manifest file I'm not sure how to force-generate it (except to create it yourself, which you could do if you follow this little documentation).

  19. #19
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    Hi Zack,

    Ok, it seems like my project was corrupted, I recreate the project and I found manifest.mf now!..

    I tried your codes.. and now I found my package name..
    but I still unable to get the version information..

    my manifest.mf ..contained:

    Java Code:
    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build
    what I missed?

  20. #20
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Give this documentation a try, it's the full official docs on setting up a manifest file for Package Versioning.

Page 1 of 2 12 LastLast

Similar Threads

  1. .DAY_OF_WEEK always returns 7
    By shurgs in forum New To Java
    Replies: 2
    Last Post: 08-20-2010, 02:32 PM
  2. Replies: 1
    Last Post: 08-20-2010, 11:30 AM
  3. helpset findHelpSet returns null
    By kmm1977 in forum AWT / Swing
    Replies: 23
    Last Post: 06-22-2010, 03:53 PM
  4. Carriage Returns in JTEXTAREA
    By AJArmstron@aol.com in forum Advanced Java
    Replies: 8
    Last Post: 04-17-2010, 07:34 PM
  5. What's the need for co-variant returns ?
    By ajeeb in forum New To Java
    Replies: 0
    Last Post: 03-23-2009, 09:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •