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:
... 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:
....annnnd the part in Java where this particular Toolbar is being used...and it apparently doesn't like the new v7 version. :
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!
- 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:
FATAL EXCEPTION: main
Process: de.dbg.aylin.stundenplan, PID: 9478
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
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2344)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.ClassCastException: android.support.v7.widget.Toolbar cannot be cast to android.widget.Toolbar
at de.dbg.aylin.stundenplan.WeekActivity.onCreate(WeekActivity.java:31)
at android.app.Activity.performCreate(Activity.java:5976)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
... 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:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize">
<!-- android:background="@color/#..." <- Farbe rausfinden!-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/save"
android:text="Speichern"
android:onClick="speichern"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cancel"
android:text="Abbruch"
android:onClick="abbrechen"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/zuStartseite2"
android:text="Home"
android:onClick="toMainActivity2" />
</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:
import android.widget.Toolbar;
... // You know, all the build stuff, class name, etc.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarEdit);
setActionBar(toolbar);
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!
Last edited: