Hi Pedro,

Could you please check if the currentlocation is not NULL. If this is null
you will see a null pointer exception when you are trying to get latitude
and longitude out of it.

Thanks

On Sat, Sep 17, 2011 at 8:30 PM, Pedro Teixeira
<[email protected]>wrote:

> Hello there, hope you can help me somehow. I've got this class example
> which used to work just fine. Basiclly it just writes to the sd card a
> log file with some of my device information.
>
> public class LogToSD
>        {
>            static PrintWriter outFile = null;
>
>            private static void initialize()
>            {
>                try {
>                    File root = Environment.getExternalStorageDirectory();
>                    if( root.canWrite() )
>                    {
>                        Calendar rightNow = Calendar.getInstance();
>                        long day = rightNow.get( Calendar.DAY_OF_YEAR );
>                        long hour = rightNow.get( Calendar.HOUR_OF_DAY );
>                        long minutes = rightNow.get( Calendar.MINUTE );
>                        long seconds = rightNow.get( Calendar.SECOND );
>
>                        String date = +day + "d_" + hour + "h-" + minutes +
> "m-" + seconds + "s";
>
>                        File gpxfile = new File( root, "ThenNnow_" + date +
> ".log" );
>                        FileWriter gpxwriter = new FileWriter( gpxfile );
>                        outFile = new PrintWriter( gpxwriter );
>                        outFile.write( "\n\n----- THEN-N-NOW USER TESTING
> LOG
> -----\n" );
>                        outFile.write( "----- INITIAL TIME (dd_hh-mm-ss): "
> +
> date + " -----\n\n" );
>                    }
>                } catch (IOException e) {
>                    Log.e( "LogToSD", "Could not write to file: " +
> e.getMessage());
>                }
>            }
>
>            public static void write( String text1, String text2 )
>            {
>                if( outFile == null )
>                    initialize();
>
>                Calendar rightNow = Calendar.getInstance();
>                long minutes = rightNow.get( Calendar.MINUTE );
>                long seconds = rightNow.get( Calendar.SECOND );
>                long ms = rightNow.get( Calendar.MILLISECOND );
>
>                String time = minutes + ":" + seconds + "." + ms;
>
>                outFile.write( time + "\t" + text1 + ": " + text2 + "\n" );
>                outFile.flush();
>
>                Log.v( "LogToSD", text1 + " " + text2 );
>            }
>
>            public static void shutdown()
>            {
>                if( outFile != null )
>                    outFile.close();
>            }
>        }
>
> In my main activity this method is called like this:
>          if (ar.equals("1")){
>                          LogToSD.write("AR:", "User Location (Latitude:"+
> (currentlocation.getLatitude() * 1E6)+", Longitude:"+
> (currentlocation.getLongitude() * 1E6)+")");
>                          }else{
>                          LogToSD.write("Normal:", "User Location
> (Latitude:"+
> (currentlocation.getLatitude() * 1E6)+", Longitude:"+
> (currentlocation.getLongitude() * 1E6)+")");
>                          }
>
> This was working just fine and now I'm getting a  NullPointerException
> which I have no idea where it came from but it points to this lines of
> code in the main activity which I just pasted before. Can someone
> please help?
>
> 09-17 15:53:03.075: ERROR/AndroidRuntime(921): Uncaught handler:
> thread main exiting due to uncaught exception
> 09-17 15:53:03.215: ERROR/AndroidRuntime(921):
> java.lang.NullPointerException
> 09-17 15:53:03.215: ERROR/AndroidRuntime(921):     at
> com.pedroteixeira.thennnow.LogToSD.write(LogToSD.java:53)
>
> Thank you very much for your help.
>
> Pedro
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to