2017-10-04 82 views
-2

我想在我的自定義提醒對話框中實現RecyclerView。錯誤稱爲

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

在這條線

hsv_font_bartextview.setLayoutManager(layoutManager); 

我的功能定製對話的代碼是像下面

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(); 
      } 
     }); 
    } 

讓我知道是否有人可以幫我解決我的問題。由於

+2

嘗試'hsv_font_bartextview =(RecyclerView)mDialog.findViewById(R.id.hsv_font_bartextview); –

+0

定義...謝謝先生!謝謝 – Priya

回答

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

findViewById()回報null,因爲你的活動不具有該ID的Widget。您的對話框可能,但對話框不是活動。如果這是hsv_font_bartextview所在的位置,則在對話框上撥打findViewById()

+2

你是對的',假設你的看法@MichaelDodd你是對的內'R.layout.font_dialogue' – Priya

相關問題