I am using Tone Analyzer of IBM Watson in my Android Code,but i keep getting java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
Following is my code
public class MainActivity extends AppCompatActivity {
    final ToneAnalyzer toneAnalyzer =
            new ToneAnalyzer("2018-01-19");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        JSONObject credentials = null; // Convert the file into a JSON object
        try {
            credentials = new JSONObject(IOUtils.toString(
                    getResources().openRawResource(R.raw.credentials), "UTF-8"
            ));
            String username = credentials.getString("username");
            String password = credentials.getString("password");
            toneAnalyzer.setUsernameAndPassword(username, password);
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Button analyzeButton = (Button)findViewById(R.id.analyze_button);
        analyzeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditText userInput = (EditText)findViewById(R.id.user_input);
                final String textToAnalyze = userInput.getText().toString();
                ToneOptions options = new ToneOptions.Builder()
                        .addTone(Tone.EMOTION)
                        .html(false).build();
                toneAnalyzer.getTone(textToAnalyze, options).enqueue(
                        new ServiceCallback<ToneAnalysis>() {
                            @Override
                            public void onResponse(ToneAnalysis response) {
                                Log.i("Hii", "onResponse: "+response.getDocumentTone());
                                List<ToneScore> scores = response.getDocumentTone()
                                        .getTones()
                                        .get(0)
                                        .getTones();
                                String detectedTones = "";
                                for(ToneScore score:scores) {
                                    if(score.getScore() > 0.5f) {
                                        detectedTones += score.getName() + " ";
                                    }
                                }
                                final String toastMessage =
                                        "The following emotions were detected:\n\n"
                                                + detectedTones.toUpperCase();
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        Toast.makeText(getBaseContext(),
                                                toastMessage, Toast.LENGTH_LONG).show();
                                    }
                                });
                            }
                            @Override
                            public void onFailure(Exception e) {
                                e.printStackTrace();
                            }
                        });
            }
        });
    }
}
Can somebody point out what am i doing wrong. I have kept my credentials.json file in raw folder. I tried writing every emotion in my Android App but i keep getting no response. Any help would be greatly appreciated.