title: Unable to instantiate activity ComponentInfo for wallpaper app
body: <p>I was trying to do a wallpaper application.I am all done but every time i open the app its crashes.</p>
  
  <p>This is my Activity</p>
  
  <pre><code>package com.wallpaper.rahuldravid;
  
  public class MainActivity extends Activity  {
          Integer [] pics= {
              R.drawable.sunset,
              R.drawable.winter
  
  };
  ImageView imageView= (ImageView)findViewById(R.id.ImageView01);;
  
  
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Gallery ga = (Gallery)findViewById(R.id.Gallery01);
  ga.setAdapter(new ImageAdapter(this));
  
  
  ga.setOnItemClickListener(new OnItemClickListener() {
  
      public void onItemClick(AdapterView&lt;?&gt; parent, View v, final int pos,long id) {
          Toast.makeText(v.getContext(), "You have selected picture " + (pos+1) +"of Rd", 
              Toast.LENGTH_SHORT).show();
          imageView.setImageResource(pics[pos]);
          imageView.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              WallpaperManager wm = WallpaperManager.getInstance(v.getContext());
              try {
                  wm.setResource(pics[pos]);
              } catch (IOException e) {
                  e.printStackTrace();
              }
            }
          });
      }
  });
  
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
   public class ImageAdapter extends BaseAdapter {
  
  private Context ctx;
  int imageBackground;
  
  public ImageAdapter(Context c) {
          ctx = c;
          TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
          imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
          ta.recycle();
      }
  
  
  public int getCount() {
  
      return pics.length;
  }
  
  
  public Object getItem(int arg0) {
  
      return arg0;
  }
  
  
  public long getItemId(int arg0) {
  
      return arg0;
  }
  
  
  public View getView(int arg0, View arg1, ViewGroup arg2) {
      ImageView iv = new ImageView(ctx);
      iv.setImageResource(pics[arg0]);
      iv.setScaleType(ImageView.ScaleType.FIT_XY);
      iv.setLayoutParams(new Gallery.LayoutParams(200,120));
      iv.setBackgroundResource(imageBackground);
      return iv;
  }
  </code></pre>
  
  <p>}
  }</p>
  
  <p>this is my manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.wallpaper.rahuldravid"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="7"
          android:targetSdkVersion="17" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
  
      &lt;/application&gt;
      &lt;uses-permission android:name="android.permission.SET_WALLPAPER" /&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>This is the logcat :</p>
  
  <pre><code>05-22 19:30:21.008: D/AndroidRuntime(30838): Shutting down VM
  05-22 19:30:21.008: W/dalvikvm(30838): threadid=1: thread exiting with uncaught exception (group=0x40a9f210)
  05-22 19:30:21.038: E/AndroidRuntime(30838): FATAL EXCEPTION: main
  05-22 19:30:21.038: E/AndroidRuntime(30838): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.wallpaper.rahuldravid/com.wallpaper.rahuldravid.MainActivity}: java.lang.NullPointerException
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.os.Handler.dispatchMessage(Handler.java:99)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.os.Looper.loop(Looper.java:137)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.app.ActivityThread.main(ActivityThread.java:4441)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at java.lang.reflect.Method.invokeNative(Native Method)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at java.lang.reflect.Method.invoke(Method.java:511)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at dalvik.system.NativeStart.main(Native Method)
  05-22 19:30:21.038: E/AndroidRuntime(30838): Caused by: java.lang.NullPointerException
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.app.Activity.findViewById(Activity.java:1794)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at com.wallpaper.rahuldravid.MainActivity.&lt;init&gt;(MainActivity.java:28)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at java.lang.Class.newInstanceImpl(Native Method)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at java.lang.Class.newInstance(Class.java:1319)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
  05-22 19:30:21.038: E/AndroidRuntime(30838):    ... 11 more
  </code></pre>
  
  <p>I have searched all over and the solution i found mostly was to make sure the activity name is right in the code and the manifest.As you can see its correct. Can you please help me out with this??</p>