なぜこのコードがエラーを投げているのですか?エラーの原因をトレースしています。java.lang.NullPointerException
if (getActivity().getApplicationContext() != null){
File file = new File(getActivity().getApplicationContext().getFilesDir() + "/img.jpg"); }
上記のコードは私のフラグメント内
私のエラーです:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.support.v4.app.FragmentActivity.getApplicationContext()' on a null object reference
おそらく、何の活動もありません。 – ifly6
@ ifly6 allright、どうすればこれを防ぐことができますか?任意のアイデア –
ヌルをチェックしたい場合は、ヌルチェックを変更する可能性があります。 – ifly6