Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
getString() を配置して呼び出す場所と方法に問題があります。
通常は定義するアクティビティの最初に試しましたが、常にエラーが発生します。onCreate() の後だけにする必要がありますか?
一部の文字列は頻繁に使用するため、使用するたびに getString() を使用したくありません。
これは正しい方法ですか?
private String helloWorld = getString(R.string.hello_world);
どうもありがとうございました!:)
ファイルの先頭で次のことを行います。
private String helloWorld;
そして、onCreate() で、
行う:
helloWorld = getString(R.String.hello_world).
問題は、getString が onCreate が呼び出されるまでクラスに関連付けられていないアクティビティ コンテキストへの参照を必要とすることです。