Estoy intentando mostrar un Snack bar en un fragment pero me da el siguiente error: > Attempt to invoke virtual method 'android.view.View > android.app.Activity.findViewById(int)' on a null object reference Este error sucede cuando quiero mostrar mi Snack bar mediante un boton, no entiendo por que sucede el error, este es mi codigo del Snack bar: public void desplegar() { Snackbar snackbar = Snackbar.make(getActivity().findViewById(android.R.id.content), "Se ha añadido a tus favoritos", Snackbar.LENGTH_LONG).setAction(getString(R.string.verfav), new View.OnClickListener() { @Override public void onClick(View view) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.qwe, new Favoritos()); transaction.commit(); } }); //ACTION snackbar.setActionTextColor(getResources().getColor(R.color.textoblanco)); View snackBarView = snackbar.getView(); //BACKGROUND snackBarView.setBackgroundColor(getResources().getColor(R.color.toolbar)); //MESSAGE TextView mensaje = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_text); mensaje.setTextColor(getResources().getColor(R.color.textoblanco)); snackbar.show(); } ya intente con diferentes formas pero no me han funcionado, no se porque se muestra ese error, este es mi codigo completo: public class Inicio extends Fragment implements noticiasAdapter.OnEventMovieListener, Response.Listener<JSONObject>, Response.ErrorListener{ RecyclerView recyclerView; private List<Noticias> noticias; private noticiasAdapter noticiasadapter; public static final String TAG = Noticias.class.getName(); RequestQueue request; JsonObjectRequest jsonObjectRequest; Context context; public Inicio(){ } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View view = inflater.inflate(R.layout.inicio, container, false); recyclerView = (RecyclerView)view.findViewById(R.id.recycler_view); noticias = new ArrayList<>(); noticiasadapter = new noticiasAdapter(noticias); noticiasadapter.setOnEventMovieListener(this); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); recyclerView.setLayoutManager(layoutManager); request = Volley.newRequestQueue(getActivity()); cargarWebService(); return view; } private void cargarWebService() { String url = "http://192.168.1.72:80/webservicemgrex/listaNoticias.php"; jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,url,null,this,this); request.add(jsonObjectRequest); } @Override public void onResponse(JSONObject response) { Noticias news = null; JSONArray json = response.optJSONArray("inicio"); try{ for (int i=0; i<json.length(); i++){ news = new Noticias(); JSONObject jsonObject = null; jsonObject = json.getJSONObject(i); news.setIdNoticia(jsonObject.optInt("idNoticia")); news.setTituloNoticia(jsonObject.optString("tituloNoticia")); news.setSubtituloNoticia(jsonObject.getString("subtituloNoticia")); news.setImagenNoticia(jsonObject.getString("imagenNoticia")); news.setDescripcionNoticia(jsonObject.getString("descripcionNoticia")); noticias.add(news); } noticiasAdapter adapter = new noticiasAdapter(noticias); recyclerView.setAdapter(adapter); noticiasadapter.notifyDataSetChanged(); }catch (JSONException e){ Toast.makeText(getActivity(),"Error al cargar la informacion del servidor: "+e, Toast.LENGTH_LONG).show(); e.printStackTrace(); } } @Override public void onErrorResponse(VolleyError error) { Toast.makeText(getActivity(),"No se pudo consultar los registros: "+error.toString(), Toast.LENGTH_LONG).show(); Log.i("Error","No se pudo consultar el registro: "+error.toString()); } @Override public void onStop() { super.onStop(); } @Override public void onResume() { super.onResume(); } @Override public void onPause() { super.onPause(); } @Override public void onDestroy() { super.onDestroy(); } //Revisar este bloque @Override public void vistaDetalle(String tituloNoticia, String subtituloNoticia, String imagenNoticia, String descripcionNoticia) { Intent intent = new Intent(getActivity(), DescripcionNoticias.class); intent.putExtra("titulon",tituloNoticia); intent.putExtra("descripcionn", descripcionNoticia); intent.putExtra("imagen", imagenNoticia); startActivity(intent); getActivity().overridePendingTransition(R.anim.left_in, R.anim.left_out); } public void desplegar() { Snackbar snackbar = Snackbar.make(getActivity().findViewById(android.R.id.content), "Se ha añadido a tus favoritos", Snackbar.LENGTH_LONG).setAction(getString(R.string.verfav), new View.OnClickListener() { @Override public void onClick(View view) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.qwe, new Favoritos()); transaction.commit(); } }); //ACTION snackbar.setActionTextColor(getResources().getColor(R.color.textoblanco)); View snackBarView = snackbar.getView(); //BACKGROUND snackBarView.setBackgroundColor(getResources().getColor(R.color.toolbar)); //MESSAGE TextView mensaje = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_text); mensaje.setTextColor(getResources().getColor(R.color.textoblanco)); snackbar.show(); } } Este es el XML que se carga en ese fragmento: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:id="@+id/content" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.example.enriq.seccion15update.Principal" tools:showIn="@layout/app_bar_main"> <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="60dp" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" tools:context=".Principal"> </android.support.v7.widget.RecyclerView> </RelativeLayout> y este es mi cardview que cargo para mostrar el contenido: <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" app:cardBackgroundColor="@color/textoblanco" app:cardCornerRadius="2dp" app:cardElevation="20dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingEnd="16dp" android:paddingStart="16dp" android:paddingTop="16dp"> <TextView android:id="@+id/tituloNoticia" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#000000" android:text="@string/tituloNoticia" android:fontFamily="sans-serif" android:textStyle="bold" android:layout_marginBottom="5dp" android:textSize="18sp" tools:targetApi="jelly_bean"/> <TextView android:id="@+id/subtituloNoticia" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#000000" android:layout_marginBottom="5dp" android:text="@string/subitutloNoticias" android:textSize="15sp" android:fontFamily="sans-serif" tools:targetApi="jelly_bean"/> <ImageView android:id="@+id/imagenNotica" android:layout_width="match_parent" android:layout_height="200dp" android:contentDescription="@string/linea_divisora_de_texto_y_video" android:scaleType="fitCenter" app:srcCompat="@drawable/example" /> <android.support.design.widget.FloatingActionButton android:id="@+id/floatingActionButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginRight="10dp" android:layout_marginBottom="10dp" android:clickable="true" android:tint="@color/barraestatus" app:backgroundTint="@color/textoblanco" app:elevation="5dp" app:rippleColor="@color/barraestatus" app:srcCompat="@drawable/unliked" /> <TextView android:id="@+id/descripcionNoticias" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp" android:text="Descripcion" android:maxLines="3" android:textAppearance="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small" android:textSize="14sp" /> <Button android:id="@+id/showMore" style="@android:style/Widget.Material.Button.Borderless" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:shadowColor="@color/barraestatus" android:text="Ver nota completa" android:textColor="@color/barraestatus" android:textStyle="bold" android:tint="@color/barraestatus" app:backgroundTint="@color/textoblanco" tools:targetApi="lollipop"/> </LinearLayout> </android.support.v7.widget.CardView>