アプリの 1 つで非常にイライラする問題に遭遇しました。
アプリの初期データをロードし、メイン アクティビティを起動して終了するスプラッシュ スクリーン アクティビティがあります。
メイン アクティビティが実行されたら、ホーム キーを押してアプリをバックグラウンドで実行し、アプリのプロセスを強制終了します。
アプリを再起動すると、スプラッシュスクリーンが実行されようとしますが、R.java ファイルのいずれかのフィールドにアクセスしようとするとすぐに失敗します。
たとえば、私はすぐにテキストビューのテキストを次のように設定しようとします:
((TextView)findViewById(R.id.splash_tv_1)).setText(application.getLanguage().pleasewait);
これにより、次の例外がスローされます。
06-29 11:18:14.661: ERROR/AndroidRuntime(21427): java.lang.NoSuchFieldError: com.pagesuite.android.reader.framework.R$id.splash_tv_1
その後、もう一度起動すると問題ありません。
TaskKiller ツール (多くのユーザーが素朴に使用していると思われるツール) を使用してアプリを強制終了した場合、または OS がプロセスを強制終了した場合も、同じ動作になります。
何か案は?
編集:
このアクティビティの onCreate() が実行される直前に、logcat で気付きましたが、次のログが記録されています。
06-29 11:18:14.571: WARN/dalvikvm(21427): VFY: unable to resolve static field 1945 (splash_logo) in Lcom/pagesuite/android/reader/framework/R$id;
06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: replacing opcode 0x60 at 0x0000
06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: dead code 0x0002-0010 in Lcom/pagesuite/android/reader/framework/activities/PS_Splashscreen;.loadLogoImg (Lcom/pagesuite/android/reader/framework/xml/appsettings/PS_AppSettings;)V
06-29 11:18:14.571: DEBUG/dalvikvm(21427): DexOpt: couldn't find static field
06-29 11:18:14.571: WARN/dalvikvm(21427): VFY: unable to resolve static field 1946 (splash_tv_1) in Lcom/pagesuite/android/reader/framework/R$id;
06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: replacing opcode 0x60 at 0x0000
06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: dead code 0x0002-0039 in Lcom/pagesuite/android/reader/framework/activities/PS_Splashscreen;.setLanguage ()V
06-29 11:18:14.571: DEBUG/dalvikvm(21427): DexOpt: couldn't find static field
06-29 11:18:14.571: WARN/dalvikvm(21427): VFY: unable to resolve static field 1946 (splash_tv_1) in Lcom/pagesuite/android/reader/framework/R$id;
06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: replacing opcode 0x60 at 0x0000
06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: dead code 0x0002-0020 in Lcom/pagesuite/android/reader/framework/activities/PS_Splashscreen;.setTextColors ()V
これらは、クラスで R.id にアクセスしようとする 3 つのインスタンスです。
注意すべきことの1つは、私が電話することです:
setContentView(R.layout.ps_splashscreen);
この行は正常に実行されているように見えるため、特にR.idが欠落しているようです。
編集:レイアウトは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="@+id/splash_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/splash_tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please wait"
android:textColor="@color/white"
android:textSize="20dip" />
<TextView
android:id="@+id/splash_tv_2"
android:layout_marginTop="20dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading..."
android:textColor="@color/white" />
</LinearLayout>