App not launching and get crashed when using the imagebutton in android
<p>I  just started to develop my first application in android.</p>

<p>Here i used a image button.</p>

<p>But when i try to run my app in device it is not launching a an errors are showing in the log cat.</p>

<p>can any one please help me in how to resolve this error.Thanks in advance.Hoping for your help.</p>

<p>This is the code i used:</p>

<pre><code>ArraysActivity.java

package com.me.array;
//import com.sweans.pus.SingleListItem;

//import com.sweans.pus.SecondScreen;


//import com.me.array.R;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView;

public class ArraysActivity extends Activity {
        ListView listView;
         private  ImageButton mybtn;
        ArrayAdapter&lt;String&gt; adapter;

        String[] sujith =new String[]{ "The-Birth", "Menu", "Album",
                        "Events", "Blog", "Press", "Reservation", "MONOMANIA",
                        "Contact" };
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mybtn = (ImageButton)findViewById(R.id.imgbtn);
        mybtn.setOnClickListener(new OnClickListener(){

            public void onClick(View v) {
                Intent nextScreen = new Intent(getApplicationContext(), ZActivity.class);
                startActivity(nextScreen);
            }
        });




         listView = (ListView) findViewById(R.id.mylist);
        adapter = new ArrayAdapter&lt;String&gt;(this,
                                android.R.layout.simple_list_item_1, android.R.id.text1, sujith);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new OnItemClickListener() {

         public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long id) {
           //   Intent nextScreen = new Intent(getApplicationContext(), SingleListItem.class);
              // startActivity(new Intent(action));
                 if(position == 0){
                 Intent i = new Intent(ArraysActivity.this, SingleListItem.class);

                 // passing variable
                 i.putExtra("my.package.dataToPass","new");
          //i.putExtra( "int",position);

                 startActivity(i);
                 }
                 else   if(position == 1){
                         Intent i = new Intent(ArraysActivity.this, ListSample.class);

                startActivity(i);
                         }

                 else   if(position == 2){
                         Intent i = new Intent(ArraysActivity.this, MyGridView.class);

                startActivity(i);
                         }
                else    if(position == 4){
                         Intent i = new Intent(ArraysActivity.this, MessageList.class);

                startActivity(i);
                         }
           }
       });
    }
}

main.xml

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" &gt;

   &lt;!--  &lt;ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="278dp"
        android:scaleType="fitXY"
        android:src="@drawable/home_page" /&gt; --&gt;

    &lt;ImageButton
       android:id="@+id/imgbtn"
        android:layout_width="fill_parent"
        android:layout_height="278dp"
        android:scaleType="fitXY"
        android:src="@drawable/home_page"
        android:contentDescription="@string/desc"/&gt;

    &lt;ListView
        android:id="@+id/mylist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" &gt;

    &lt;/ListView&gt;

&lt;/LinearLayout&gt;


Androidmanifest.xml

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.me.array"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-sdk android:minSdkVersion="7" /&gt;

    &lt;application
        android:icon="@drawable/icon_andro"
        android:label="@string/app_name" &gt;
        &lt;activity
            android:name=".ArraysActivity"
            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;activity android:name=".SingleListItem"&gt;&lt;/activity&gt;
              &lt;activity android:name=".menu"&gt;&lt;/activity&gt;
              &lt;activity android:name=".ListSample"&gt;&lt;/activity&gt;
              &lt;activity android:name=".SeperatedListAdapter"&gt;&lt;/activity&gt;
              &lt;activity android:name=".MyGridView"&gt;&lt;/activity&gt;
                 &lt;activity android:name=".Message"&gt;&lt;/activity&gt;
                    &lt;activity android:name=".MessageList"&gt;&lt;/activity&gt;
                 &lt;activity android:name=".BaseFeedParser"&gt;&lt;/activity&gt;
                 &lt;activity android:name=".SeparatedListAdapter"&gt;&lt;/activity&gt;
                 &lt;activity android:name=".RssHandler"&gt;&lt;/activity&gt;
                     &lt;activity android:name=".ZActivity"&gt;&lt;/activity&gt;
    &lt;/application&gt;
                        &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
&lt;/manifest&gt;
</code></pre>

<p>The log cat is showing a NPE in line number 36,ie mybtn.setOnClickListener(new OnClickListener(){.</p>

<p>my log cat is <img src="http://i.stack.imgur.com/DzxhQ.png" alt="enter image description here"></p>
