我想從Course_Bean.java獲取school_id。我已經試過,但錯誤是:java.lang.String不能轉換爲Bean.Course_Bean
java.lang.String中不能轉換到Bean.Course_Bean
這是AllTopic_Fragment.java
public AllTopic_Fragment(Context mContext, Object obj) {
this.mContext = mContext;
mNavigationDeleget = (NavigationDeleget) mContext;
this.object = ((Course_Bean)obj).getId(); //in this line was error
this.object2 = ((Course_Bean)obj).getSchool_id();
Bitmap default_bitmap = Util.drawableToBitmap(mContext.getResources().getDrawable(R.mipmap.profile_default));
這是TopicMainFragment.java
public Topic_MainFragment(Context mContext, Object object) {
this.mContext = mContext;
mNavigationDeleget = (NavigationDeleget) mContext;
this.obj = object;
}
private void displayView(String fragmentName, Object obj) {
//deatachFragment(fragTransaction);
// mFragmentManager = getSupportFragmentManager();
fragmentTransaction = mFragmentManager.beginTransaction();
if (fragmentName.equals(VerlinConstant.ALLTOPIC_FRAGMENT)) {
mFragment = new AllTopic_Fragment(mContext, obj); //this line was error
} else if (fragmentName.equals(VerlinConstant.RECOMMENDED_FRAGMENT)) {
mFragment = new Recommended_Fragment(mContext, obj);
並且在這個腳本中,TopicMainFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mFragmentManager = getChildFragmentManager();
if (view == null) {
view = inflater.inflate(R.layout.topic_main_fragment, container, false);
intializeGUI(view);
if (VerlinConstant.SELECT_FRAG.equalsIgnoreCase("")) {
displayView(VerlinConstant.ALLTOPIC_FRAGMENT, obj); //this line was error
changeViewColor(alltopic_tab_txt);
} else if (VerlinConstant.SELECT_FRAG.equalsIgnoreCase("all")) {
displayView(VerlinConstant.ALLTOPIC_FRAGMENT, obj);
changeViewColor(alltopic_tab_txt);
請幫助
什麼是Course_Bean?異常對我來說很明顯 – Denny
'displayView(VerlinConstant.ALLTOPIC_FRAGMENT,obj);' - >你在哪裏初始化'obj'? –
course_bean是保存/返回school_id值的文件,所以我想從course_bean.java獲取school_id值@Denny – muffin