Learn, Share, Build

107
October 14, 2017, at 01:30 AM

• What is a NullPointerException, and how do I fix it? 12 answers

I have to iterate over 3 triangles (Dreieck x,y,z, IT IS NECESSARY THAT THEY HAVE THESE NAMES), and I want them in one Array.

I have written a method "check If Valid" which checks if it is possible to construct these triangle. If it is possible, it should return "true". I have written a foreach loop and I want that for every triangle in the array dreiecke it should print "true" if it is possible to construct it and "false" if it isn't possible. In my case it throws a `NullPointerException`.

Is there something wrong with initializing the Array?

``````public class DreieckTest {
public static void main(String[] args) {
Dreieck[] dreiecke = new Dreieck[3];
//triangle
Dreieck x = new Dreieck(1, 7, 5);
Dreieck y = new Dreieck(3, 4, 5);
Dreieck z = new Dreieck(5, 3, 3);
for(Dreieck dreieck: dreiecke) {
System.out.println(dreieck.istGültig());
}
}
}
``````

and here is the class Dreieck:

``````public class Dreieck {
// attribute
private int a;
private int b;
private int c;
public Dreieck(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
//check if possible
public boolean istGültig() {
if (a + b > c ^ a + c > b ^ b + c > a) {
return true;
} else {
return false;
}
}
``````

Use this

``````dreiecke[0]= new Dreieck(1, 7, 5);
dreiecke[1] = new Dreieck(3, 4, 5);
dreiecke[2] = new Dreieck(5, 3, 3);
``````
POPULAR ONLINE

Learn, Share, Build

I have written a kafka connect jar and I get below error:

209

Learn, Share, Build

I am trying to convert JNEAT into ajar file, using Apache Ant (and following these instructions)

172

Learn, Share, Build

Is there a simple which analog for maven to locate jars in the local repository?

137

Learn, Share, Build

I work on projects that use a lot of different types of lists, so I did this

190