title: Change text color in adapter
body: <p>I need to change text color in of list view with switch of a button click. List view with custom adapter and custom layout. Text view in <code>newsitemlist_layout.xml</code> inflated with adapter normal it works fine but in fragment gives an error:</p>
  
  <blockquote>
    <p>Adaptor.setTextColor(int)' on a null object reference</p>
  </blockquote>
  
  <p>The problem is that adapter is initialized in fragment and switch or button in main activity if I implement change text color in fragment it works but not in main activity. Is there any way to do this?</p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>NewsAdaptor adaptor;
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  fab.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick ( View view ) {
          Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                  .setAction("Action", null).show();
      }
  });
  
  DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  drawer.addDrawerListener(toggle);
  toggle.syncState();
  
  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
  View headerView = navigationView.getHeaderView(0);
  
  
  aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
     @SuppressLint("ResourceAsColor")
     @Override
     public void onCheckedChanged ( CompoundButton buttonView, boolean   isChecked ) {
  
             adaptor.setTextColor(Color.GREEN);
              adaptor.notifyDataSetChanged();
             } else {
  
  
              adaptor.setTextColor(Color.RED);
              adaptor.notifyDataSetChanged();
  
          }
     }
  });
  </code></pre>
  
  <p>Fragment.java</p>
  
  <pre><code>NewsAdaptor adapter;
  adapter = new NewsAdaptor(Main2Activity.this, newsItemsList);
      lvRss.setAdapter(adapter);
  </code></pre>
  
  <p>NewsAdapter.java</p>
  
  <pre><code> public class NewsAdaptor extends BaseAdapter {
      TextView tvtitle;
      Context context;
      private int color;
  
  
  
      public NewsAdaptor ( Context context, ArrayList &lt;NewsItem&gt; newsList ) {
          this.context = context;
          this.newsList = newsList;
          this.color = Color.RED;
      }
  
      ArrayList &lt;NewsItem&gt; newsList;
  
  
      @Override
      public int getCount () {
  
          return newsList.size();
      }
  
      @Override
      public Object getItem ( int position ) {
  
          return newsList.get(position);
      }
  
      @Override
      public long getItemId ( int position ) {
          return 0;
      }
  
      @SuppressLint("ResourceAsColor")
      @Override
      public View getView ( int position, View convertView, ViewGroup parent ) {
          if (convertView == null) {
              convertView = View.inflate(context, R.layout.newsitemlist_layout, null);
  
          }
          NewsItem currentNews = newsList.get(position);
          tvtitle = (TextView) convertView.findViewById(R.id.textView1id);
  
          tvtitle.setText(currentNews.getTitle());
          tvtitle.setTextColor(color);
          return convertView;
      }
      public void setTextColor(int color) {
          this.color = color;
      }
  }
  </code></pre>
  
  <p>NewsItem.java</p>
  
  <pre><code>public class NewsItem implements Serializable {
  
  String title;
  
  public String getTitle () {
      return title;
  }
  
  public void setTitle ( String title ) {
      this.title = title;
  }
  
  
  @Override
  public String toString() {
      return title;
  }
  </code></pre>
  
  <p>NewsItemlist.layout.xml</p>
  
  <pre><code>&lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="150dp"&gt;
      &lt;TextView
          android:id="@+id/textView1id"
          android:layout_width="237dp"
          android:layout_height="83dp"
          android:layout_alignEnd="@+id/pubDateid"
          android:layout_alignParentTop="true"
          android:layout_alignRight="@+id/pubDateid"
          android:ellipsize="end"
          android:gravity="right"
          android:text="News TITLE"
          android:textStyle="bold" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>