2016-04-11 12 views
0

からのフラグメントのテキストを設定することができ、私はNullPointerExceptionが、がどのように活動

主な活動

ProductDetail productDetail = (ProductDetail)findViewById(R.id.pd_details); 
    productDetail.setDescription("This is description"); 

FragmentDescription.java 

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    return inflater.inflate(R.layout.fragment_description, null); 


ProductDetail.java 

@Override 
public void setDescription(String description) { 
    tvDescription.setText(description); 
} 
+0

を使用しましたコンストラクタをフラグメントに追加してそこに配置します。 – Nanoc

答えて

0

が追加FragmentManager

ProductDetail productDetail = (ProductDetail)getSupportFragmentManager().findFragmentById(R.id.pd_details);  
    productDetail.setDescription("This is description"); 
+0

did not work.Error:破棄不可能な型です。キャストできません。 –

+0

@VishawThakkar、それからgetSupportFragmentManager()を使用します。サポートライブラリを使用している可能性があります。それが起こる理由です。私は投稿を更新しました –

+0

同じ問題が 'android.support.v4.app.Fragment'を 'com.example.niraj.CustomDesign.ui.ProductDetail'にキャストできません –

関連する問題