1. Are you ready for the Galaxy S20? Here is everything we know so far!

Problem solved, ignore this thread

Discussion in 'Android Development' started by MuteNightingale, Jan 23, 2016.

  1. MuteNightingale

    Thread Starter

    This problem has been solved. I am yet to figure how to delete this thread, but my solution was:
    - importing android.support.v7.widget.Toolbar
    - using the setSupportActionBar(Toolbar toolbar) method instead of setActionBar
    - extending the AppCompatActivity class instead (it worked; the real problem was the last point all along)
    - AND setting the value in res/values/styles to "NoActionBar"


    thanks anyway! ^^

    -----

    Hellowies, everyone. I am working on a schedule app (for a school seminar) and... ok, I'll cut to the point. Whenever I attempt to run it, logcat slaps the following "FATAL EXCEPTION" into my face:

    Code (Text):
    1.  
    2. FATAL EXCEPTION: main
    3.   Process: de.dbg.aylin.stundenplan, PID: 9478
    4.   java.lang.RuntimeException: Unable to start activity ComponentInfo{de.dbg.aylin.stundenplan/de.dbg.aylin.stundenplan.WeekActivity}: java.lang.ClassCastException: android.support.v7.widget.Toolbar cannot be cast to android.widget.Toolbar
    5.   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2344)
    6.   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
    7.   at android.app.ActivityThread.access$800(ActivityThread.java:145)
    8.   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
    9.   at android.os.Handler.dispatchMessage(Handler.java:102)
    10.   at android.os.Looper.loop(Looper.java:135)
    11.   at android.app.ActivityThread.main(ActivityThread.java:5319)
    12.   at java.lang.reflect.Method.invoke(Native Method)
    13.   at java.lang.reflect.Method.invoke(Method.java:372)
    14.   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
    15.   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
    16.   Caused by: java.lang.ClassCastException: android.support.v7.widget.Toolbar cannot be cast to android.widget.Toolbar
    17.   at de.dbg.aylin.stundenplan.WeekActivity.onCreate(WeekActivity.java:31)
    18.   at android.app.Activity.performCreate(Activity.java:5976)
    19.   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    20.   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)
    21.   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
    22.   at android.app.ActivityThread.access$800(ActivityThread.java:145)
    23.   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
    24.   at android.os.Handler.dispatchMessage(Handler.java:102)
    25.   at android.os.Looper.loop(Looper.java:135)
    26.   at android.app.ActivityThread.main(ActivityThread.java:5319)
    27.   at java.lang.reflect.Method.invoke(Native Method)
    28.   at java.lang.reflect.Method.invoke(Method.java:372)
    29.   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
    30.   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
    31.  
    ... I get the problem (I believe), but what can I do about it? We have to use minimum API 15 for our group project and if I attempt to use the obsolete actionbaractivity, Android Studio complains and the new AppCompatActivity ruins all essential other methods in my classes for some reason (they are all marked red the moment I try to extend something other than "Activity") .

    Have any of you had to deal with this problem before? :?

    Here, I'll post the relevant xml and code parts for those who are so kind as to look into this issue (THANK YOU ALL!!):

    XML:
    Code (Text):
    1.  
    2. <android.support.v7.widget.Toolbar
    3.     android:id="@+id/toolbarEdit"
    4.     android:layout_width="match_parent"
    5.     android:layout_height="wrap_content"
    6.     android:minHeight="?android:attr/actionBarSize">
    7.     <!--   android:background="@color/#..."  <- Farbe rausfinden!-->
    8.  
    9.     <Button
    10.         android:layout_width="wrap_content"
    11.         android:layout_height="wrap_content"
    12.         android:id="@+id/save"
    13.         android:text="Speichern"
    14.         android:onClick="speichern"
    15.         />
    16.  
    17.     <Button
    18.         android:layout_width="wrap_content"
    19.         android:layout_height="wrap_content"
    20.         android:id="@+id/cancel"
    21.         android:text="Abbruch"
    22.         android:onClick="abbrechen"/>
    23.  
    24.     <Button
    25.         android:layout_width="wrap_content"
    26.         android:layout_height="wrap_content"
    27.         android:id="@+id/zuStartseite2"
    28.         android:text="Home"
    29.         android:onClick="toMainActivity2" />
    30.  
    31. </android.support.v7.widget.Toolbar>
    ....annnnd the part in Java where this particular Toolbar is being used...and it apparently doesn't like the new v7 version. :

    Code (Text):
    1.  
    2. import android.widget.Toolbar;
    3. ... // You know, all the build stuff, class name, etc.
    4.  
    5. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarEdit);
    6. setActionBar(toolbar);
    7.  
    Similar Toolbars are gonna be used in two other activities as well. Now, importing android.support.v7.widget.Toolbar instead would be cool, but this way I can't use setActionBar(Toolbar t) or any other method doing the same job.. well, Android Studio doesn't suggest anything. <:"(

    Please help!
     


    #1 MuteNightingale, Jan 23, 2016
    Last edited: Jan 23, 2016

    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...