Saturday, 15 February 2014

java - URI.parse and imagebutton error -


code when the user clicks on a button, but I have to open the error Web view:

  java.lang.NullPointerException: calling virtual method on a null object reference info.teammumu.cougarcardapp.SocialMediaFragment to zero android.widget.ImageButton.setOnClickListener to (android.view.View $ OnClickListener) ' Effort. onCreateView (SocialMediaFragment.java:28)  

Java code:

  public class SocialMediaFragment extends Piece {public ImageButton fbbutton; Public Image Button Twitton; Public Image Button Ignaton; @Override public view onCreateView (LayoutInflater inflater, ViewGroup container, bundle savedInstanceState) {See rootView = inflater.inflate (R.layout.fragment_socialmedia, container, false); Fbbutton = (ImageButton) getActivity (). FindViewById (RIDFebbutton); Twbutton = (image button) getActivity () FindViewById (R.id.twbutton); Igbutton = (ImageButton) getActivity (). FindViewById (R.id.igbutton); Fbbutton.setOnClickListener (New View.OnClickListener) {@Override Public Zero onClick (see v) {intro browserIntent = new intent (Intent.ACTION_VIEW, URI.parse ("https://www.facebook.com/universityofhouston")) ; StartActivity;}}); Twbutton.setOnClickListener (see the new OnClickListener (click on {@Override Public Zero (see V)} {intent BrowserEntent = new intent (Intent.ACTION_VIEW, Uri.parse ("website"); startActivity (BrowserImentant);}} ); Igbutton.setOnClickListener (see the new OnClickListener () {@Override click on Public Zero (see V) {Intent BrowserIntent = New Intent (Intent.ACTION_VIEW, Uri.parse ("website"); startActivity (BrowserImentant);}} ); Return root view; }}  

I had asked a question like this before, but it was never answered or maybe I could not understand it ... thanks for anyone who helped with this Could! I was trying to solve it for a few days but did not get success. It crashes and I can not open anything to tabs

use rootView

  fbbutton = (ImageButton) rootView.findViewById (instead of  getActivity ()  which is given from  onCreateView  R.id.fbbutton to use ideas from slice layout;); Twbutton = (ImageButton) rootView.findViewById (R.id.twbutton); .....   

Because the return reference of the activity of getActivity in which the current piece is added, hence the getActivity () calling. FindViewById (& lt; id & gt;) means that the use of view from the activity layout rather than fragmentation.


No comments:

Post a Comment