Using an external xml file for custom list view adapter?
<p>I am currently developing my first Android Application. In the app there should be a listView which is displaying at the left side a pic and next to it 2 textViews.</p>

<p>The xml for the listView looks like the following:</p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="?android:attr/listPreferredItemHeight"
            android:padding="6dip" &gt;

&lt;ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="6dip"
        android:contentDescription="TODO"
        android:src="@drawable/ic_launcher" /&gt;

&lt;TextView
        android:id="@+id/secondLine"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/icon"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="Description"
        android:textSize="12sp" /&gt;

&lt;TextView
        android:id="@+id/firstLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/secondLine"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:layout_toRightOf="@id/icon"
        android:gravity="center_vertical"
        android:text="Example application"
        android:textSize="16sp" /&gt;

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

<p>The xml for the the MainActivity is looking this:</p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            tools:context=".MainActivity"&gt;

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

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

<p>My MainActivity.java code looks looks like the following:</p>

<pre><code>import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends ListActivity {
    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2" };
    String[] values2 = new String[] {"good","bad","medium","not yet tested","don't know it","very cool","Just Windows","piece of shit","very cool","don't know it too"};
    ListView listView = (ListView) findViewById(R.id.listview);
    ListViewAdapter adapter1 = new ListViewAdapter (values,values2,android.R.id.list);
    listView.setAdapter(adapter1);
    }
}
</code></pre>

<p>My current Custom Adapter looks like this:</p>

<pre><code>import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter {

String[] values;
String[] values2;
Context ctxt;
LayoutInflater layoutInflater;

public ListViewAdapter (String [] Values,String [] Values2, Context context) {
    values = Values;
    values2 = Values2;
    ctxt = context;
    layoutInflater = (LayoutInflater) context.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    return values.length;
}

@Override
public Object getItem(int position) {
    String [] res = new String [] {values [position],values2 [position]};
    return res;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    TextView name1 = (TextView)convertView.findViewById(android.R.id.text1);
    TextView name2 = (TextView)convertView.findViewById(android.R.id.text2);
    name1.setText(values [position]);
    name2.setText(values2 [position]);
    return convertView;
}
}
</code></pre>

<p>I get the following error when launching the app:</p>

<blockquote>
  <p>Process: de.gotthold.myapplication2.app, PID: 16723
          java.lang.RuntimeException: Unable to start activity ComponentInfo{de.gotthold.myapplication2.app/de.gotthold.myapplication2.app.MainActivity}:
  java.lang.NullPointerException: Attempt to invoke virtual method 'void
  android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a
  null object reference
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
                  at android.app.ActivityThread.access$800(ActivityThread.java:144)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:155)
                  at android.app.ActivityThread.main(ActivityThread.java:5727)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
           Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void
  android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a
  null object reference
                  at de.gotthold.myapplication2.app.MainActivity.onCreate(MainActivity.java:19)
                  at android.app.Activity.performCreate(Activity.java:5961)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
                  at android.app.ActivityThread.access$800(ActivityThread.java:144)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:155)
                  at android.app.ActivityThread.main(ActivityThread.java:5727)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
      02-06 12:45:27.641  16723-16723/? D/Process﹕ killProcess, pid=16723
      02-06 12:45:27.641  16723-16723/? D/Process﹕ com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:138
  java.lang.ThreadGroup.uncaughtException:693
  java.lang.ThreadGroup.uncaughtException:690</p>
</blockquote>

<p>I would like the get an explanation for this problem, not a link to a tutorial because I tried working trough them and this happend. I read also multiple stackoverflow threads, but none of could solve my problem.</p>

<p>Thanks for your help,
school-guy</p>

<p>P.S.: This is not the app I am developing this is a diffrent one where I am messing around with my new learnt knowledge.</p>