Results 1 to 3 of 3
  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Date from a image

    Hi,

    I have this line in my code to get the date taken from a image:

    Java Code:
    Date digiDate  = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED);
    It works great if there is a date in this field, however if the date is empty, I get a null pointer exeption.
    I have tried with different variants of if/else, but no success.
    Any suggestions?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default Re: Date from a image

    Wrap your code in a try { ... } catch block and handle the NPE.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Date from a image

    Thanks! Changed my code to this:
    Java Code:
    Date digiDate = null;
                    try {
                    digiDate  = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED);
                    }catch(Exception ex){
                        long d             = file.lastModified();
                        java.sql.Date date = new java.sql.Date(d);
                        digiDate           = date;
                                
                    }
    So if theres no digital date, it gets the filedate.
    Works nice! :)

Similar Threads

  1. Replies: 5
    Last Post: 02-16-2012, 09:26 AM
  2. Replies: 4
    Last Post: 07-27-2011, 11:57 AM
  3. Replies: 2
    Last Post: 05-12-2011, 04:52 PM
  4. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  5. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM

Posting Permissions

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