我有日历库,其中有 CalendarViewActivity。
我的项目使用这个库并扩展 CalendarViewActivity 来设置自定义活动标题。
日历活动:
public class CalendarActivity extends CalendarViewActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set custom activity title
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.window_title);
TextView title = (TextView) getWindow().findViewById(R.id.txt_header);
if (isGo) {
title.setText(getResources().getString(R.string.title_date_go));
} else {
title.setText(getResources().getString(R.string.title_date_go_back));
}
}
}
在某些设备中(确切地知道:asus tf101,Samsung Galaxy Gio S5660)我在这一行得到 NullPointerException:
super.onCreate(savedInstanceState);
这引用了库中的这一行(此处出现异常):
((Button) findViewById(R.id.btn_today)).setOnClickListener(this);
Xml 布局(库中的 CalendarViewActivity):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/calendar_header"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/prevMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/descr_btn_prev_month"
android:src="@drawable/calendar_left_arrow_selector" >
</ImageView>
<TextView
android:id="@+id/currentMonth"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" >
</TextView>
<ImageView
android:id="@+id/nextMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/descr_btn_next_month"
android:src="@drawable/calendar_right_arrow_selector" >
</ImageView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp" >
<GridView
android:id="@+id/calendarHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/transparent"
android:numColumns="7" >
</GridView>
<GridView
android:id="@+id/calendar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/calendar_bg"
android:listSelector="@android:color/transparent"
android:numColumns="7">
</GridView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp">
<Button
android:id="@+id/btn_today"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/calendar_button"
android:text="@string/btn_today"
android:gravity="center"
android:textColor="@android:color/white"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button
android:id="@+id/btn_tomorrow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/calendar_button"
android:text="@string/btn_tomorrow"
android:gravity="center"
android:textColor="@android:color/white"
android:layout_marginLeft="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
这仅出现在某些设备中,其他设备正常。
这很奇怪..
请帮助我,非常感谢!
编辑:
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.package.package/net.package.package.ui.activities.CalendarActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.metalex.calendarview.UI.Activities.CalendarViewActivity.onCreate(CalendarViewActivity.java:118)
at net.aviascanner.aviascanner.ui.activities.CalendarActivity.onCreate(CalendarActivity.java:20)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
java.lang.NullPointerException
at com.metalex.calendarview.UI.Activities.CalendarViewActivity.onCreate(CalendarViewActivity.java:118)
at net.aviascanner.aviascanner.ui.activities.CalendarActivity.onCreate(CalendarActivity.java:20)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)