list view null pointer exception in android
<p>hi all i have a list view with some values in string array and i pass it to list view by </p>

<pre><code> list1.setAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, array)); 
</code></pre>

<p>it get NullPointerException on this line.     </p>

<p>my code:</p>

<pre><code>public class SecondActivity extends Activity{

int min=00,hr=00,sec=00;
TextView tv1;
ListView list1;
private String array[] = { "Iphone", "Tutorials", "Gallery", "Android","item 1", "item 2", "item3", "item 4" }; 

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.secondactivity);

    tv1=(TextView)findViewById(R.id.textView1);
    list1 = (ListView) findViewById(R.id.list);

    Bundle bundle = this.getIntent().getExtras();
    hr = Integer.parseInt(bundle.getString("key1"));
    min = Integer.parseInt(bundle.getString("key2"));
    sec=Integer.parseInt(bundle.getString("key3"));

    tv1.setText(String.format("%02d:%02d:%02d", hr, min, sec));


    list1.setAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, array));      // line no 38  


list1.setOnItemClickListener(
        new OnItemClickListener()
        {
            public void onItemClick(AdapterView&lt;?&gt; arg0, View view,int position, long id) {
                // TODO Auto-generated method stub
                Object o = list1.getItemAtPosition(position);
                String pen = o.toString();
                Toast.makeText(getApplicationContext(), "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show();


            }

            public void onItemClick1(AdapterView&lt;?&gt; arg0, View arg1,
                    int arg2, long arg3) {   // eclipse told me to add Unimplemented method(this method).
                // TODO Auto-generated method stub

            }


        }       
);

 }
</code></pre>

<p>}</p>

<p>my xml file:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
 &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
   &lt;TextView android:text="TextView" android:id="@+id/textView1"     android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/TextView&gt;

  &lt;ListView android:id="@+id/list"  android:layout_width="fill_parent"   android:layout_height="wrap_content" android:layout_marginLeft="10px" android:layout_marginRight="10px" android:layout_marginTop="65px" android:layout_marginBottom="40px" android:paddingLeft="0px"
android:paddingRight="0px" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>my Log cat file:</p>

<pre><code> 05-12 17:50:12.295: ERROR/AndroidRuntime(3776): Caused by: java.lang.NullPointerException
  05-12 17:50:12.295: ERROR/AndroidRuntime(3776):     at com.stop.watch.SecondActivity.onCreate(SecondActivity.java:38)
  05-12 17:50:12.295: ERROR/AndroidRuntime(3776):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 05-12 17:50:12.295: ERROR/AndroidRuntime(3776):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
</code></pre>
