Gson cannot be resolved to a type error randomly started appearing

public static Partita carica(int id) {
Gson gson = new Gson();
return gson.fromJson(Utili.leggiFileJson("partite", Integer.toString(id)), Partita.class);
}
public static Partita carica(int id) {
Gson gson = new Gson();
return gson.fromJson(Utili.leggiFileJson("partite", Integer.toString(id)), Partita.class);
}
i have this method that loads a json file into a class, which i dont exactly know it started throwing an error at this line Gson gson = new Gson(); despite me not touching that function or the Util function. The wierd part is that if i rewrite that function in a runnable class like
public static void main(String[] args) {
Gson gson = new Gson();
Partita p = gson.fromJson(Utili.leggiFileJson("partite", Integer.toString(25066)), Partita.class);
}
public static void main(String[] args) {
Gson gson = new Gson();
Partita p = gson.fromJson(Utili.leggiFileJson("partite", Integer.toString(25066)), Partita.class);
}
it works. so i can say its not an issue with imports or my util function
4 Replies
JavaBot
JavaBot9mo ago
This post has been reserved for your question.
Hey @asdru! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
tjoener
tjoener9mo ago
What's the error?
asdru
asdruOP9mo ago
Caused by: java.lang.Error: Unresolved compilation problems:
Gson cannot be resolved to a type
Gson cannot be resolved to a type
Caused by: java.lang.Error: Unresolved compilation problems:
Gson cannot be resolved to a type
Gson cannot be resolved to a type
i solved it by writing this instead return new Gson().fromJson(Utili.leggiFileJson("partite", Integer.toString(id)), Partita.class); though its very yucky and have no idea why it works
JavaBot
JavaBot9mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server