[英]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.