title: Error calling a custom ListView from another activity (not main activity) in Android?
body: <p>My MainActivity file does some other task. 
  AccountInfo is used to generate my list. </p>
  
  <pre><code>   public class AccountInfo extends Activity {
          TextView sublistHeadtext;
          ImageView sublistHeadImage;
          ListView listItem;
          String[] ItemViewNames;
          AccInfoCustomAdapter adapter;
  
          public ArrayList&lt;String&gt; CustomListViewValuesArr = new ArrayList&lt;String&gt;();
  
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.sub_list);
  
              int value = getIntent().getExtras().getInt("listpoition");
  
              sublistHeadtext = (TextView) findViewById(R.id.ListItemtext);
              sublistHeadtext.setText("Account Information");
  
              sublistHeadImage = (ImageView) findViewById(R.id.ListItemimage);
              sublistHeadImage.setImageResource(R.drawable.accinfoimg);
  
              listItem = (ListView) findViewById(R.id.listItem);
              ItemViewNames = getResources().getStringArray(R.array.accInfoList);
              Log.wtf("AA", "executed !");
  
              /******** Take some data in Arraylist ( CustomListViewValuesArr ) ***********/
              setListData();
  
              /**************** Create Custom Adapter *********/
              adapter = new AccInfoCustomAdapter(CustomListViewValuesArr,
                      getBaseContext());
  
              //adapter = new AccInfoCustomAdapter(CustomListViewValuesArr,AccountInfo.this);
              Log.wtf("AA", "arrayList : "+CustomListViewValuesArr);
              listItem.setAdapter(adapter);
          }
  
          /****** Function to set data in ArrayList *************/
          public void setListData() {
              for (int i = 0; i &lt; ItemViewNames.length; i++)
                  CustomListViewValuesArr.add(ItemViewNames[i]);
          }
  
      }
  
  
  
  
  AdatperFile 
  </code></pre>
  
  <p>public class AccInfoCustomAdapter extends BaseAdapter implements
              OnClickListener {</p>
  
  <pre><code>    private ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;(); 
      private Context context; 
  
  
  
      public AccInfoCustomAdapter(ArrayList&lt;String&gt; list, Context context) { 
          this.list = list; 
          this.context = context; 
      } 
  
      @Override
      public int getCount() { 
          return list.size(); 
      } 
  
      @Override
      public Object getItem(int pos) { 
          return list.get(pos); 
      } 
  
      @Override
      public long getItemId(int pos) { 
         // return list.get(pos).getId();
          //just return 0 if your list items do not have an Id variable.
          return 0;
      } 
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
          View view = convertView;
          if (view == null) {
              LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
              view = inflater.inflate(R.layout.sublist_item, null);
          } 
  
          //Handle TextView and display string from your list
          TextView listItemText = (TextView)view.findViewById(R.id.ListItemtext); 
          listItemText.setText(list.get(position)); 
  
          //Handle buttons and add onClickListeners
          ImageButton nextBtn = (ImageButton)view.findViewById(R.id.ListItemimgbtn);
  
  
          nextBtn.setOnClickListener(new View.OnClickListener(){
              @Override
              public void onClick(View v) { 
  
                  Toast.makeText(context, "position : "+position, Toast.LENGTH_LONG).show();
              }
          });
  
          return view; 
      }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
  
      } 
      }
  </code></pre>
  
  <p>I am getting a null pointer exception on line          </p>
  
  <p>listItem.setAdapter(adapter);</p>
  
  <blockquote>
    <p>I think the error exists here       </p>
  </blockquote>
  
  <pre><code>adapter = new AccInfoCustomAdapter (CustomListViewValuesArr, getBaseContext());
  </code></pre>
  
  <p>LOGCAT :- </p>
  
  <pre><code>02-18 18:16:46.170: E/AndroidRuntime(16303): FATAL EXCEPTION: main
  02-18 18:16:46.170: E/AndroidRuntime(16303): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xyzbank/com.example.xyzbank.AccountInfo}: java.lang.NullPointerException
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2060)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2085)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.os.Handler.dispatchMessage(Handler.java:99)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.os.Looper.loop(Looper.java:137)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.app.ActivityThread.main(ActivityThread.java:4747)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at java.lang.reflect.Method.invokeNative(Native Method)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at java.lang.reflect.Method.invoke(Method.java:511)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at dalvik.system.NativeStart.main(Native Method)
  02-18 18:16:46.170: E/AndroidRuntime(16303): Caused by: java.lang.NullPointerException
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at com.example.xyzbank.AccountInfo.onCreate(AccountInfo.java:45)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.app.Activity.performCreate(Activity.java:5008)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
  02-18 18:16:46.170: E/AndroidRuntime(16303):    ... 11 more
  </code></pre>