好吧,我读了很多关于这个错误的文章,现在我觉得我疯了,下面是我的活动的onCreate。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_event);
i_name= (EditText)findViewById(R.id.input_event_name);
i_loc = (EditText)findViewById(R.id.input_event_location);
i_date = (EditText)findViewById(R.id.input_event_date);
i_time = (EditText)findViewById(R.id.input_event_time);
i_desc = (EditText)findViewById(R.id.input_event_description);
final LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.action_bar_edit_mode, null);
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));我从here获得了两个actionbar按钮的代码。我在我的笔记本电脑上翻了一遍,现在我正试着让它在我的电脑上工作。
现在我读到了一些关于“我在我的活动中没有行动栏”和关于“我没有标题集”的文章。在我的笔记本电脑上效果很好。我试着设置Feature_action标杆。getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
我也试图设定另一个主题,但没有任何帮助。
minSdkVersion 11 targetSdkVersion 21
逻辑猫
java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2277)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5147)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.test.test2.NewEvent.onCreate(NewEvent.java:92)有谁知道发生了什么,我可以尝试另一个想法吗?
发布于 2014-11-20 16:19:14
由于您使用的是ActionBarActivity (来自支持库),所以需要调用支持方法:
getSupportActionBar();编辑-回复评论:
就像你那样做:
getSupportActionBar().setCustomView(view, new ActionBar.LayoutParams(ViewGroup
.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));但是,确保只从support导入 ActionBar:
import android.support.v7.app.ActionBar;https://stackoverflow.com/questions/27044265
复制相似问题