function with error messages: error / null or null. can't see why [duplicate]












-1
















This question already has an answer here:




  • What is a debugger and how can it help me diagnose problems?

    2 answers




I wrote a function:



    private static LinearFunction aproxFunction(List<Point> list) {
try{
int amountOfClusters = getAmountOfClusters(list);
//System.out.println(amountOfClusters); for debug
LinearFunction linear = new LinearFunction[amountOfClusters];
int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
clusters = getClusters(list, amountOfClusters);
for(int i = 0; i < amountOfClusters; i++) {
List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
int points = new int[pointsList.size()][3];
for(int j = 0; j < points.length; j++) {
points[j][0] = pointsList.get(j).getX();
points[j][1] = pointsList.get(j).getY();
points[j][2] = pointsList.get(j).getValue();
}
pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
int array = new int[2][2];
array = aprox(removeDuplicates(points));
if((array[1][0] - array[0][0]) == 0) {
linear[i].a = 0;
linear[i].b = 0;
linear[i].flag = true;
linear[i].c = array[0][0];
} else {
linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
linear[i].b = array[1][1] - array[1][0] * linear[i].a;
}
linear[i].cluster = clusters[i][0];
linear[i].id = convertIdToString(clusters[i][1]);
}
return linear;
} catch (Exception e) {
System.out.println("Error - aproxFunction: " + e.getMessage());
}
LinearFunction error = new LinearFunction[1];
error[0].a = -1;
return error;
}


and I constantly receive the error messages of either division by null or just null. I can't find the reason for that.
The only division in this function happens here:



linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);


but above that you have a check for null division, so how can I still get that error message.



As for the error message null I just don't know what it means. I read that it might be caused by an objects being null but how to find out which and where?










share|improve this question













marked as duplicate by luk2302, Raedwald java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    you should really print the stacktrace, inspect it and debug your code and step through it line by line. What is the exact error message? null is not 0 / zero.

    – luk2302
    Nov 22 '18 at 19:26











  • I checked in other parts of the code the input list isn't empty.

    – Jan Jankowski
    Nov 22 '18 at 19:30











  • the exact messages are null or sometimes I get the other one which is / by zero

    – Jan Jankowski
    Nov 22 '18 at 19:31











  • print the stacktrace.

    – luk2302
    Nov 22 '18 at 19:31











  • Error - aproxFunction: null java.lang.NullPointerException at projekt_msi.aproxFunction(projekt_msi.java:148) at projekt_msi.main(projekt_msi.java:105) Error - main: null

    – Jan Jankowski
    Nov 22 '18 at 19:40


















-1
















This question already has an answer here:




  • What is a debugger and how can it help me diagnose problems?

    2 answers




I wrote a function:



    private static LinearFunction aproxFunction(List<Point> list) {
try{
int amountOfClusters = getAmountOfClusters(list);
//System.out.println(amountOfClusters); for debug
LinearFunction linear = new LinearFunction[amountOfClusters];
int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
clusters = getClusters(list, amountOfClusters);
for(int i = 0; i < amountOfClusters; i++) {
List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
int points = new int[pointsList.size()][3];
for(int j = 0; j < points.length; j++) {
points[j][0] = pointsList.get(j).getX();
points[j][1] = pointsList.get(j).getY();
points[j][2] = pointsList.get(j).getValue();
}
pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
int array = new int[2][2];
array = aprox(removeDuplicates(points));
if((array[1][0] - array[0][0]) == 0) {
linear[i].a = 0;
linear[i].b = 0;
linear[i].flag = true;
linear[i].c = array[0][0];
} else {
linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
linear[i].b = array[1][1] - array[1][0] * linear[i].a;
}
linear[i].cluster = clusters[i][0];
linear[i].id = convertIdToString(clusters[i][1]);
}
return linear;
} catch (Exception e) {
System.out.println("Error - aproxFunction: " + e.getMessage());
}
LinearFunction error = new LinearFunction[1];
error[0].a = -1;
return error;
}


and I constantly receive the error messages of either division by null or just null. I can't find the reason for that.
The only division in this function happens here:



linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);


but above that you have a check for null division, so how can I still get that error message.



As for the error message null I just don't know what it means. I read that it might be caused by an objects being null but how to find out which and where?










share|improve this question













marked as duplicate by luk2302, Raedwald java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    you should really print the stacktrace, inspect it and debug your code and step through it line by line. What is the exact error message? null is not 0 / zero.

    – luk2302
    Nov 22 '18 at 19:26











  • I checked in other parts of the code the input list isn't empty.

    – Jan Jankowski
    Nov 22 '18 at 19:30











  • the exact messages are null or sometimes I get the other one which is / by zero

    – Jan Jankowski
    Nov 22 '18 at 19:31











  • print the stacktrace.

    – luk2302
    Nov 22 '18 at 19:31











  • Error - aproxFunction: null java.lang.NullPointerException at projekt_msi.aproxFunction(projekt_msi.java:148) at projekt_msi.main(projekt_msi.java:105) Error - main: null

    – Jan Jankowski
    Nov 22 '18 at 19:40
















-1












-1








-1









This question already has an answer here:




  • What is a debugger and how can it help me diagnose problems?

    2 answers




I wrote a function:



    private static LinearFunction aproxFunction(List<Point> list) {
try{
int amountOfClusters = getAmountOfClusters(list);
//System.out.println(amountOfClusters); for debug
LinearFunction linear = new LinearFunction[amountOfClusters];
int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
clusters = getClusters(list, amountOfClusters);
for(int i = 0; i < amountOfClusters; i++) {
List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
int points = new int[pointsList.size()][3];
for(int j = 0; j < points.length; j++) {
points[j][0] = pointsList.get(j).getX();
points[j][1] = pointsList.get(j).getY();
points[j][2] = pointsList.get(j).getValue();
}
pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
int array = new int[2][2];
array = aprox(removeDuplicates(points));
if((array[1][0] - array[0][0]) == 0) {
linear[i].a = 0;
linear[i].b = 0;
linear[i].flag = true;
linear[i].c = array[0][0];
} else {
linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
linear[i].b = array[1][1] - array[1][0] * linear[i].a;
}
linear[i].cluster = clusters[i][0];
linear[i].id = convertIdToString(clusters[i][1]);
}
return linear;
} catch (Exception e) {
System.out.println("Error - aproxFunction: " + e.getMessage());
}
LinearFunction error = new LinearFunction[1];
error[0].a = -1;
return error;
}


and I constantly receive the error messages of either division by null or just null. I can't find the reason for that.
The only division in this function happens here:



linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);


but above that you have a check for null division, so how can I still get that error message.



As for the error message null I just don't know what it means. I read that it might be caused by an objects being null but how to find out which and where?










share|improve this question















This question already has an answer here:




  • What is a debugger and how can it help me diagnose problems?

    2 answers




I wrote a function:



    private static LinearFunction aproxFunction(List<Point> list) {
try{
int amountOfClusters = getAmountOfClusters(list);
//System.out.println(amountOfClusters); for debug
LinearFunction linear = new LinearFunction[amountOfClusters];
int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
clusters = getClusters(list, amountOfClusters);
for(int i = 0; i < amountOfClusters; i++) {
List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
int points = new int[pointsList.size()][3];
for(int j = 0; j < points.length; j++) {
points[j][0] = pointsList.get(j).getX();
points[j][1] = pointsList.get(j).getY();
points[j][2] = pointsList.get(j).getValue();
}
pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
int array = new int[2][2];
array = aprox(removeDuplicates(points));
if((array[1][0] - array[0][0]) == 0) {
linear[i].a = 0;
linear[i].b = 0;
linear[i].flag = true;
linear[i].c = array[0][0];
} else {
linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
linear[i].b = array[1][1] - array[1][0] * linear[i].a;
}
linear[i].cluster = clusters[i][0];
linear[i].id = convertIdToString(clusters[i][1]);
}
return linear;
} catch (Exception e) {
System.out.println("Error - aproxFunction: " + e.getMessage());
}
LinearFunction error = new LinearFunction[1];
error[0].a = -1;
return error;
}


and I constantly receive the error messages of either division by null or just null. I can't find the reason for that.
The only division in this function happens here:



linear[i].a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);


but above that you have a check for null division, so how can I still get that error message.



As for the error message null I just don't know what it means. I read that it might be caused by an objects being null but how to find out which and where?





This question already has an answer here:




  • What is a debugger and how can it help me diagnose problems?

    2 answers








java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 19:21









Jan JankowskiJan Jankowski

255




255




marked as duplicate by luk2302, Raedwald java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by luk2302, Raedwald java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    you should really print the stacktrace, inspect it and debug your code and step through it line by line. What is the exact error message? null is not 0 / zero.

    – luk2302
    Nov 22 '18 at 19:26











  • I checked in other parts of the code the input list isn't empty.

    – Jan Jankowski
    Nov 22 '18 at 19:30











  • the exact messages are null or sometimes I get the other one which is / by zero

    – Jan Jankowski
    Nov 22 '18 at 19:31











  • print the stacktrace.

    – luk2302
    Nov 22 '18 at 19:31











  • Error - aproxFunction: null java.lang.NullPointerException at projekt_msi.aproxFunction(projekt_msi.java:148) at projekt_msi.main(projekt_msi.java:105) Error - main: null

    – Jan Jankowski
    Nov 22 '18 at 19:40
















  • 1





    you should really print the stacktrace, inspect it and debug your code and step through it line by line. What is the exact error message? null is not 0 / zero.

    – luk2302
    Nov 22 '18 at 19:26











  • I checked in other parts of the code the input list isn't empty.

    – Jan Jankowski
    Nov 22 '18 at 19:30











  • the exact messages are null or sometimes I get the other one which is / by zero

    – Jan Jankowski
    Nov 22 '18 at 19:31











  • print the stacktrace.

    – luk2302
    Nov 22 '18 at 19:31











  • Error - aproxFunction: null java.lang.NullPointerException at projekt_msi.aproxFunction(projekt_msi.java:148) at projekt_msi.main(projekt_msi.java:105) Error - main: null

    – Jan Jankowski
    Nov 22 '18 at 19:40










1




1





you should really print the stacktrace, inspect it and debug your code and step through it line by line. What is the exact error message? null is not 0 / zero.

– luk2302
Nov 22 '18 at 19:26





you should really print the stacktrace, inspect it and debug your code and step through it line by line. What is the exact error message? null is not 0 / zero.

– luk2302
Nov 22 '18 at 19:26













I checked in other parts of the code the input list isn't empty.

– Jan Jankowski
Nov 22 '18 at 19:30





I checked in other parts of the code the input list isn't empty.

– Jan Jankowski
Nov 22 '18 at 19:30













the exact messages are null or sometimes I get the other one which is / by zero

– Jan Jankowski
Nov 22 '18 at 19:31





the exact messages are null or sometimes I get the other one which is / by zero

– Jan Jankowski
Nov 22 '18 at 19:31













print the stacktrace.

– luk2302
Nov 22 '18 at 19:31





print the stacktrace.

– luk2302
Nov 22 '18 at 19:31













Error - aproxFunction: null java.lang.NullPointerException at projekt_msi.aproxFunction(projekt_msi.java:148) at projekt_msi.main(projekt_msi.java:105) Error - main: null

– Jan Jankowski
Nov 22 '18 at 19:40







Error - aproxFunction: null java.lang.NullPointerException at projekt_msi.aproxFunction(projekt_msi.java:148) at projekt_msi.main(projekt_msi.java:105) Error - main: null

– Jan Jankowski
Nov 22 '18 at 19:40














2 Answers
2






active

oldest

votes


















0














You are initialising an array of LinearFunctions, but you are not initialising each LinearFunction object inside it.



Have you tried this:



private static LinearFunction aproxFunction(List<Point> list) {
try{
int amountOfClusters = getAmountOfClusters(list);
//System.out.println(amountOfClusters); for debug
LinearFunction linear = new LinearFunction[amountOfClusters];
int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
clusters = getClusters(list, amountOfClusters);
for(int i = 0; i < amountOfClusters; i++) {
linear[i] = new LinearFunction()
...





share|improve this answer































    0














    I solved this NullPointerException like this:



                for(int i = 0; i < amountOfClusters; i++) {
    LinearFunction lf = new LinearFunction();
    List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
    int points = new int[pointsList.size()][3];
    for(int j = 0; j < points.length; j++) {
    points[j][0] = pointsList.get(j).getX();
    points[j][1] = pointsList.get(j).getY();
    points[j][2] = pointsList.get(j).getValue();
    }
    pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
    int array = new int[2][2];
    array = aprox(removeDuplicates(points));
    if((array[1][0] - array[0][0]) == 0) {
    lf.a = 0;
    lf.b = 0;
    lf.flag = true;
    lf.c = array[0][0];
    } else {
    lf.a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
    lf.b = array[1][1] - array[1][0] * linear[i].a;
    }
    lf.cluster = clusters[i][0];
    lf.id = convertIdToString(clusters[i][1]);
    linear[i] = lf;
    }


    So I created an object of the same class as the array, and only at the end of the loop I point it to an element of the array.






    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You are initialising an array of LinearFunctions, but you are not initialising each LinearFunction object inside it.



      Have you tried this:



      private static LinearFunction aproxFunction(List<Point> list) {
      try{
      int amountOfClusters = getAmountOfClusters(list);
      //System.out.println(amountOfClusters); for debug
      LinearFunction linear = new LinearFunction[amountOfClusters];
      int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
      clusters = getClusters(list, amountOfClusters);
      for(int i = 0; i < amountOfClusters; i++) {
      linear[i] = new LinearFunction()
      ...





      share|improve this answer




























        0














        You are initialising an array of LinearFunctions, but you are not initialising each LinearFunction object inside it.



        Have you tried this:



        private static LinearFunction aproxFunction(List<Point> list) {
        try{
        int amountOfClusters = getAmountOfClusters(list);
        //System.out.println(amountOfClusters); for debug
        LinearFunction linear = new LinearFunction[amountOfClusters];
        int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
        clusters = getClusters(list, amountOfClusters);
        for(int i = 0; i < amountOfClusters; i++) {
        linear[i] = new LinearFunction()
        ...





        share|improve this answer


























          0












          0








          0







          You are initialising an array of LinearFunctions, but you are not initialising each LinearFunction object inside it.



          Have you tried this:



          private static LinearFunction aproxFunction(List<Point> list) {
          try{
          int amountOfClusters = getAmountOfClusters(list);
          //System.out.println(amountOfClusters); for debug
          LinearFunction linear = new LinearFunction[amountOfClusters];
          int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
          clusters = getClusters(list, amountOfClusters);
          for(int i = 0; i < amountOfClusters; i++) {
          linear[i] = new LinearFunction()
          ...





          share|improve this answer













          You are initialising an array of LinearFunctions, but you are not initialising each LinearFunction object inside it.



          Have you tried this:



          private static LinearFunction aproxFunction(List<Point> list) {
          try{
          int amountOfClusters = getAmountOfClusters(list);
          //System.out.println(amountOfClusters); for debug
          LinearFunction linear = new LinearFunction[amountOfClusters];
          int clusters = new int[amountOfClusters][2]; // 2nd field 0 == r, 1 == g, 2 == b
          clusters = getClusters(list, amountOfClusters);
          for(int i = 0; i < amountOfClusters; i++) {
          linear[i] = new LinearFunction()
          ...






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 21:26









          pavlos163pavlos163

          504844




          504844

























              0














              I solved this NullPointerException like this:



                          for(int i = 0; i < amountOfClusters; i++) {
              LinearFunction lf = new LinearFunction();
              List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
              int points = new int[pointsList.size()][3];
              for(int j = 0; j < points.length; j++) {
              points[j][0] = pointsList.get(j).getX();
              points[j][1] = pointsList.get(j).getY();
              points[j][2] = pointsList.get(j).getValue();
              }
              pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
              int array = new int[2][2];
              array = aprox(removeDuplicates(points));
              if((array[1][0] - array[0][0]) == 0) {
              lf.a = 0;
              lf.b = 0;
              lf.flag = true;
              lf.c = array[0][0];
              } else {
              lf.a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
              lf.b = array[1][1] - array[1][0] * linear[i].a;
              }
              lf.cluster = clusters[i][0];
              lf.id = convertIdToString(clusters[i][1]);
              linear[i] = lf;
              }


              So I created an object of the same class as the array, and only at the end of the loop I point it to an element of the array.






              share|improve this answer




























                0














                I solved this NullPointerException like this:



                            for(int i = 0; i < amountOfClusters; i++) {
                LinearFunction lf = new LinearFunction();
                List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
                int points = new int[pointsList.size()][3];
                for(int j = 0; j < points.length; j++) {
                points[j][0] = pointsList.get(j).getX();
                points[j][1] = pointsList.get(j).getY();
                points[j][2] = pointsList.get(j).getValue();
                }
                pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
                int array = new int[2][2];
                array = aprox(removeDuplicates(points));
                if((array[1][0] - array[0][0]) == 0) {
                lf.a = 0;
                lf.b = 0;
                lf.flag = true;
                lf.c = array[0][0];
                } else {
                lf.a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
                lf.b = array[1][1] - array[1][0] * linear[i].a;
                }
                lf.cluster = clusters[i][0];
                lf.id = convertIdToString(clusters[i][1]);
                linear[i] = lf;
                }


                So I created an object of the same class as the array, and only at the end of the loop I point it to an element of the array.






                share|improve this answer


























                  0












                  0








                  0







                  I solved this NullPointerException like this:



                              for(int i = 0; i < amountOfClusters; i++) {
                  LinearFunction lf = new LinearFunction();
                  List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
                  int points = new int[pointsList.size()][3];
                  for(int j = 0; j < points.length; j++) {
                  points[j][0] = pointsList.get(j).getX();
                  points[j][1] = pointsList.get(j).getY();
                  points[j][2] = pointsList.get(j).getValue();
                  }
                  pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
                  int array = new int[2][2];
                  array = aprox(removeDuplicates(points));
                  if((array[1][0] - array[0][0]) == 0) {
                  lf.a = 0;
                  lf.b = 0;
                  lf.flag = true;
                  lf.c = array[0][0];
                  } else {
                  lf.a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
                  lf.b = array[1][1] - array[1][0] * linear[i].a;
                  }
                  lf.cluster = clusters[i][0];
                  lf.id = convertIdToString(clusters[i][1]);
                  linear[i] = lf;
                  }


                  So I created an object of the same class as the array, and only at the end of the loop I point it to an element of the array.






                  share|improve this answer













                  I solved this NullPointerException like this:



                              for(int i = 0; i < amountOfClusters; i++) {
                  LinearFunction lf = new LinearFunction();
                  List<Point> pointsList = new ArrayList<>(getPointsInCluster(list, clusters[i][0], convertIdToString(clusters[i][1])));
                  int points = new int[pointsList.size()][3];
                  for(int j = 0; j < points.length; j++) {
                  points[j][0] = pointsList.get(j).getX();
                  points[j][1] = pointsList.get(j).getY();
                  points[j][2] = pointsList.get(j).getValue();
                  }
                  pointsToFile(pointsList, clusters[i][0], convertIdToString(clusters[i][1]), "_points_in_cluster_");
                  int array = new int[2][2];
                  array = aprox(removeDuplicates(points));
                  if((array[1][0] - array[0][0]) == 0) {
                  lf.a = 0;
                  lf.b = 0;
                  lf.flag = true;
                  lf.c = array[0][0];
                  } else {
                  lf.a = (array[1][1] - array[0][1]) / (array[1][0] - array[0][0]);
                  lf.b = array[1][1] - array[1][0] * linear[i].a;
                  }
                  lf.cluster = clusters[i][0];
                  lf.id = convertIdToString(clusters[i][1]);
                  linear[i] = lf;
                  }


                  So I created an object of the same class as the array, and only at the end of the loop I point it to an element of the array.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 21:26









                  Jan JankowskiJan Jankowski

                  255




                  255















                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen