Hashmap NullPointerException

Discussion in 'Plugin Development' started by gidonyou, May 7, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    gidonyou

    I have Problem with Saving and Loading the Hashmap..

    MainClass
    Code:java
    1. public final ScoreBoardManager sbm = new ScoreBoardManager(this); // <-- HashMap Class
    2.  
    3. public void onEnable() {
    4. sbm.start
    5. }
    6.  
    7. public void onDisable(){
    8. sbm.stop
    9. }
    10.  


    Hashmap Class
    Code:java
    1.  
    2. public void start() {
    3. load();
    4. addAll();
    5. }
    6.  
    7. public void stop(){
    8. save();
    9. }
    10.  
    11. @SuppressWarnings("unchecked")
    12. public void load() {
    13. File dir = plugin.getDataFolder();
    14. if (!dir.exists())
    15. if (!dir.mkdir())
    16. System.out.println("Chould not create directory for MineWar");
    17.  
    18. db = (java.util.HashMap<OfflinePlayer, Double>) so
    19. .load(new File(plugin.getDataFolder(), "point.dat"));
    20.  
    21. if (db == null){
    22. db = new java.util.HashMap<OfflinePlayer, Double>();
    23. }
    24. update();
    25. }
    26.  
    27. public void save() {
    28. so.save(db, new File(plugin.getDataFolder(), "point.dat"));
    29. }
    30. }


    SaveObject Class (soClass)

    Code:java
    1. public void save(Object o, File f) {
    2. try {
    3. if (!f.exists())
    4. f.createNewFile();
    5. oos.writeObject(o);
    6. oos.flush();
    7. oos.close();
    8. } catch (Exception e) {
    9. e.printStackTrace();
    10. }
    11. }
    12.  
    13. public Object load(File f) {
    14. try {
    15. Object result = ois.readObject();
    16. ois.close();
    17. return result;
    18. } catch (Exception e) {
    19. return null;
    20. }
    21. }
    22.  


    Is it fine with start/stoping and creating the file, but it give me exception if i try to edit(put/contains/etc)

    it give
    Code:java


    SavingObject code by TheBCBroz
     
  2. Offline

    Garris0n

    I can't tell what anything does because you only posted parts of the code.

    ಠ_ಠ
     
  3. Offline

    gidonyou

    Well.. I meant "based on"
    anyway.. I think I don't have to show every single line of the code..

    If I tell you another line, I think I have to write
    Code:java
    1. public java.util.HashMap<OfflinePlayer, Double> db;
     
  4. Offline

    Garris0n

    Use the players' UUIDs instead of offline players.
     
Thread Status:
Not open for further replies.

Share This Page