Project

General

Profile

« Previous | Next » 

Revision c020555e

Added by Leszek Koltunski almost 2 years ago

Do not crash when something's wrong with the JSON file - handle this gracefully, do not change the object then, and report this to Firebase.

View differences:

src/main/java/org/distorted/config/ConfigScreenPane.java
78 78

  
79 79
      mObjectOrdinal = objectOrdinal;
80 80
      JsonReader reader = JsonReader.getInstance();
81
      reader.parseJsonFileMetadata(stream);
81
      String name,author;
82
      int year, difficulty;
83

  
84
      try
85
        {
86
        reader.parseJsonFileMetadata(stream);
87
        name       = reader.getObjectName();
88
        author     = reader.getInventor();
89
        year       = reader.getYearOfInvention();
90
        difficulty = reader.getComplexity();
91
        }
92
      catch(Exception ex)
93
        {
94
        name = "?";
95
        author = "?";
96
        year = 0;
97
        difficulty = 0;
98
        }
82 99

  
83
      String name = reader.getObjectName();
84
      String author = reader.getInventor();
85
      int year = reader.getYearOfInvention();
86 100
      String both = year>0 ? author+" "+year : author;
87 101

  
88 102
      LinearLayout layout = act.findViewById(R.id.configLayout);
......
91 105
      view = layout.findViewById(R.id.configDetailsAuthor2);
92 106
      view.setText(both);
93 107

  
94
      int difficulty = reader.getComplexity();
95

  
96 108
      if( difficulty<0          ) difficulty=0;
97 109
      if( difficulty>NUM_IMAGES ) difficulty=NUM_IMAGES;
98 110

  

Also available in: Unified diff