Issue
I am getting a class cast exception that only occurs when I am using genymotion. Whenever I try this on a real device I do not have an issue.
Stacktrace:
5-11 19:05:10.217 1278-1278/com.vast.homestory.betadebug E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
at android.widget.ListView.setupChild(ListView.java:1874)
at android.widget.ListView.makeAndAddView(ListView.java:1843)
at android.widget.ListView.fillDown(ListView.java:675)
at android.widget.ListView.fillFromTop(ListView.java:736)
at android.widget.ListView.layoutChildren(ListView.java:1655)
at android.widget.AbsListView.onLayout(AbsListView.java:2012)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
I am using a merge adapter from Commonsware and code:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup v = (ViewGroup) inflater.inflate(R.layout.fragment_profile_merge_list, container, false);
initViews(inflater, container, v);
setViews();
setListAdapter(mergeAdapter);
return v;
}
public void initViews(LayoutInflater inflater, ViewGroup container, View v) {
progressBar = (ProgressBar) v.findViewById(R.id.profile_fragment_progress_bar);
profileHeaderRL = (RelativeLayout) inflater.inflate(R.layout.profile_header_layout, container, false);
contactInfoRL = (RelativeLayout) inflater.inflate(R.layout.profile_contact_info_layout, container, false);
addressRL = (RelativeLayout) inflater.inflate(R.layout.profile_address_layout, container, false);
listingInfoRL = (RelativeLayout) inflater.inflate(R.layout.profile_listing_info_layout, container, false);
logoutRL = (RelativeLayout) inflater.inflate(R.layout.profile_logout_layout, container, false);
switch (profileMode) {
case AGENT_MODE:
mergeAdapter.addView(profileHeaderRL);
mergeAdapter.addView(contactInfoRL);
mergeAdapter.addView(addressRL);
mergeAdapter.addView(logoutRL);
break;
case SEARCH_MODE:
mergeAdapter.addView(profileHeaderRL);
mergeAdapter.addView(contactInfoRL);
mergeAdapter.addView(addressRL);
break;
case LISTING_MODE:
mergeAdapter.addView(profileHeaderRL);
mergeAdapter.addView(addressRL);
mergeAdapter.addView(listingInfoRL);
break;
}
profileIV = (RoundedImageView) profileHeaderRL.findViewById(R.id.profile_image_view);
emailIV = (ImageView) contactInfoRL.findViewById(R.id.profile_email_icon);
phoneIV = (ImageView) contactInfoRL.findViewById(R.id.profile_phone_icon);
initialsTV = (TextView) profileHeaderRL.findViewById(R.id.profile_initials_tv);
nameTV = (TextView) profileHeaderRL.findViewById(R.id.profile_name_tv);
brokerageTV = (TextView) profileHeaderRL.findViewById(R.id.profile_brokerage_tv);
officeRL = (RelativeLayout) addressRL.findViewById(R.id.profile_office_rv);
emailAddressTV = (TextView) contactInfoRL.findViewById(R.id.profile_email_tv);
phoneNumberTV = (TextView) contactInfoRL.findViewById(R.id.profile_phone_number_tv);
addressTV = (TextView) addressRL.findViewById(R.id.profile_address_tv);
cityStateTV = (TextView) addressRL.findViewById(R.id.profile_city_state_tv);
zipTV = (TextView) addressRL.findViewById(R.id.profile_zip_tv);
officeTV = (TextView) addressRL.findViewById(R.id.profile_office_tv);
doneTV = (TextView) profileHeaderRL.findViewById(R.id.profile_done_tv);
editTV = (TextView) profileHeaderRL.findViewById(R.id.profile_edit_tv);
logoutButton = (Button) logoutRL.findViewById(R.id.profile_logout_button);
priceTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_price_tv);
priceSqftTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_pricesqft_tv);
bedsTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_beds_tv);
bathsTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_baths_tv);
sqftTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_sqft_tv);
lotSizeTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_lot_size_tv);
yearTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_years_tv);
floorsTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_stories_tv);
}
public void setViews() {
switch (profileMode) {
case AGENT_MODE:
setAgentViews();
setEmailAndPhoneActions();
break;
case SEARCH_MODE:
setSearchViews();
setEmailAndPhoneActions();
break;
case LISTING_MODE:
setListingViews();
break;
}
nameTV.setText(hsProfileData.getFirstName() + " " + hsProfileData.getLastName());
initialsTV.setText(ProfileDataFormatter.getInitials(hsProfileData.getFirstName() + " " + hsProfileData.getLastName()));
HomeStoryApplication.getInstance().getPicasso(getActivity()).
load(HSApiController.getInstance().getClientProfileImageURL(profileId))
.fit()
.centerCrop()
.into(profileIV, new Callback.EmptyCallback() {
public void onSuccess() {
initialsTV.setVisibility(View.GONE);
}
});
doneTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getActivity().onBackPressed();
}
});
editTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (profileMode) {
case AGENT_MODE:
Intent editAgentProfileIntent = new Intent(getActivity(), AddNewSearchActivity.class);
editAgentProfileIntent.putExtra(PROFILE_ID, profileId);
editAgentProfileIntent.putExtra(PROFILE_MODE, AGENT_MODE);
startActivity(editAgentProfileIntent);
break;
case SEARCH_MODE:
Intent editSearchIntent = new Intent(getActivity(), AddNewSearchActivity.class);
editSearchIntent.putExtra(PROFILE_ID, profileId);
editSearchIntent.putExtra(PROFILE_MODE, SEARCH_MODE);
startActivity(editSearchIntent);
break;
case LISTING_MODE:
Intent editListingIntent = new Intent(getActivity(), AddNewListingActivity.class);
editListingIntent.putExtra(AddNewListingActivity.EXTRA_PROFILE_ID, listing.getProfileID());
startActivity(editListingIntent);
break;
}
}
});
}
UPDATE: Commonsware showed me how to fix the issue. I needed to pass in the ListView as the container for the views I was adding to the merge adapter. And then move the code over to onViewCreated,
Here is the updated code:
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ListView listView = getListView();
initViews(listView, view);
setViews();
setListAdapter(mergeAdapter);
}
And now initViews just gets the LayoutInflater from the host activity.
public void initViews(ViewGroup container, View v) {
LayoutInflater inflater = getActivity().getLayoutInflater();
....
Thanks for the help!
Solution
In initViews()
, you need the second parameter to your inflate()
calls to be the ListView
. That's not what you have -- you are passing in the container into which this fragment will be placed. Change initViews()
to use the ListView
in its inflate()
calls, and you should have better results.
Though to be honest, if I am correct in my interpretation of your code, I would be expecting you to crash in any Android environment, not just the Genymotion emulator.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.