简体   繁体   English

尝试调用虚方法 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager

[英]Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager

I am trying to implement RecyclerView in one of my custom alert dialogue.我正在尝试在我的自定义警报对话框之一中实现 RecyclerView。 Its crashing with error called它因错误而崩溃,称为

Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference 

on this line在这条线上

hsv_font_bartextview.setLayoutManager(layoutManager);

My function code of custom dialogue is like below我的自定义对话功能代码如下

private void showGotoPageDialog() {

        final Dialog mDialog = new Dialog(SettingsActivity.this);
        mDialog.setContentView(R.layout.font_dialogue);
        mDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        LinearLayoutManager layoutManager
                = new LinearLayoutManager(SettingsActivity.this, LinearLayoutManager.HORIZONTAL, false);
        hsv_font_bartextview=(RecyclerView)findViewById(R.id.hsv_font_bartextview);
        hsv_font_bartextview.setLayoutManager(layoutManager);


        TextAdapterTextview textAdaptertextview = new TextAdapterTextview(SettingsActivity.this, Globle.getFontArray());
        hsv_font_bartextview.setAdapter(textAdaptertextview);
        textAdaptertextview.setOnClickLIstner(new OnTClickLIstner() {
            @Override
            public void onClick(View v, String image, int position) {
                Toast.makeText(SettingsActivity.this,image,Toast.LENGTH_SHORT).show();

            }
        });

        mDialog.show();
        TextView dismiss = (TextView) mDialog.findViewById(R.id.dialog_dismiss);
        dismiss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDialog.dismiss();
            }
        });
    }

Let me know if someone can help me for solve my issue.让我知道是否有人可以帮助我解决我的问题。 Thanks谢谢

hsv_font_bartextview=(RecyclerView)findViewById(R.id.hsv_font_bartextview);

findViewById() returns null , because your activity does not have a widget with that ID. findViewById()返回null ,因为您的活动没有具有该 ID 的小部件。 Your dialog might, but the dialog is not the activity.您的对话可能,但对话不是活动。 Call findViewById() on the dialog if that is where the hsv_font_bartextview is.如果hsv_font_bartextview所在的hsv_font_bartextview ,则在对话框上调用findViewById()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RecyclerView没有LayoutManager android.support.v7.widget.RecyclerView - RecyclerView has no LayoutManager android.support.v7.widget.RecyclerView '布尔android.support.v7.widget.RecyclerView $ LayoutManager.canScrollVertically()' - 'boolean android.support.v7.widget.RecyclerView$LayoutManager.canScrollVertically()' 我有两个空指针尝试调用虚拟方法 'void android.support.v7.widget.RecyclerView.setHasFixedSize(boolean) - I am having a two null pointer Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setHasFixedSize(boolean) 无法导入导入android.support.v7.widget.RecyclerView; - Cannot import import android.support.v7.widget.RecyclerView; android.support.v7.widget.RecyclerView无法实例化 - android.support.v7.widget.RecyclerView failed to instantiate eclipse中无法启动android.support.v7.widget.Recyclerview错误 - android.support.v7.widget.Recyclerview could not be initiated error in eclipse 找不到以下类: - android.support.v7.widget.RecyclerView - The following classes could not be found: - android.support.v7.widget.RecyclerView java.lang.NullPointerException:尝试写入字段'int android.support.v7.widget.RecyclerView - java.lang.NullPointerException: Attempt to write to field 'int android.support.v7.widget.RecyclerView android.support.v4.widget.NestedScrollView无法转换为android.support.v7.widget.RecyclerView - android.support.v4.widget.NestedScrollView cannot be cast to android.support.v7.widget.RecyclerView android.support.v7.widget.RecyclerView无法强制转换为android.widget.ListView - android.support.v7.widget.RecyclerView cannot be cast to android.widget.ListView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM