Jump to content

Recommended Posts

Posted

Hello there!

 

I tried loading JSON data to my mod using OkHttpClient. for some reason when the client loads it just crushes itself. I checked what is causing this and this line was the problematic one (99% certain).

public static OkHttpClient APIClient = new OkHttpClient();

 

Do you guys know why is this happening? and maybe how can I fix this? thanks!

Posted

What do you mean by "crush"? Is the client crashing? Is it freezing?

 

Post the code where you use the client. If it's crashing, post the crash report as well.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
10 minutes ago, Choonster said:

What do you mean by "crush"? Is the client crashing? Is it freezing?

 

Post the code where you use the client. If it's crashing, post the crash report as well.

 

By crashing I mean this, and the only like that is causing this is the line I sent up there, for sure.

 

report:

Caused by: java.lang.NoClassDefFoundError: okio/BufferedSource
    at okhttp3.internal.Util.<clinit>(Util.java:48)
    at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:122)
    at me.mods.testingForge.this.that.<clinit>(that.java:14)
    at me.mods.testingForge.mainClass.preInit(mainClass.java:14)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:211)
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:189)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556)
    ... 16 more
Caused by: java.lang.ClassNotFoundException: okio.BufferedSource
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 47 more
Caused by: java.lang.NullPointerException
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)
    ... 49 more

 

Screenshot_1.png

Posted
5 minutes ago, Bets said:

Caused by: java.lang.NoClassDefFoundError: okio/BufferedSource

 

OkHttp depends on Okio, which you don't have.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
2 hours ago, diesieben07 said:

May I suggest a more practical solution? Minecraft already depends on Apache's HttpClient, there is no need to ship your own library for it.

 
 

Yeah well I am not familiar with it very much so I'll use this one for now.

 

Oh and for some reason when I run the Client it's not loading the JSON for me, but when I run the class but it's own it does.

Do I need to somehow add the functions of the class to the mod? by

Quote

@EventManager

 

Maybe?

Posted (edited)
53 minutes ago, diesieben07 said:

I am not sure what you mean, please show your code.

 
 

Well inside a second class file I have I use a public static void function - for some reason, it just won't run when I run the Client. It does run only when I run the class file alone.

public static void main(String[] args) {
   System.out.println("Is this working?");
}

 

Edited by Bets
Posted
2 minutes ago, Bets said:

Well inside a second class file I have I use a public static void function - for some reason, it just won't run when I run the Client. It does run only when I run the class file alone.


public static void main(String[] args) {
   System.out.println("Is this working?");
}

 

Uh yeah. Because that's a Main function, as in the first method that the JVM invokes, except that the main class that the JVM is invoking is GradleStart, calling Main(args) there.  Which means YOUR method is not called.  Just because it's public and static doesn't mean it gets invoked.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 minutes ago, Draco18s said:

Uh yeah. Because that's a Main function, as in the first method that the JVM invokes, except that the main class that the JVM is invoking is GradleStart, calling Main(args) there.  Which means YOUR method is not called.  Just because it's public and static doesn't mean it gets invoked.

 

 

So I need to invoke it from the main class? if so how can I do that :P

Posted

How about you not make a Java Main method and use the Forge init events?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
3 minutes ago, Draco18s said:

How about you not make a Java Main method and use the Forge init events?

 

Well, I'm a little new to Forge so I'm not sure how exactly to do that! but I have an FMLPreInitializationEvent in my main class, is that it? it's registering an event_bus to the other class I have there.

Posted (edited)
34 minutes ago, diesieben07 said:

I suggest you read the documentation on Loading Stages and Events (or really anything that is applicable from the documentation page).

 
 

Yeah but the thing I need to do to the function I mentioned before is what? add something like @SubscribeEvent?

Edited by Bets
Posted
4 minutes ago, diesieben07 said:

Ehm... what?

 

How can I basically make the function work xD because I have one that has a @SubscribeEvent above it. and it works. So should I just do the same to this one or there's something else there?

Posted
Just now, diesieben07 said:

I don't know what you mean by "work" and I don't know what you want to achieve. I linked you the documentation about loading stages, that is how your mod "starts up".

 
 

By work I mean make the function run. because currently it's just sitting there and doing nothing.

 

I did make an other function that works in the same class, this is the working one:

@SubscribeEvent
public void onRenderText(RenderGameOverlayEvent.Text e) {
//RENDER SCREEN TEXT HERE
}

 

So how can I make the second one to work like this too? I changed the name of the function before from main to something else, but how can I get Forge to recognize it and run it.

Posted

You mean, register an event handler?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
11 hours ago, diesieben07 said:

When do you want it to run, is the question.

 

Probably everytime you join a specific server.

 

8 hours ago, Draco18s said:

You mean, register an event handler?

 

Will that make it run when you join a specific server like I said before? (or even work at all? I just need to check if it loads the JSON when you use the Client) O.o

Posted
1 minute ago, diesieben07 said:

Probably? Well, to detect when you join a server you can use ClientConnectedToServerEvent on the client or PlayerLoggedInEvent on the server. It depends on what you want to achieve which one to choose.

 

Oh! this makes sense lol, will definitely try that! :P

Posted (edited)

Note that all subclasses of FMLNetworkEvent (e.g. ClientConnectedToServerEvent) are fired on a Netty thread rather than the main client/server thread, so methods that handle them must not directly interact with normal Minecraft classes.

 

You need to use IThreadListener#addScheduledTask to run a task on the main thread where you can safely interact with normal Minecraft classes.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
3 hours ago, Choonster said:

Note that all subclasses of FMLNetworkEvent (e.g. ClientConnectedToServerEvent) are fired on a Netty thread rather than the main client/server thread, so methods that handle them must not directly interact with normal Minecraft classes.

 

You need to use IThreadListener#addScheduledTask to run a task on the main thread where you can safely interact with normal Minecraft classes.

 

So I basically need to create an  IThreadListener#addScheduledTask runnable (if I'm correct) and run the  ClientConnectedToServerEvent inside it?

Posted
12 minutes ago, Bets said:

So I basically need to create an  IThreadListener#addScheduledTask runnable (if I'm correct) and run the  ClientConnectedToServerEvent inside it?

 

I feel like you probably understood what I told you, but what you said doesn't make a lot of sense.

 

In your ClientConnectedToServerEvent handler, you need to call IThreadListener#addScheduledTask with an implementation of Runnable that actually performs the desired task. This can be a regular class, an anonymous class, a lambda or a method reference.

 

Forge's documentation explains how to get the IThreadListener for each side here.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
On 2/12/2017 at 7:50 PM, Choonster said:

 

I feel like you probably understood what I told you, but what you said doesn't make a lot of sense.

 

In your ClientConnectedToServerEvent handler, you need to call IThreadListener#addScheduledTask with an implementation of Runnable that actually performs the desired task. This can be a regular class, an anonymous class, a lambda or a method reference.

 

Forge's documentation explains how to get the IThreadListener for each side here.

 
 

Oh! so Minecraft.getMinecraft(); is called IThreadListener? lol I did not know that! I think i'll figure it out now thanks! :D 

Posted
2 minutes ago, Bets said:

Oh! so Minecraft.getMinecraft(); is called IThreadListener? lol I did not know that! I think i'll figure it out now thanks! :D 

 

The Minecraft class implements the IThreadListener interface, so you can use an instance of it as an IThreadListener.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
On 2/14/2017 at 4:30 PM, Choonster said:

 

The Minecraft class implements the IThreadListener interface, so you can use an instance of it as an IThreadListener.

 

I have a couple of functions that control the OkHttp one, one that is calling the server and the receiving ones - do all of them need to be in the runnable? I tried just inserting a simple System.out.printIn("123"); inside the runnable but it doesn't seem to do anything.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.