java lang nullpointerexception ticking memory connection

net.minecraft.server.MinecraftServer Encountered an unexpected exception
h: Ticking memory connection
at tb.c(SourceFile:188)
at net.minecraft.server.MinecraftServer.w(SourceFile:720)
at net.minecraft.server.MinecraftServer.v(SourceFile:627)
Показать полностью…
at czd.v(SourceFile:155)
at net.minecraft.server.MinecraftServer.run(SourceFile:532)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Not a JSON Object: null
at com.google.gson.JsonElement.getAsJsonObject(JsonElement.java:90)
at vo.a(SourceFile:81)
at vo. (SourceFile:47)
at up.a(SourceFile:917)
at sg. (SourceFile:176)
at up.g(SourceFile:441)
at te.b(SourceFile:119)
at te.ab_(SourceFile:66)
at hn.a(SourceFile:221)
at tb.c(SourceFile:175)
. 5 more
18:14:04 net.minecraft.server.MinecraftServer This crash report has been saved to: C:UsersFORMUSAppDataRoaming.minecraftcrash-reportscrash-2018-03-19_19.14.04-server.txt
18:14:04 net.minecraft.server.MinecraftServer Stopping server
18:14:04 net.minecraft.server.MinecraftServer Saving players
18:14:04 net.minecraft.server.MinecraftServer Saving worlds
18:14:04 net.minecraft.server.MinecraftServer Saving chunks for level ‘Побiда’/overworld
21:14:04 game —— Minecraft Crash Report ——
// Ooh. Shiny.

Time: 19.03.18 19:14
Description: Ticking memory connection

java.lang.IllegalStateException: Not a JSON Object: null
at com.google.gson.JsonElement.getAsJsonObject(JsonElement.java:90)
at vo.a(SourceFile:81)
at vo. (SourceFile:47)
at up.a(SourceFile:917)
at sg. (SourceFile:176)
at up.g(SourceFile:441)
at te.b(SourceFile:119)
at te.ab_(SourceFile:66)
at hn.a(SourceFile:221)
at tb.c(SourceFile:175)
at net.minecraft.server.MinecraftServer.w(SourceFile:720)
at net.minecraft.server.MinecraftServer.v(SourceFile:627)
at czd.v(SourceFile:155)
at net.minecraft.server.MinecraftServer.run(SourceFile:532)
at java.lang.Thread.run(Thread.java:745)

A detailed walkthrough of the error, its code path and all known details is as follows:
————————————————————————————-—

При попытке запуска Minecraft часто появляется ошибка «The game crashed whilst initializing game». После показа окна с уведомлением игра выключается. Причинами краша могут послужить: ошибочно сформированная конфигурация, недостаток ОЗУ, устаревшая Java, неподходящие моды и т. п.

Способы решения ошибки

Сегодня известно 4 основных способа устранения сбоя:

  1. Неправильный файл конфигурации. Следует перейти в папку с exe-файлом и изменить название папки config. Теперь нужно запустить игру Minecraft повторно. Алгоритм проверит наличие папки config, так как её нет, система создаст папку со стандартными конфигурационными настройками. Если переименование не помогает устранить ошибку, следует вернуть название изменённой папки;
  2. Устаревшая версия Java – это важная платформа для работы игры. Рекомендуется устанавливать последнюю версию пакета, который доступен по ссылке ;
  3. Неподходящие или сбойные моды, шейдеры и т. п. Стоит вернуть изначальные текстуры и убрать добавленные моды. В будущем перед установкой модов следует проверять, что они подходят для текущей версии игры;
  4. Расширить размер выделенной оперативной памяти. Java-платформа требует достаточный объём памяти.

Один из способов должен решить ошибку. Если этого не случилось, стоит переустановить игру.

So I started writing tests for our Java-Spring-project.

What I use is JUnit and Mockito. It’s said, that when I use the when(). thenReturn() option I can mock services, without simulating them or so. So what I want to do is, to set:

But no matter which when-clause I do, I always get a NullpointerException, which of course makes sense, because input is null.

Also when I try to mock another method from an object:

There I also get a Nullpointer, because the method needs a variable, which isn’t set.

But I want to use when()..thenReturn() to get around creating this variable and so on. I just want to make sure, that if any class calls this method, then no matter what, just return true or the list above.

Is it a basically misunderstanding from my side, or is there something else wrong?

Code:

And here is my test class:

13 Answers 13

The default return value of methods you haven’t stubbed yet is false for boolean methods, an empty collection or map for methods returning collections or maps and null otherwise.

This also applies to method calls within when(. ) . In you’re example when(myService.getListWithData(inputData).get()) will cause a NullPointerException because myService.getListWithData(inputData) is null — it has not been stubbed before.

One option is create mocks for all intermediate return values and stub them before use. For example:

Or alternatively, you can specify a different default answer when creating a mock, to make methods return a new mock instead of null: RETURNS_DEEP_STUBS

You should read the Javadoc of Mockito.RETURNS_DEEP_STUBS which explains this in more detail and also has some warnings about its usage.

I hope this helps. Just note that your example code seems to have more issues, such as missing assert or verify statements and calling setters on mocks (which does not have any effect).

Оцените статью