Global variables?

Put your problem here if it does not fit any of the other categories.

Global variables?

Postby jones » Thu Oct 22, 2009 2:57 pm

hi all together,

i have a serious problem with variables over different functions within the same class:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class HelloWidget extends AppWidgetProvider {
  2.  
  3.         private static final String TAG = "HelloWidget";
  4.  
  5.         public String timer;
  6.  
  7.  
  8.  
  9.         public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
  10.  
  11.                 Log.d(TAG, "onUpdate");        
  12.  
  13.                 this.timer = "yeahh";
  14.  
  15.         }
  16.  
  17.        
  18.  
  19.         public void onDeleted(Context context, int[] appWidgetIds) {
  20.  
  21.                 Log.d(TAG, "onDeleted");
  22.  
  23.                 Log.d(TAG, this.timer);
  24.  
  25.         }
  26.  
  27.        
  28.  
  29. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

This piece of code throws a NullPointerException at line
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Log.d(TAG, this.timer);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4

I am wondering why it is so difficult to declare variables globally. Am I just used to too different programming languages?

Where is my mistake?

Thanks and cheers
Jonas
jones
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Oct 22, 2009 2:49 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests