java.lang.ArrayIndexOutOfBoundsException at lösung.main

Immo Primus

Mitglied
Hey, habe ein (wie es mir scheint) fehlerfreies Programm geschrieben, bekomme aber folgende Fehlermeldung:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at lösung.main(lösung.java:7)

Kann mir jemand weiterhelfen wie ich das Problem abstelle, bzw. wo der Fehler liegt?
Java:
public class lösung
{
    public static void main (String[] args)
    {
     int n = args.length, s = 0;
     int von = Integer.parseInt(args[0]);
     int bis = Integer.parseInt(args[n]);
     int erg = sum(args , von, bis);
      
        System.out.println(erg);
    }
       public static int sum(String[] v, int von, int bis)
      {
          if (bis - von <= 1 )
         {
           return Integer.parseInt(v[von]);
         }
          else
         {
           int mid  = (bis + von)/2;
           return sum(v,von,mid) + sum(v,mid,bis);
         }


      }
  
}
 

truesoul

Top Contributor
Hallo.

int bis = Integer.parseInt(args[n]);

Beim index vom Array fängt man bei 0 an, wenn ein Array die länge von 2 hat kann der größte index also welchen Wert haben?

Grüße
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
F TableModelListener: java.lang.ArrayIndexOutOfBoundsException: 132 Java Basics - Anfänger-Themen 3
F Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11 at main.main(main.java:11) Java Basics - Anfänger-Themen 2
JaVaN0oB java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 18
R Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 5
I Compiler-Fehler Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 Java Basics - Anfänger-Themen 3
R java.lang.ArrayIndexOutOfBoundsException: 0 Rechner Error Java Basics - Anfänger-Themen 4
C Compiler-Fehler Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 Java Basics - Anfänger-Themen 3
V java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 2
L Fehler: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 4
L Compiler-Fehler Problem beim Programmieren eines Kalenders (java.lang.ArrayIndexOutOfBoundsException) Java Basics - Anfänger-Themen 2
B java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 4
R Compiler-Fehler java.lang.ArrayIndexOutOfBoundsException, warum? Java Basics - Anfänger-Themen 6
H java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 Java Basics - Anfänger-Themen 5
S java.lang.ArrayIndexOutOfBoundsException: 5 nur wieso? Java Basics - Anfänger-Themen 2
V java.lang.ArrayIndexOutOfBoundsException: Java Basics - Anfänger-Themen 3
O Exception in thread "main" java.lang.ArithmeticException: / by zero Java Basics - Anfänger-Themen 4
F Fehlermeldung java.lang.NullPointerException Java Basics - Anfänger-Themen 4
D java.lang.NullPointerException Java Basics - Anfänger-Themen 19
X java.lang.NullPointerException fehler ? Java Basics - Anfänger-Themen 1
S Compiler-Fehler Exception in thread "main" java.lang.Error: Unresolved compilation problem: Java Basics - Anfänger-Themen 6
B java.lang.NullPointerException bei javafx Java Basics - Anfänger-Themen 10
H JUnit in Eclipse: java.lang.NoClassDefFoundError: Java Basics - Anfänger-Themen 9
B java.lang.ArithmeticException: / by zero Java Basics - Anfänger-Themen 3
P java.lang.ClassCastException Bedeutung und Lösung Java Basics - Anfänger-Themen 3
J Erste Schritte java.lang.NoClassDefFoundError Java Basics - Anfänger-Themen 4
R Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 10
T Compiler-Fehler java.lang.ArithmeticException: / by zero Java Basics - Anfänger-Themen 2
D Erste Schritte Java.lang.NullPointer.Exception Java Basics - Anfänger-Themen 8
H java.lang.NullPointerException Java Basics - Anfänger-Themen 4
G java.lang.NullPointerException Java Basics - Anfänger-Themen 3
N jodaTime java.lang.IllegalArgumentException: Invalid format Java Basics - Anfänger-Themen 3
E Compiler-Fehler java.lang.NullPointerException Java Basics - Anfänger-Themen 2
F Erste Schritte java.lang.StringIndexOutOfBoundsException Java Basics - Anfänger-Themen 3
J java.lang.NullPointerException in meiner JavaFXControllerKlasse Java Basics - Anfänger-Themen 26
R java.lang.StringIndexOutOfBoundsException Java Basics - Anfänger-Themen 1
D Communications link failure | java.lang.NullPointerException Java Basics - Anfänger-Themen 3
H java.lang.NoClassDefFoundError Run as>> Run on Server Java Basics - Anfänger-Themen 2
F java.lang.NullPointerException, kann aber nicht sein! Java Basics - Anfänger-Themen 4
S Java memory fehler: Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap spa Java Basics - Anfänger-Themen 5
M java.lang.Enum.valueOf(Unknown Source) Java Basics - Anfänger-Themen 2
A Code läuft nicht, Fehlermeldung Exception in thread "main" java.lang.Error: Unresolved compilation " Java Basics - Anfänger-Themen 11
P Exception in thread "main" java.lang.NoClassDefFoundError: Java Basics - Anfänger-Themen 1
C Hilfe!!! java.lang.ClassCastException Java Basics - Anfänger-Themen 1
O java.lang.IndexOutOfBoundsException JTable autoSort Java Basics - Anfänger-Themen 5
M Compiler-Fehler Java suckt - java.lang.NullPointerException Java Basics - Anfänger-Themen 12
W Methoden Rückgabedatentyp java.util.Map<java.lang.String,? extends ...> Java Basics - Anfänger-Themen 4
L Compiler-Fehler Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 2
F Exception in thread main java.lang.StackOverflowError Java Basics - Anfänger-Themen 3
K Caused by: java.lang.NoClassDefFoundError: org/mindrot/jbcrypt/BCrypt Java Basics - Anfänger-Themen 0
S java.lang.NullPointerException Java Basics - Anfänger-Themen 4
G Compiler-Fehler java.lang.NullPointerException Java Basics - Anfänger-Themen 4
OnDemand java.lang.reflect.InvocationTargetException Java Basics - Anfänger-Themen 9
A Compiler-Fehler Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 7
J Klassen java.lang.String - lexikographisches Sortieren Java Basics - Anfänger-Themen 5
P Interpreter-Fehler java.lang.NullPointerException Java Basics - Anfänger-Themen 3
T Erste Schritte import java.lang.System.out Java Basics - Anfänger-Themen 4
T Problem mit Eclipse? Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 4
H Classpath java.lang.NoClassDefFoundError externe Libary Java Basics - Anfänger-Themen 4
M Exception in thread "main" java.lang.NoClassDefFoundError: MeineKlasse Java Basics - Anfänger-Themen 12
X Applet Fehler: java.lang.reflect.InvocationTargetException Java Basics - Anfänger-Themen 45
K Date cannot be cast to java.lang.Integer Java Basics - Anfänger-Themen 4
H java.lang.IndexOutOfBoundsException bei verschachtelter ArrayList Java Basics - Anfänger-Themen 9
S Fehler: "java.lang.NullPointerException" Java Basics - Anfänger-Themen 6
V java.lang.NoSuchMethodError Java Basics - Anfänger-Themen 2
J java.lang.math asin() Java Basics - Anfänger-Themen 18
I Erste Schritte Ausführfehler: java.lang.NullPointerException Java Basics - Anfänger-Themen 3
K Error: java.lang.NoSuchMethodException Java Basics - Anfänger-Themen 2
M Compiler-Fehler Fehler Meldung java.lang.NumberFormatException: empty String Java Basics - Anfänger-Themen 2
G java.lang.ClassNotFoundException Java Basics - Anfänger-Themen 4
1 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException Java Basics - Anfänger-Themen 5
S Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 11
S String index out of range: 8 at java.lang.String.substring(Unknown Source) Java Basics - Anfänger-Themen 13
V [Greenfoot] java.lang.NullPointerException Java Basics - Anfänger-Themen 12
S Compiler-Fehler java.lang.NullPointerException Java Basics - Anfänger-Themen 10
X Interpreter-Fehler "java.lang.NullPionterException: null" bei BlueJ Java Basics - Anfänger-Themen 10
P java.lang.ClassCastException Java Basics - Anfänger-Themen 2
D java.lang.NoSuchMethodError: main Java Basics - Anfänger-Themen 11
S expected java.lang.string but found char Java Basics - Anfänger-Themen 5
S Umgebungsvariable Exception in thread "main" java.lang.UnsatisfiedLinkError: no J3D in java.librar y.path Java Basics - Anfänger-Themen 15
S Compiler-Fehler java.lang.SecurityException: Invalid signature file digest for Manifest main attributes Java Basics - Anfänger-Themen 5
M Klassen Exception in thread "main" java.lang.NoClassDefFoundError: Java Basics - Anfänger-Themen 2
A Compiler-Fehler unreported exception java.lang.Exception; must be caught or declared to be thrown Java Basics - Anfänger-Themen 7
K Fehlermeldung: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 Java Basics - Anfänger-Themen 4
M Datentypen java.util.Arrays$ArrayList cannot be cast to [Ljava.lang.String; Java Basics - Anfänger-Themen 11
J java.lang.NullPointerException Java Basics - Anfänger-Themen 18
K Interpreter-Fehler java.lang.NullPointerException Java Basics - Anfänger-Themen 6
F Ich kenn mich nicht mehr aus - 'java.lang.NoSuchMethodError: main' in Applet? Java Basics - Anfänger-Themen 2
K OOP java.lang.NullPointerException Java Basics - Anfänger-Themen 2
N iText PDF Fehler, java.lang.ClassNotFoundException: com.lowagie.text.Phrase Java Basics - Anfänger-Themen 7
M java.lang.NumberFormatException-Problem Java Basics - Anfänger-Themen 6
H java.lang.NoSuchMethodError: Java Basics - Anfänger-Themen 5
J java.lang.UnsatisfiedLinkError: Java Basics - Anfänger-Themen 9
T List in java.lang.Object... einfügen Java Basics - Anfänger-Themen 12
M java.lang.StringTokenizer Java Basics - Anfänger-Themen 4
I java.lang.String cannot be cast to OBJEKT Java Basics - Anfänger-Themen 8
P java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory Java Basics - Anfänger-Themen 1
Y java.lang.NoSuchMethodError: main Java Basics - Anfänger-Themen 9
B Exception in thread "main" java.lang.NullPointerException Fehler Hilfe! Java Basics - Anfänger-Themen 4
D java.lang.outofmemoryerror java heap space bei Hashtable Java Basics - Anfänger-Themen 3
Spin Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: data must Java Basics - Anfänger-Themen 10

Ähnliche Java Themen

Neue Themen


Oben