Android studio android studio java.lang.NullPointerException

Android studio android studio java.lang.NullPointerException,android-studio,Android Studio,所以我正在开发一个需要在sd卡中写入的应用程序,当我尝试在文件中写入时,它会显示:java.lang.NullPointerException 这是我的密码: public void goWrite() { File sdPath = Environment.getExternalStorageDirectory(); sdPath = new File(sdPath.getAbsolutePath() + "/" + DIR); sdPath.mkdir();

所以我正在开发一个需要在sd卡中写入的应用程序,当我尝试在文件中写入时,它会显示:
java.lang.NullPointerException
这是我的密码:

public void goWrite() {
    File sdPath = Environment.getExternalStorageDirectory();
    sdPath = new File(sdPath.getAbsolutePath() + "/" + DIR);
    sdPath.mkdir();
    Toast.makeText(this ,"" + sdPath ,Toast.LENGTH_LONG).show();
    File sdFile = new File(sdPath ,filename);
    try {
        BufferedWriter bw = new BufferedWriter(new FileWriter(sdFile));
        bw.write("Correct answers - " + correct + "\nincorrect answers - " + incorrect);
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
这是我的舱单


我需要做什么?
感谢您的帮助:D

在goWrite方法中。。。它没有确切说明NPE在哪里logcat应该包括callstack(带有行号)…Oops没有注意到这一点,问题在于sdFile声明行
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".indentification"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".trivia"
        android:label="@string/title_activity_indentification" >
    </activity>
    <activity
        android:name=".Summary"
        android:label="@string/title_activity_summary" >
    </activity>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

</application>