当我单击按钮时,应用程序崩溃

史诗般的马里奥71

这里的错误:

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代码:

/**
 * 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文件:

?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>

当我单击按钮时,应用程序崩溃

使用Android Studio中的选项卡式活动示例旧版Android Studio库

欢迎任何帮助

Zain

android:onClick除非在活动类而非片段类中创建属性,否则不能在片段布局中使用属性。

在您的情况下:

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

系统查看托管的活动类,Fragment1但未找到OpenRadio(View)方法。

因此,如果OpenRadio(View)方法所持有的代码与片段无关,则需要将方法移至活动类。或者在OpenRadio(View)调用Activity时需要在片段和Activity之间建立一些通信,对于这一部分,您可以在此处检查答案

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

当我单击某个按钮时,为什么我的应用程序崩溃?

来自分类Dev

当我单击按钮时,Android 应用程序崩溃,onClickListener 出现问题

来自分类Dev

当我单击打开弹出窗口的按钮时应用程序崩溃

来自分类Dev

当我单击菜单按钮时,Android 应用程序崩溃

来自分类Dev

当我单击按钮时,应用程序停止

来自分类Dev

我的应用程序在单击按钮时崩溃

来自分类Dev

单击提交按钮时我的应用程序崩溃

来自分类Dev

单击按钮时应用程序崩溃

来自分类Dev

如何获得从SQLite数据库中选择的特定值?当我单击按钮时,应用程序崩溃

来自分类Dev

当我点击我的一项活动的返回按钮时,我的应用程序崩溃

来自分类Dev

当我使用OnClicklistener作为按钮时,即使它为空,我的应用程序也会崩溃

来自分类Dev

当我选择单选按钮时,我的应用程序崩溃了

来自分类Dev

当我按下开始按钮时,我的应用程序崩溃了

来自分类Dev

当我尝试向其中添加图像按钮时,我的应用程序崩溃了

来自分类Dev

当我单击列表中的歌曲时应用程序崩溃

来自分类Dev

当我单击浮动操作按钮时,我的应用程序崩溃:只有创建视图层次结构的原始线程才能触摸其视图

来自分类Dev

当我单击UserInfo按钮时如果强制关闭我的应用程序

来自分类Dev

当我在Android应用程序中单击“笔记”按钮时,如何调用我的NoteMain类

来自分类Dev

当我单击按钮时,我无法再使用应用程序,直到它结束

来自分类Dev

当我在活动上放置按钮时,Android应用程序崩溃,空活动正常运行

来自分类Dev

试图让按钮更改网络视图 url 但当我按下它时应用程序崩溃

来自分类Dev

为什么当我按下按钮在表中插入值时应用程序崩溃?

来自分类Dev

为什么当我点击搜索按钮时应用程序崩溃?

来自分类Dev

当我点击注销时,我的应用程序崩溃

来自分类Dev

当我单击快速WebView中的共享按钮时,重定向到Facebook应用程序

来自分类Dev

当我单击按钮时刷新整个用户在WinForms应用程序中输入的数据

来自分类Dev

当我单击主页按钮时,android应用程序未关闭

来自分类Dev

当我单击快速WebView中的共享按钮时,重定向到Facebook应用程序

来自分类Dev

当我单击“翻译”按钮时,“应用程序名称”一直停止。

Related 相关文章

  1. 1

    当我单击某个按钮时,为什么我的应用程序崩溃?

  2. 2

    当我单击按钮时,Android 应用程序崩溃,onClickListener 出现问题

  3. 3

    当我单击打开弹出窗口的按钮时应用程序崩溃

  4. 4

    当我单击菜单按钮时,Android 应用程序崩溃

  5. 5

    当我单击按钮时,应用程序停止

  6. 6

    我的应用程序在单击按钮时崩溃

  7. 7

    单击提交按钮时我的应用程序崩溃

  8. 8

    单击按钮时应用程序崩溃

  9. 9

    如何获得从SQLite数据库中选择的特定值?当我单击按钮时,应用程序崩溃

  10. 10

    当我点击我的一项活动的返回按钮时,我的应用程序崩溃

  11. 11

    当我使用OnClicklistener作为按钮时,即使它为空,我的应用程序也会崩溃

  12. 12

    当我选择单选按钮时,我的应用程序崩溃了

  13. 13

    当我按下开始按钮时,我的应用程序崩溃了

  14. 14

    当我尝试向其中添加图像按钮时,我的应用程序崩溃了

  15. 15

    当我单击列表中的歌曲时应用程序崩溃

  16. 16

    当我单击浮动操作按钮时,我的应用程序崩溃:只有创建视图层次结构的原始线程才能触摸其视图

  17. 17

    当我单击UserInfo按钮时如果强制关闭我的应用程序

  18. 18

    当我在Android应用程序中单击“笔记”按钮时,如何调用我的NoteMain类

  19. 19

    当我单击按钮时,我无法再使用应用程序,直到它结束

  20. 20

    当我在活动上放置按钮时,Android应用程序崩溃,空活动正常运行

  21. 21

    试图让按钮更改网络视图 url 但当我按下它时应用程序崩溃

  22. 22

    为什么当我按下按钮在表中插入值时应用程序崩溃?

  23. 23

    为什么当我点击搜索按钮时应用程序崩溃?

  24. 24

    当我点击注销时,我的应用程序崩溃

  25. 25

    当我单击快速WebView中的共享按钮时,重定向到Facebook应用程序

  26. 26

    当我单击按钮时刷新整个用户在WinForms应用程序中输入的数据

  27. 27

    当我单击主页按钮时,android应用程序未关闭

  28. 28

    当我单击快速WebView中的共享按钮时,重定向到Facebook应用程序

  29. 29

    当我单击“翻译”按钮时,“应用程序名称”一直停止。

热门标签

归档