title: Attempt to invoke virtual method [Null object reference]
body: <p>I'm spending the last 5 days trying solve this problem. I really do not have any idea about how to solve it. I'm getting <code>Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference</code>. Check my code:</p>
  
  <p><strong>RecyclerView.java</strong></p>
  
  <pre><code>package etes.xdda.music;
  import android.app.Dialog;
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.Color;
  import android.graphics.drawable.ColorDrawable;
  import android.media.MediaPlayer;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageButton;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import java.util.List;
  
  
  public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.MyViewHolder&gt; implements View.OnClickListener{
  
      Context mContext;
      List&lt;mList&gt; mData;
      Dialog myDialog;
  
      private MediaPlayer mediaPlayer;
      private int playbackPosition=0;
  
      private LinearLayout menu_dialog;
      public RecyclerViewAdapter(Context mContext, List&lt;mList&gt; mData) {
          this.mContext = mContext;
          this.mData = mData;
      }
  
      public void onClick(View view) {
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v;
          v = LayoutInflater.from(mContext).inflate(R.layout.item_list, parent, false);
          final MyViewHolder vHolder = new MyViewHolder(v);
  
          // Dialog ini
          myDialog = new Dialog(mContext);
          myDialog.setContentView(R.layout.dialog);
          myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  
          vHolder.item_play.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v)
              {
  
                  TextView dialog_name_tv = (TextView) myDialog.findViewById(R.id.dialog_name_id);
                  TextView dialog_phone_tv = (TextView) myDialog.findViewById(R.id.dialog_author_id);
                  ImageView dialog_contact_img = (ImageView) myDialog.findViewById(R.id.dialog_img);
                  dialog_name_tv.setText(mData.get(vHolder.getAdapterPosition()).getName());
                  dialog_phone_tv.setText(mData.get(vHolder.getAdapterPosition()).getPhone());
                  dialog_contact_img.setImageResource(mData.get(vHolder.getAdapterPosition()).getPhoto());
                  //Toast.makeText(mContext, "Test click "+String.valueOf(vHolder.getAdapterPosition()), Toast.LENGTH_SHORT).show();
                  myDialog.show();
              }
          });
          vHolder.menu_play.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v)
              {
                  menu_dialog = v.getRootView().findViewById(R.id.menu_dialog);
                  menu_dialog.setVisibility(v.VISIBLE);
  
                  MainActivity a = new MainActivity();
                  a.initAudio(v.getContext(), mData.get(vHolder.getAdapterPosition()).getURL());
                  MainActivity.setMargins(v.getRootView().findViewById(R.id.viewpager_id), 0,0,0,100);
              }
          });
          return vHolder;
      }
  
      @Override
      public void onBindViewHolder(MyViewHolder holder, int position) {
  
          holder.tv_name.setText(mData.get(position).getName());
          holder.tv_author.setText(mData.get(position).getPhone());
          holder.img.setImageResource(mData.get(position).getPhoto());
      }
  
      @Override
      public int getItemCount() {
          return mData.size();
      }
  
      public static class MyViewHolder extends RecyclerView.ViewHolder {
  
          private ImageButton item_play;
          private LinearLayout menu_play;
          private TextView tv_name;
          private TextView tv_author;
          private TextView tv_url;
          private ImageView img;
  
          public MyViewHolder(View itemView) {
              super(itemView);
              item_play = itemView.findViewById(R.id.info_id);
              menu_play = itemView.findViewById(R.id.list_item_id);
  
              tv_name = (TextView) itemView.findViewById(R.id.name_list);
              tv_author = (TextView) itemView.findViewById(R.id.author_list);
              img = (ImageView) itemView.findViewById(R.id.img_contact);
          }
      }
  }
  </code></pre>
  
  <p>Note that I'm invoking <strong>MainActivity.java</strong> in this part:</p>
  
  <pre><code>vHolder.menu_play.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v)
          {
              menu_dialog = v.getRootView().findViewById(R.id.menu_dialog);
              menu_dialog.setVisibility(v.VISIBLE);
  
              MainActivity a = new MainActivity();
              a.initAudio(v.getContext(), mData.get(vHolder.getAdapterPosition()).getURL());
              MainActivity.setMargins(v.getRootView().findViewById(R.id.viewpager_id), 0,0,0,100);
          }
      });
  </code></pre>
  
  <p>And here's my <strong>MainActivity.java</strong></p>
  
  <pre><code>package etes.xdda.music;
  
  import android.annotation.SuppressLint;
  import android.content.Context;
  import android.media.MediaPlayer;
  import android.net.Uri;
  import android.support.design.widget.TabLayout;
  import android.support.v4.view.ViewPager;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageButton;
  import android.widget.LinearLayout;
  
  
  public class MainActivity extends AppCompatActivity {
  
      private DrawerLayout nDrawerLayout;
      private ActionBarDrawerToggle mToggle;
  
      private TabLayout tabLayout;
      private ViewPager viewPager;
      private viewPagerAdapter adapter;
      public LinearLayout menu_dialog;
      private String player_status = "playing";
      private ImageButton player_img;
  
  
  
      private static MediaPlayer mediaPlayer;
  
      @SuppressLint("RestrictedApi")
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          nDrawerLayout = findViewById(R.id.drawer);
  
          menu_dialog = findViewById(R.id.menu_dialog);
          menu_dialog.setVisibility(View.GONE);
  
          player_img = findViewById(R.id.playorpause);
          player_img.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                //setMargins(viewPager, 0,0,0,110);
                                                if (player_status == "playing") {
                                                    player_img.setImageResource(R.drawable.ic_play_arrow_black_24dp);
                                                    meplayer.pauseAudio();
                                                    player_status = "paused";
                                                } else {
                                                    player_img.setImageResource(R.drawable.ic_pause_black_24dp);
                                                    meplayer.startAudio();
                                                    player_status = "playing";
                                                }
                                            }
                                        });
  
  
  
          //menu_dialog.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
  
          mToggle = new ActionBarDrawerToggle(this, nDrawerLayout, R.string.open, R.string.close);
          nDrawerLayout.addDrawerListener(mToggle);
          getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          tabLayout = findViewById(R.id.tablayout_id);
          viewPager = findViewById(R.id.viewpager_id);
          //viewPager.setLayoutParams(new ViewPager.LayoutParams(0, 0));
          //setMarginBottom(viewPager, 0);
          setMargins(viewPager, 0,0,0,0);
  
          adapter = new viewPagerAdapter(getSupportFragmentManager());
  
          //Add fragments here
          adapter.addFragment(new fragmentList(), ""); //Lista de música
          adapter.addFragment(new fragmentFrequent(), ""); //Frequentes
          adapter.addFragment(new fragmentPlayList(), ""); //Playlist
  
          viewPager.setAdapter(adapter);
          tabLayout.setupWithViewPager(viewPager);
  
          tabLayout.getTabAt(0).setIcon(R.drawable.ic_music_note_black_24dp); //Lista de música
          tabLayout.getTabAt(1).setIcon(R.drawable.ic_filter_list_black_24dp); // Frequentes
          tabLayout.getTabAt(2).setIcon(R.drawable.ic_queue_music_black_24dp); // Playlist
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          if (mToggle.onOptionsItemSelected(item)) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      protected void onPostCreate(Bundle savedInstanceState) {
          super.onPostCreate(savedInstanceState);
          // Sync the toggle state after onRestoreInstanceState has occurred.
          mToggle.syncState();
      }
      public static void setMargins (View v, int l, int t, int r, int b) {
          if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
              ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
              p.setMargins(l, t, r, b);
              v.requestLayout();
          }
      }
  
      public void initAudio(final Context context, final String url) {
          if (mediaPlayer == null) {
              mediaPlayer = MediaPlayer.create(context, Uri.parse(url));
          }
          mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
              @Override
              public void onCompletion(MediaPlayer mp) {
                  //Toast.makeText(context, "TEST", Toast.LENGTH_LONG).show();
                  killMediaPlayer();
                  updateLayout();
  
              }
          });
          mediaPlayer.start();
      }
  
      private static void killMediaPlayer() {
          if (mediaPlayer != null) {
              try {
                  mediaPlayer.reset();
                  mediaPlayer.release();
                  mediaPlayer = null;
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  
      private void updateLayout() {
      try {
          menu_dialog = findViewById(R.id.menu_dialog);
          menu_dialog.setVisibility(View.GONE);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>And the part of code that is giving crash is this:</p>
  
  <pre><code>private void updateLayout() {
      try {
          menu_dialog = findViewById(R.id.menu_dialog);
          menu_dialog.setVisibility(View.GONE);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>@edit: I have added this piece of code, I don't know if can help</p>
  
  <p><strong>fragmentList.java</strong></p>
  
  <pre><code>package etes.xdda.music;
  
  import android.support.v4.app.Fragment;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Toast;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.JsonArrayRequest;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class fragmentList extends Fragment {
  
      View v;
      private RecyclerView myrecyclerview;
      private List&lt;mList&gt; lstContact;
  
      private String URL_JSON = "https://pastebin.com/raw/fG3zd40U";
      private JsonArrayRequest ArrayRequest;
      private RequestQueue requestQueue ;
      MainActivity activity;
  
      public fragmentList() {
      }
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          v = inflater.inflate(R.layout.list_fragment,container,false);
          myrecyclerview = (RecyclerView) v.findViewById(R.id.list_recyclerview);
          RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(activity, lstContact);
          myrecyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
          myrecyclerview.setAdapter(recyclerViewAdapter);
          return v;
      }
  
      @Override
      public void onCreate(@Nullable Bundle savedInstaceState) {
          super.onCreate(savedInstaceState);
          _JSONcall();
      }
  
  
      public void _JSONcall() {
  
          lstContact = new ArrayList&lt;&gt;();
          ArrayRequest = new JsonArrayRequest(URL_JSON, new Response.Listener&lt;JSONArray&gt;() {
              @Override
              public void onResponse(JSONArray response) {
  
                  JSONObject jsonObject = null;
  
                  for (int i = 0 ; i&lt;response.length();i++) {
                      try {
  
                          jsonObject = response.getJSONObject(i);
  
                          lstContact.add(new mList(jsonObject.getString("name"), jsonObject.getString("description"), jsonObject.getString("link"), R.drawable.ic_play_circle_filled_black_24dp));
                      }
                      catch (JSONException e) {
                          e.printStackTrace();
                          Toast.makeText(getActivity(), "Error 1!",
                                  Toast.LENGTH_LONG).show();
                      }
                  }
  
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Toast.makeText(getActivity(), "Error 3!",
                          Toast.LENGTH_LONG).show();
              }
          });
  
  
          requestQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
          requestQueue.add(ArrayRequest);
      }
  }
  </code></pre>
  
  <p>Please, help me, I have no more ideas about what I should do. Thank you</p>