I'm trying to get the numerical sum of an ArrayList called proStarsArray
when the okDone
button is activated, and send that data as a string to my next activity to be printed via a TextView. I receive no warnings when the for
loop is added to the okDone
button's case in the code, but when I test the app, it crashes as soon as the the okDone
button is activated.
I've tried creating an if
statement, and formatting the for loop without brackets around the "do this" section of the statement, to no avail. It still crashes as soon as I try to start the next activity. I'm not seeing the likely, ridiculously simple solution to this problem of mine. Please help me dudes.
Here is the code from the activity in question.
package com.progolferrating.progolferrating;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class ProsGolfer extends Activity implements View.OnClickListener {
RatingBar ratingBar1;
TextView tvproResult;
Button enterMore;
Button okDone;
Double sum;
float[] proHolder = new float[1];
List <Double> proStarsArray = new ArrayList<>();
//Some methods have been omitted for this display
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.enterMore:
proStarsArray.add(Double.valueOf(proHolder[0]));
tvproResult2.setText(String.valueOf(proStarsArray));
break;
The code in question below
case R.id.okDone:
for (Double temp : proStarsArray) {
sum += temp;
}
Intent intent = new Intent(ProsCons.this,FinalStars.class);
intent.putExtra("sumProArray", sum.toString());
startActivity(intent);
break;
}
}
}
Here is the Exception log
09-11 21:10:12.517 24921-24921/com.verdictdecision.verdictdecision E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.verdictdecision.verdictdecision, PID: 24921
java.lang.NullPointerException
at com.progolferrating.progolferrating.ProsGolfer.onClick(ProsGolfer.java:86)
at android.view.View.performClick(View.java:4480)
at android.view.View$PerformClick.run(View.java:18673)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5872)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
at dalvik.system.NativeStart.main(Native Method)