Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden. Du solltest ein Upgrade durchführen oder ein alternativer Browser verwenden.
Ich gehe davon aus dass das Problem daran liegt, dass du "weapons" static gemacht hast, und nicht genau weißt, was static in dem Kontext bedeutet. Zeig doch mal die Version, die dir die Exception auslöst.
Weiterhin würde ich NIE UND NIEMALS einen absoluten Pfad benutzen und schon gar nicht von Root aus. Das funktioniert nur unter Windows. Du solltest immer relative Pfade benutzen. Beutze dafür die system properties userdir etc.
Das ist zwar deutlich mehr Tipparbeit abert dafür läuft es nachher auch auf jedem System
Ich brauche das static um es von anderen Klassen aufzurufen und selbst wenn ich es in public mache aendere , macht das keinen unterschied.
Hier mal der ganze Code:
Java:
import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
// um in eine textdatei zu schreiben
public class WeaponsDataBase
{
public static String name;
public static String quote;
public static int maxlife;
public static int armor;
public static int magc_armor;
public static int stamina;
public static int phys_attack;
public static int magc_attack;
public static int mana;
public static int spec_ability1;
public static int spec_ability2;
public static int quantity;
public static int slot;
public static int quality;
public static int itemsize = 1; // höchste id des letzten items
public static String path;
public static ArrayList alname = new ArrayList();
public static ArrayList alquote = new ArrayList();
public static ArrayList almaxlife = new ArrayList();
public static ArrayList alarmor = new ArrayList();
public static ArrayList almagc_armor = new ArrayList();
public static ArrayList alstamina = new ArrayList();
public static ArrayList alphys_attack = new ArrayList();
public static ArrayList almagc_attack = new ArrayList();
public static ArrayList almana = new ArrayList();
public static ArrayList alspec_abil1 = new ArrayList();
public static ArrayList alspec_abil2 = new ArrayList();
public static ArrayList alquantity = new ArrayList();
public static ArrayList alslot = new ArrayList();
public static ArrayList alquality = new ArrayList();
public static void itemName(String x)
{
path = x;
}
public static File weapons = new File("C:"+File.separator+"sys"+File.separator+"weapons"+File.separator+path+".txt"); // muss geändert werden bei installation
// public static File test_path_weapons = new File("C:/sys/weapons/"+path+".txt");
public static void loadItems()
{
if (weapons.exists())
{
try
{
Scanner sc = new Scanner(weapons);
for (int i = 0; i < itemsize ; i++) // speist die textdatei in arraylists
{
alname.add(sc.nextLine()); // Name
alquote.add(sc.nextLine()); // Beschreibung
almaxlife.add(sc.nextLine()); // Leben
alarmor.add(sc.nextLine()); // Rüstung
almagc_armor.add(sc.nextLine()); // Schutz vor Magie
alstamina.add(sc.nextLine()); // Stamina
alphys_attack.add(sc.nextLine()); // Physischer Schaden
almagc_attack.add(sc.nextLine());// Magischer Schaden
almana.add(sc.nextLine()); // Mana
alspec_abil1.add(sc.nextLine()); // Spezielle Fähigkeiten
alspec_abil2.add(sc.nextLine()); // ""
alquantity.add(sc.nextLine()); // Geld Wert
alslot.add(sc.nextLine()); // Stelle des Equips
alquality.add(sc.nextLine()); // 14 ( Qualitaet)
System.out.println("Erfolgreich geladen");
}
}
catch(FileNotFoundException e)
{
System.out.println("FileNotFoundException");
// nothing to do
}
}
else
{
System.out.println("File: " + path + " not found.");
}
}
public static void showItemStats(int x) // Id des Items ausgeben
{
if (alname.size() > 0)
{
System.out.println("[" + alname.get(x) + "]" );
System.out.println("[" + alquote.get(x) + "]" );
System.out.println("[" + almaxlife.get(x) + "]" );
System.out.println("[" + alarmor.get(x) + "]" );
System.out.println("[" + almagc_armor.get(x) + "]" );
System.out.println("[" + alstamina.get(x) + "]" );
System.out.println("[" + alphys_attack.get(x) + "]" );
System.out.println("[" + almagc_attack.get(x) + "]" );
System.out.println("[" + almana.get(x) + "]" );
System.out.println("[" + alspec_abil1.get(x) + "]" );
System.out.println("[" + alspec_abil2.get(x) + "]" );
System.out.println("[" + alquantity.get(x) + "]" );
System.out.println("[" + alslot.get(x) + "]" );
System.out.println("[" + alquality.get(x) + "]" );
}
else
{
System.out.println("Error beim auslesen der datei");
}
}
}
'static' Variablen-Deklarationen fließen (in ihrer Reihenfolge wie sie im Code kommen) in den statischen Konstruktor der Klasse ein.
'static' Methoden-Deklarationen sind Klassenmethoden, und werden erst ausgeführt, wenn das Programm dies (an anderer Stelle) dann macht.
Das kann verzwickt werden, wenn die 'static' Methode wiederum vom statischen Konstruktor aufgerufen wird... (was hier aber nicht vorliegt).
Also, wie schon gesagt: Nochmal im Buch nachlesen, was 'static' bedeutet, was ein statischer Konstruktor ist, was eine static-Methode ist, ...