0

I am trying to get a shadow effect to slider Listview. I am trying to put a RelativeLayout with the shadow image beneath the ListView. I have done the following in my xml file but I get force closes with the following errors. Please guide me step by step what to do and where I am going wrong.

My xml file

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"

android:layout_height="match_parent">


<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 


   >




</FrameLayout>


     <FrameLayout
        android:layout_width="250dp"
        android:layout_height="match_parent"
         > 

   <ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="#656565"
    android:dividerHeight="0.01dp"
     android:fadingEdgeLength="10dp"

    android:background="@color/list_background"
    android:listSelector="@drawable/list_selector"
   />

</FrameLayout>
   </android.support.v4.widget.DrawerLayout>

error logs:

 05-02 17:37:03.256: E/AndroidRuntime(3132): FATAL EXCEPTION: main
 05-02 17:37:03.256: E/AndroidRuntime(3132): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.taskmanager/com.example.taskmanager.Profile}: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.os.Handler.dispatchMessage(Handler.java:99)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.os.Looper.loop(Looper.java:137)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.app.ActivityThread.main(ActivityThread.java:5041)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at java.lang.reflect.Method.invokeNative(Native Method)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at java.lang.reflect.Method.invoke(Method.java:511)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at dalvik.system.NativeStart.main(Native Method)
 05-02 17:37:03.256: E/AndroidRuntime(3132): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:857)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1058)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at com.example.taskmanager.Profile.SelectItem(Profile.java:311)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at com.example.taskmanager.Profile.onCreate(Profile.java:152)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.app.Activity.performCreate(Activity.java:5104)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
 05-02 17:37:03.256: E/AndroidRuntime(3132):    ... 11 more
 05-02 17:38:42.195: E/Trace(3353): error opening trace file: No such file or directory (2)
 05-02 17:38:44.306: E/AndroidRuntime(3353): FATAL EXCEPTION: main
 05-02 17:38:44.306: E/AndroidRuntime(3353): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.taskmanager/com.example.taskmanager.Profile}: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.os.Handler.dispatchMessage(Handler.java:99)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.os.Looper.loop(Looper.java:137)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.app.ActivityThread.main(ActivityThread.java:5041)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at java.lang.reflect.Method.invokeNative(Native Method)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at java.lang.reflect.Method.invoke(Method.java:511)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at dalvik.system.NativeStart.main(Native Method)
 05-02 17:38:44.306: E/AndroidRuntime(3353): Caused by: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:857)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1058)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at com.example.taskmanager.Profile.SelectItem(Profile.java:311)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at com.example.taskmanager.Profile.onCreate(Profile.java:152)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.app.Activity.performCreate(Activity.java:5104)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
 05-02 17:38:44.306: E/AndroidRuntime(3353):    ... 11 more

Profile.class

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    final HashMap<String, String> c=db.getAddedContacts();
    // Initializing
    dataList = new ArrayList<DrawerItem>();
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
     TypefaceSpan tp;
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
            GravityCompat.START);
          final ActionBar actionBar = getActionBar();

    actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.green));
    actionBar.setCustomView(R.layout.actionbars);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setIcon(
              new ColorDrawable(getResources().getColor(android.R.color.transparent)));  
13
  • Line 311 in Profile.java.
    – vjdhama
    May 2, 2014 at 17:52
  • 1
    Please post the Activity code where you reference this layout. According to this, can't help to much other than tell you, its not possible to cast a DrawerLayout to Relative layout and its throwing a ClassCastException cause it says your trying to do that
    – kandroidj
    May 2, 2014 at 17:52
  • I have not refernced this layout anywhere in my activity code. Just added in the xml file
    – user3509091
    May 2, 2014 at 17:58
  • The error is in your Activity code.
    – vjdhama
    May 2, 2014 at 18:00
  • K then I will add my activity code
    – user3509091
    May 2, 2014 at 18:00

1 Answer 1

1

Apparently you have your listView inside of FrameLayout. If you remove it things will works just fine.

Otherwise set a id to 2nd frameLayout in xml

android:id="@+id/framelayout"

and then get the instance of that FrameLayout

FrameLayout frameLayout = (LinearLayout) findViewById(R.id.frameLayout);

Pass instance of the FrameLayout to mDrawerLayout.closeDrawer(frameLayout);.

Hope this solves the problem.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.