CalendarViewActivityがあるカレンダーライブラリがあります。
私のプロジェクトはこのライブラリを使用し、CalendarViewActivityを拡張してカスタムアクティビティのタイトルを設定します。
CalendarActivity:
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)