title: gridview setOnItemClickListener not working
body: <p>I'm using a gridview to display numbers,
  I want the next activity, 
  when i click on any  number
  but when i click on the n number nothing happens there is no error in logcat nor any force close.</p>
  
  <p>Here is the code</p>
  
  <pre><code>public class CActivity extends Activity 
  {
    GridView gridView; 
  
     public void onCreate(Bundle savedInstanceState) 
              {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.cactivity);
  
               gridView.setOnItemClickListener(new OnItemClickListener()
              {
                public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                  int position, long id) {
  
              Intent myIntent = new Intent(getApplicationContext(), Abc.class);
              startActivity(myIntent);
              //finish();
          }
      });
  }
         private void initComponent() 
         {
           gridView = (GridView) findViewById(R.id.month_gridView);
           }
  </code></pre>
  
  <p>I don't know what the problem is but <code>gridView.setAdapter(adapter);</code> is working.  plz help</p>
  
  <pre><code> gridView.setAdapter(adapter);
  </code></pre>
  
  <p>If i use </p>
  
  <pre><code>  GridView gridView = (GridView) findViewById(R.id.month_gridView);
  </code></pre>
  
  <p>then the app force closes</p>
  
  <p>logcat</p>
  
  <pre><code>02-07 21:10:12.721: W/dalvikvm(719): threadid=1: thread exiting with uncaught exception (group=0x40015560)
  02-07 21:10:12.780: E/AndroidRuntime(719): FATAL EXCEPTION: main
  02-07 21:10:12.780: E/AndroidRuntime(719): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.indianic.demo.calendark/com.indianic.demo.calendark.CalendarActivity}: java.lang.NullPointerException
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.os.Handler.dispatchMessage(Handler.java:99)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.os.Looper.loop(Looper.java:123)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.app.ActivityThread.main(ActivityThread.java:3683)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at java.lang.reflect.Method.invokeNative(Native Method)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at java.lang.reflect.Method.invoke(Method.java:507)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at dalvik.system.NativeStart.main(Native Method)
  02-07 21:10:12.780: E/AndroidRuntime(719): Caused by: java.lang.NullPointerException
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.app.Activity.findViewById(Activity.java:1647)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at com.indianic.demo.calendark.CalendarActivity.&lt;init&gt;(CalendarActivity.java:44)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at java.lang.Class.newInstanceImpl(Native Method)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at java.lang.Class.newInstance(Class.java:1409)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
  02-07 21:10:12.780: E/AndroidRuntime(719):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
  02-07 21:10:12.780: E/AndroidRuntime(719):  ... 11 more
  02-07 21:10:18.061: I/Process(719): Sending signal. PID: 719 SIG: 9
  </code></pre>
  
  <p>I used initComponent() method before setting setOnItemClickListener() </p>
  
  <p>the force close error is gone and app opens normally, </p>
  
  <p>But the next activity is not opening or nothing happens.when i click on the items.
  :(</p>
  
  <p>AS you said i tried different cases,Still no success</p>
  
  <pre><code>              public void onItemClick(AdapterView&lt;?&gt; parent, View v3,
                  int position, long id) {
  
  
              //setContentView(R.layout.abc);
              switch (position) {
              case 0:
                  Intent myIntent = new Intent(getApplicationContext(),Abc.class);
                  startActivity(myIntent);
                  break;
              case 1:
                  Intent myIntent1 = new Intent(getApplicationContext(),Abc.class);
                  startActivity(myIntent1);
                  break;
              case 2:
                  Intent myIntent2 = new Intent(getApplicationContext(),Abc.class);
                  startActivity(myIntent2);
                  break;
              case 3:
                  Intent myIntent3 = new Intent(getApplicationContext(),Abc.class);
                  startActivity(myIntent3);
                  break;
              case 4:
                  Intent myIntent4 = new Intent(getApplicationContext(),Abc.class);
                  startActivity(myIntent4);
                  break;
              case 5:
                  Intent myIntent5 = new Intent(getApplicationContext(),Abc.class);
                  startActivity(myIntent5);
                  break;
              case 6:
                  Intent myIntent6 = new Intent(getApplicationContext(),Abc.class);
                  startActivity(myIntent6);
                  break;
  
              default:
                  break;
              }
            }
  
      });
  </code></pre>