when I click on the button the app crashes

EpicMario71

Here the error:

java.lang.IllegalStateException: Could not find method OpenRadio(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatImageButton with id 'RadioPootis'

java code:

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link Fragment1#newInstance} factory method to
 * create an instance of this fragment.
 */
public class Fragment1 extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public Fragment1() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment Fragment1.
     */
    // TODO: Rename and change types and number of parameters
    public static Fragment1 newInstance(String param1, String param2) {
        Fragment1 fragment = new Fragment1();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_1, container, false);
    }

    String url = "https://epicmario71.tk";

    public void OpenRadio(View view) {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
    }
}

xml file:

?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout  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="match_parent"
    android:background="?attr/background"
    tools:context=".ui.main.Fragment1">

    <ImageView
        android:id="@+id/imageView11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="18dp"
        android:layout_marginLeft="18dp"
        android:layout_marginTop="15dp"
        android:src="@drawable/webp_net_resizeimage__6_"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/imageView12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="22dp"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="15dp"
        android:src="@drawable/webp_net_resizeimage__6_"
        app:layout_constraintStart_toEndOf="@+id/RadioPootis"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/imageView13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="22dp"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="15dp"
        android:src="@drawable/webp_net_resizeimage__6_"
        app:layout_constraintStart_toEndOf="@+id/imageView12"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/RadioPootis"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="22dp"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="16dp"
        android:background="@null"
        android:onClick="OpenRadio"
        android:src="@drawable/webp_net_resizeimage__6_"
        app:layout_constraintStart_toEndOf="@+id/imageView11"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

when I click on the button the app crashes

Using tabbed activity from android studio example whit legacy android studio libraries

Any help is welcome

Zain

You can not use android:onClick attribute in fragment layout unless you create it in the activity class, not the fragment class.

In your case:

Here the error: java.lang.IllegalStateException: Could not find method OpenRadio(View) in a parent or ancestor Context for android:onClick attribute defined on view class

The system looks at the activity class that hosts Fragment1, and didn't find OpenRadio(View) method.

So, you need to either move the OpenRadio(View) method to the activity class in case the code it holds is not relevant to the fragment; or you need to build some communication between the fragment and the activity when OpenRadio(View) of the activity is called, for this part you can check answers here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

when I click on the button the app crashes

From Dev

Android app crashes when click button

From Dev

Google Maps crashes on my app when I click the button (Intent) to open it

From Dev

How can I get the specific values I selected from SQLite Database? When I click on the button the app jut crashes

From Dev

Android Button Click Crashes App

From Dev

Android App crashes on Button click

From Dev

My app crashes when i press the start button

From Dev

My app crashes when I try to add Image Button to it

From Dev

App crashes when clicking on a button

From Dev

Android App crashes upon menu button click

From Dev

App crashes on button Click Action iOS

From Dev

Android App crashes upon menu button click

From Dev

Adding button click event crashes app at launch

From Dev

Why does my app crash when i click a certain button?

From Dev

redirect to the facebook app when I click share button in swift webview

From Dev

android app not closing when I click on home button

From Dev

How to open Google Map when I click on a button in android app

From Dev

redirect to the facebook app when I click share button in swift webview

From Dev

App crashes when click with empty text fields

From Dev

java - Android app crashes when button is pressed

From Dev

When i click on a listview item, the app crashes, instead of opening up another activity

From Dev

When i click on a listview item, the app crashes, instead of opening up another activity

From Dev

Trying to make a button change the web view url but when I press it it crashes the app

From Dev

My app crashes when I hit BACK button on one of my activities

From Dev

Smooch crashes when I press the button

From Dev

app crashes after button click once password is entered

From Dev

Xamarin Forms button click event crashes when running

From Dev

When I try to set a clickListener, app crashes

From Dev

App crashes when I entered nothing on edittext

Related Related

  1. 1

    when I click on the button the app crashes

  2. 2

    Android app crashes when click button

  3. 3

    Google Maps crashes on my app when I click the button (Intent) to open it

  4. 4

    How can I get the specific values I selected from SQLite Database? When I click on the button the app jut crashes

  5. 5

    Android Button Click Crashes App

  6. 6

    Android App crashes on Button click

  7. 7

    My app crashes when i press the start button

  8. 8

    My app crashes when I try to add Image Button to it

  9. 9

    App crashes when clicking on a button

  10. 10

    Android App crashes upon menu button click

  11. 11

    App crashes on button Click Action iOS

  12. 12

    Android App crashes upon menu button click

  13. 13

    Adding button click event crashes app at launch

  14. 14

    Why does my app crash when i click a certain button?

  15. 15

    redirect to the facebook app when I click share button in swift webview

  16. 16

    android app not closing when I click on home button

  17. 17

    How to open Google Map when I click on a button in android app

  18. 18

    redirect to the facebook app when I click share button in swift webview

  19. 19

    App crashes when click with empty text fields

  20. 20

    java - Android app crashes when button is pressed

  21. 21

    When i click on a listview item, the app crashes, instead of opening up another activity

  22. 22

    When i click on a listview item, the app crashes, instead of opening up another activity

  23. 23

    Trying to make a button change the web view url but when I press it it crashes the app

  24. 24

    My app crashes when I hit BACK button on one of my activities

  25. 25

    Smooch crashes when I press the button

  26. 26

    app crashes after button click once password is entered

  27. 27

    Xamarin Forms button click event crashes when running

  28. 28

    When I try to set a clickListener, app crashes

  29. 29

    App crashes when I entered nothing on edittext

HotTag

Archive