Intent from Fragment to Activity

后端 未结 11 1493
再見小時候
再見小時候 2021-02-03 23:22

I was trying to go to another page using button, but it always fail.

Here is my First Class with its XML:

public class Fin         


        
11条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 00:14

    Remove this

    android:onClick="goToAttract"
    

    Then

    View rootView = inflater.inflate(R.layout.fragment_home, container, false);
    Button b = (Button)rootView.findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener()
    {
         public void onClick(View v)
         {
            Intent intent = new Intent(getActivity(), MainActivityList.class);
            startActivity(intent);
    
         } 
    
    });
    return rootView;
    

    The error says you need to public void goToAttract(View v) in Activity class

    Could not find method goToAttract(View) in the activity class
    

    Reason pls check the answer by PareshMayani @

    Android app crashing (fragment and xml onclick)

    Edit:

    Caused by: java.lang.OutOfMemoryError
    

    I guess you have a image that is too big to fit in and it needs to be scaled down. Hence the OutOfMemoryError.

提交回复
热议问题