cant use ActionBar methods in android studio -
i trying set things action bar same errors on method use (e.g actionbar.settitle("my title");
or actionbar.setbackgrounddrawable(r.drawable.actionbar_draw);
)
i cant use methods it...
they give error:
required android.support.v7.app.actionbar found android.app.actionbar
i using minimum sdk 15 , code:
package com.tos.test.testactionbarapp; import android.support.v7.app.actionbar; import android.support.v7.app.appcompatactivity; import android.os.bundle; public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); actionbar actionbar = getactionbar(); actionbar.settitle("my title"); } }
problem is, app crashes whenever start because of code , get:
---
------ beginning of crash 05-28 15:32:00.403 11476-11476/ccom.tos.test.testactionbarapp e/androidruntime: fatal exception: main process: com.tos.test.testactionbarapp, pid: 11476 java.lang.runtimeexception: unable start activity componentinfo{com.tos.test.testactionbarapp/com.tos.test.testactionbarapp.mainactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'java.lang.charsequence android.app.actionbar.gettitle()' on null object reference @ android.app.activitythread.performlaunchactivity(activitythread.java:2325) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2387) @ android.app.activitythread.access$800(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1303) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5254) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698) caused by: java.lang.nullpointerexception: attempt invoke virtual method 'java.lang.charsequence android.app.actionbar.gettitle()' on null object reference @ com.tos.test.testactionbarapp.mainactivity.oncreate(mainactivity.java:21) @ android.app.activity.performcreate(activity.java:5990) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1106) @ android.app.activitythread.performlaunchactivity(activitythread.java:2278) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2387) @ android.app.activitythread.access$800(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1303) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5254) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698)
you have import android.support.v7.app.actionbar
, use getsupportactionbar()
method od activity.
Comments
Post a Comment