I'm trying to make my first block in Eclipse, but the launcher crashes whenever I try to run it. I'm not sure what I'm doing wrong. I've created a new instance of the block, registered it, gave the constructor all the necessary fields, triple-checked the run methods, and I still haven't found the problem. I am running Minecraft 1.7.10.
Here are the classes:
Creates a BasicBlock object and registers it:
package com.mrcrayfish.tutorial.blocks;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
public final class ModBlocks {
public static Block tutorialBlock;
public static final void init() {
tutorialBlock = new BasicBlock("tutorialBlock", Material.wood);
GameRegistry.registerBlock(tutorialBlock, "tutorialBlock");
}
}
BasicBlock class:
package com.mrcrayfish.tutorial.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import com.mrcrayfish.tutorial.Reference;
public class BasicBlock extends Block {
public BasicBlock(String unlocalizedName, Material material) {
super(material);
this.setBlockName(unlocalizedName);
this.setBlockTextureName(Reference.MOD_ID + ":" + unlocalizedName);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setHardness(2.0F);
this.setResistance(6.0F);
this.setLightLevel(20.0F);
this.setHarvestLevel("shovel", 3);
this.setStepSound(soundTypeMetal);
}
}
Proxy with runtime methods:
package com.mrcrayfish.tutorial.proxy;
import cpw.mods.fml.common.event.*;
import com.mrcrayfish.tutorial.blocks.ModBlocks;
import com.mrcrayfish.tutorial.init.ModItems;
public class CommonProxy {
public void preInit(FMLPreInitializationEvent e) {
ModItems.init();
ModItems.register();
ModBlocks.init();
}
public void init(FMLInitializationEvent e) {
}
public void postInit(FMLPostInitializationEvent e) {
}
}
Main runtime class:
package com.mrcrayfish.tutorial;
import com.mrcrayfish.tutorial.init.ModItems;
import com.mrcrayfish.tutorial.proxy.CommonProxy;
import com.mrcrayfish.tutorial.blocks.ModBlocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.Mod.EventHandler;
#Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class Tutorial {
#Instance
public static Tutorial instance;
#SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;
#EventHandler
public void preInit(FMLPreInitializationEvent event) {
ModItems.init();
ModItems.register();
ModBlocks.init();
proxy.preInit(event);
}
#EventHandler
public void init(FMLInitializationEvent event) {
System.out.println("init");
proxy.init(event);
}
#EventHandler
public void postInit(FMLPostInitializationEvent event) {
System.out.println("postinit");
proxy.postInit(event);
}
}
Reference class with final variables/enums:
package com.mrcrayfish.tutorial;
import net.minecraft.block.material.Material;
public class Reference {
public static final String MOD_ID = "ctm";
public static final String NAME = "MrCrayfish's Tutorial Mod";
public static final String VERSION = "1.0";
public static final String CLIENT_PROXY_CLASS = "com.mrcrayfish.tutorial.proxy.ClientProxy";
public static final String SERVER_PROXY_CLASS = "com.mrcrayfish.tutorial.proxy.ServerProxy";
public enum TutorialItems {
CHEESE("cheese", "ItemCheese");
public String unlocalizedName;
public String registryName;
TutorialItems(String unlocalizedName, String registryName) {
this.unlocalizedName = unlocalizedName;
this.registryName = registryName;
}
public String getUnlocalizedName() {
return unlocalizedName;
}
public String getRegistryName() {
return registryName;
}
}
public enum EBlock {
TUTORIALBLOCK("tutorialBlock", Material.wood);
String BlockName;
Material material;
EBlock(String BlockName, Material material) {
this.BlockName = BlockName;
this.material = material;
}
}
}
ClientProxy class:
package com.mrcrayfish.tutorial.proxy;
import cpw.mods.fml.common.event.*;
public class ClientProxy extends CommonProxy
{
public void preInit(FMLPreInitializationEvent h)
{
super.preInit(h);
}
public void init(FMLInitializationEvent h)
{
super.init(h);
}
public void postInit(FMLPostInitializationEvent h)
{
super.postInit(h);
}
}
ServerProxy class:
package com.mrcrayfish.tutorial.proxy;
import cpw.mods.fml.common.event.*;
public class ServerProxy extends CommonProxy
{
public void preInit(FMLPreInitializationEvent h)
{
super.preInit(h);
}
public void init(FMLInitializationEvent h)
{
super.init(h);
}
public void postInit(FMLPostInitializationEvent h)
{
super.postInit(h);
}
}
The most I could get out of the debug report is that there is an issue with the "preInit" method in "Tutorial.java". Here's the crash report:
at cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry.add(FMLControlledNamespacedRegistry.java:410)
at cpw.mods.fml.common.registry.GameData.registerItem(GameData.java:849)
at cpw.mods.fml.common.registry.GameData.registerItem(GameData.java:812)
at cpw.mods.fml.common.registry.GameRegistry.registerItem(GameRegistry.java:149)
at cpw.mods.fml.common.registry.GameRegistry.registerItem(GameRegistry.java:137)
at com.mrcrayfish.tutorial.init.ModItems.register(ModItems.java:23)
at com.mrcrayfish.tutorial.proxy.CommonProxy.preInit(CommonProxy.java:10)
at com.mrcrayfish.tutorial.proxy.ClientProxy.preInit(ClientProxy.java:8)
at com.mrcrayfish.tutorial.Tutorial.preInit(Tutorial.java:26)
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 cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
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 cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
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 cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:556)
at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:243)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:522)
at net.minecraft.client.Minecraft.run(Minecraft.java:942)
at net.minecraft.client.main.Main.main(Main.java:164)
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.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)
After looking through eclipse's console output, I think I can narrow down the issue:
[09:12:27] [Client thread/INFO] [MinecraftForge]: Attempting early MinecraftForge initialization
[09:12:27] [Client thread/INFO] [FML]: MinecraftForge v10.13.4.1558 Initialized
[09:12:27] [Client thread/INFO] [FML]: Replaced 183 ore recipies
[09:12:27] [Client thread/INFO] [MinecraftForge]: Completed early MinecraftForge initialization
[09:12:28] [Client thread/INFO] [FML]: Found 0 mods from the command line. Injecting into mod discoverer
[09:12:28] [Client thread/INFO] [FML]: Searching C:\Users\Chris\Desktop\Forge\eclipse\mods for mods
[09:12:44] [Client thread/INFO] [FML]: Forge Mod Loader has identified 4 mods to load
[09:12:45] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, ctm] at CLIENT
[09:12:45] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, ctm] at SERVER
Seems to be an issue with the proxy classes I created.
When the preInit Event occures you run the following lines
ModItems.init();
ModItems.register();
ModBlocks.init();
and then you run your Proxies preInit Methode
since bothe the ClientProxy and ServerProxy just call super.preInit
both call CommonProxy's preInit Methode which also does
ModItems.init();
ModItems.register();
ModBlocks.init();
this means you are trying to register everything twich wich probably causes the error.
Related
I'm trying to use a simple socket server to receive some commands(bukkit api).
With the thread, the plugin can receive commands and send it to the main server, so that i can control the server.
But when i tried to use a use a thread to solve the problem, an error happened:
CODE:
package tiance.auroracore;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import tiance.auroracore.metrics.Metrics;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public final class AuroraCore extends JavaPlugin {
private int port;// 默认服务器端口
private String AcceptCommand;
public AuroraCore() {
this.port=9028;
this.AcceptCommand=new String();
}
// 创建指定端口的服务器
public AuroraCore(int port) {//构造方法
this.port = port;//将方法参数赋值给类参数
this.AcceptCommand=new String();
}
// 提供服务
public void service() {//创建service方法
ServerSocket server;
try {
server = new ServerSocket(port);//创建 ServerSocket类
}
catch (IOException e) {
System.out.println("Error! Cannot start the server! Is the port already used?");
return;
}
while (true) {
try {// 建立服务器连接
Socket socket = server.accept();// 等待客户连接
try {
DataInputStream in = new DataInputStream(socket
.getInputStream());// 读取客户端传过来信息的DataInputStream
DataOutputStream out = new DataOutputStream(socket
.getOutputStream());// 向客户端发送信息的DataOutputStream
while (true) {
String accept = in.readUTF();// 读取来自客户端的信息
AcceptCommand = accept;
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), AcceptCommand);
}
} finally {// 建立连接失败的话不会执行socket.close();
socket.close();//关闭连接
server.close();//关闭
}
} catch (IOException e) {//捕获异常
e.printStackTrace();
}
}
}
#Override
public void onEnable() {
new BukkitRunnable(){
public void run(){
new AuroraCore().service();//调用service方法
}
}.runTaskAsynchronously(this);
int pluginId = 13929;
Metrics metrics = new Metrics(this, pluginId);
saveDefaultConfig();
}
#Override
public void onDisable() {
}
}
ERROR
[12:45:28 WARN]: [AuroraCore] Plugin AuroraCore v1.0.0 generated an exception while executing task 2
java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:218) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at tiance.auroracore.AuroraCore.<init>(AuroraCore.java:19) ~[?:?]
at tiance.auroracore.AuroraCore$1.run(AuroraCore.java:69) ~[?:?]
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftTask.run(CraftTask.java:76) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:54) [craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_281]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_281]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_281]
Caused by: java.lang.IllegalStateException: Initial initialization
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:221) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at tiance.auroracore.AuroraCore.<init>(AuroraCore.java:19) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_281]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_281]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_281]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_281]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_281]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:79) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:143) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:393) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:301) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.loadPlugins(CraftServer.java:379) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:218) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:905) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0(MinecraftServer.java:263) ~[craftbukkit-1.16.5.jar:3096a-Bukkit-af1a232]
... 1 more
I've edited the code again and again,but didn't found any solution. I've also seen some questions on the website, but none of them could solve my problem.I didn't found any repeat main class .I really don't know what to do! If someone can help, i will be very glad and thankful to him or her.
Replace new AuroraCore() with AuroraCore.this.
You have to replace new AuroraCore() with AuroraCore.this to initialize service() void
#Override
public void onEnable() {
new BukkitRunnable(){
public void run(){
AuroraCore.this.service();//调用service方法
}
}.runTaskAsynchronously(this);
int pluginId = 13929;
Metrics metrics = new Metrics(this, pluginId);
saveDefaultConfig();
}
I just wrote this code here:
package SpellcheckerClient;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
BorderPane root = FXMLLoader.load(getClass().getResource("/controller/gui.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Spellchecker Client");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
And this is the corresponding controller.
package controller;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import spellchecker.remote.SpellcheckerRemoteAdapter;
public class Controller {
#FXML
TextField input;
#FXML
Button send;
#FXML
TextArea area;
#FXML
Button connect;
private SpellcheckerRemoteAdapter adapter;
#FXML
private void send() throws RemoteException{
String toCheck = input.getText();
this.area.appendText(toCheck + "\n");
this.area.appendText(checkRoutine(toCheck, this.adapter) + "\n\n");
this.input.clear();
}
public void initiateConnection() {
try {
Registry registry = LocateRegistry.getRegistry(1088);
this.adapter = (SpellcheckerRemoteAdapter) registry.lookup(SpellcheckerRemoteAdapter.NAME);
this.area.appendText("Verbindung erfolgreich aufgebaut!\n");
connect.setDisable(true);
} catch (Exception e) {
if(this.adapter == null) {
this.area.appendText("Server nicht gefunden!\n");
}
}
}
private static String checkRoutine(String input, SpellcheckerRemoteAdapter adapter) throws RemoteException {
if (input == null || input.isEmpty()) {
return "Bitte etwas eingeben!";
}
String[] words = input.split(" ");
boolean control = true;
String output = "";
for(String word : words) {
if(!adapter.check(word)) {
control = false;
output += word + ":\t" + adapter.getProposal(word) + "\n";
}
}
if(control) {
return "Alles Okay!\n";
}
return output;
}
}
If I run this code on my Laptop, where I wrote it, it runs perfectly fine in Eclipse and as runnable Jar. However, if I try to run the JAR on another computer i receive this error message:
Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
at javafx.graphics/com.sun.glass.ui.Screen.initScreens(Unknown Source)
at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
at javafx.graphics/com.sun.glass.ui.Screen.initScreens(Unknown Source)
at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.graphics/com.sun.prism.d3d.D3DPipeline.getAdapterOrdinal(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.assignScreensAdapters(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runToolkit(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$startup$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
On my Laptop and my Computer are the same Versions of the JDK/JRE installed.
I don't really get what the error message is telling me.
Hello I have the same issue on my Eclipse environnement (Windows 10 OS),
adding in VM option -Djava.library.path="C:\WINDOWS\Sun\Java\bin" solved my problem
That means that javafx-graphics-[version]-win.jar call some native dll. And You have to found were those dll is stored.
I found the path, thanks to jvisualvm and showing the VM option for the case where it's the application run correctly.
Hoping that it will solve your problem.
Which JDk you have installed?? I have the same issue and i use JDK 8 instead of JDK 9. Which helped me.Sample Image of Exception
This is because jar which i created it was created on JDK 8 through a different system.
Where as when it was executing on another system which has JDK9. So it is version incompatible.
After keeping single JDK 8 and mapped it to system environment when i try to run my jar it worked for me.
Good Luck :)
I am new in java development and try to learn Retrofit api i am getting exception can any one help me ? i have paste my code and output exception below kindly take a look of it
Thank you ,
package com.company;
import com.sun.deploy.util.SessionState;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Client;
import retrofit.client.Request;
import retrofit.client.Response;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
// write your code here
RetrofitInterface retrofitInterface = (RetrofitInterface)new RestAdapter.Builder().setEndpoint("http://localhost:8080/new_pro").build().create(RetrofitInterface.class);
retrofitInterface.getUser(222, new Callback<String>() {
#Override
public void success(String s, Response response) {
//System.out.print(s);
}
#Override
public void failure(RetrofitError retrofitError) {
}
});
}
}
Output
Exception in thread "main" java.lang.IllegalArgumentException: RetrofitInterface.getUser: Must have return type or Callback as last argument, not both.
at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:107)
at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:267)
at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
at com.sun.proxy.$Proxy0.getUser(Unknown Source)
at com.company.Main.main(Main.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Previous Interface i was using
public interface RetrofitInterface {
// asynchronously with a callback
#GET("/")
Header getUser(#Query("user_id") int userId, Callback<Header> callback);
}
Modified Interface i am using and its working.
public interface RetrofitInterface {
// asynchronously with a callback
#GET("/")
void getUser(#Query("user_id") int userId, Callback<Header> callback);
}
I'm having a NullPointerException when trying to load the plugin in my bukkit server, but no errors in Eclipse. My plugin is a Rush pluing and alot of things are not used/missing.
The Error is this:
[18:11:10] [Server thread/ERROR]: Could not load 'plugins\rush.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:182) ~ [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:308) ~ [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:231) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:255) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:233) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
Caused by: java.lang.NullPointerException
at me.mailh.Rush.MainRush.<init>(MainRush.java:62) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_45]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_45]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~ [?:1.7.0_45]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_45]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:178) ~ [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
... 9 more
Here is my code:
package me.mailh.Rush;
import java.io.File;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team;
public class MainRush extends JavaPlugin implements Listener{
public final Logger logger = Logger.getLogger("Minecraft");
public static MainRush plugin;
public void onEnable(){
this.logger.info("Rush is enabled.");
getServer().getPluginManager().registerEvents(this, this);
}
private ScoreboardManager manager = Bukkit.getScoreboardManager();
private Scoreboard board = manager.getNewScoreboard();
private Team bleu = board.registerNewTeam("bleu");
private Team orange = board.registerNewTeam("orange");
public void onDisable(){
this.logger.info("Rush is disabled.");
}
public boolean onCommand(CommandSender s, Command c, String lbl, String[] args){
Player pl = (Player) s;
if (lbl.equalsIgnoreCase("rush")){
if (args.length == 0){
World w = Bukkit.getWorld("rush");
Location rush = new Location( w, -210, 51, -8 );
pl.sendMessage(ChatColor.GOLD + "Teleportation...");
pl.teleport(rush);
}
if (args[0].equalsIgnoreCase("bleu")){
board.resetScores(pl.getPlayer());
orange.removePlayer(pl.getPlayer());
bleu.addPlayer(pl.getPlayer());
pl.sendMessage(ChatColor.AQUA + "Vous êtes dans l'équipe bleu");
bleu.setAllowFriendlyFire(false);
}
if (args[0].equalsIgnoreCase("leave")){
board.resetScores(pl.getPlayer());
bleu.removePlayer(pl.getPlayer());
orange.removePlayer(pl.getPlayer());
pl.sendMessage(ChatColor.RED + "Vous avez quitté votre équipe");
}
if (args[0].equalsIgnoreCase("orange")){
board.resetScores(pl.getPlayer());
bleu.removePlayer(pl.getPlayer());
orange.addPlayer(pl.getPlayer());
pl.sendMessage(ChatColor.GOLD + "Vous êtes dans l'équipe orange");
orange.setAllowFriendlyFire(false);
}
}
return true;
}
public void rollback(){
if(Bukkit.getServer().unloadWorld("rush",false))
{
new File("rush").delete();
Bukkit.getServer().createWorld(new WorldCreator("rush"));
}
}
#EventHandler
public void onLeave(PlayerQuitEvent e){
Player p = (Player) e.getPlayer();
bleu.removePlayer(p);
orange.removePlayer(p);
board.resetScores(p);
}
#EventHandler
public void Death(PlayerDeathEvent event){
if (event.getEntityType() == EntityType.PLAYER){
Player player = event.getEntity();
Team team = board.getPlayerTeam(player);
if(team.equals(bleu)){
player.sendMessage("did it work? bleu");
}
else if (team.equals(orange)){
player.sendMessage("did it work orange?");
}
}
}
}
It seems to this code:
private ScoreboardManager manager = Bukkit.getScoreboardManager();
private Scoreboard board = manager.getNewScoreboard();
The reason is that you're not declaring these variables inside of a method, so, they get loaded before your onEnable() method is called, making it so that you can't get anything using Bukkit as it Bukkit has not yet been initialized.
What I recommend doing is doing something like this outside of any methods:
private ScoreboardManager manager;
private Scoreboard board;
then doing this in your onEnable():
manager = Bukkit.getScoreboardManager();
board = manager.getNewScoreboard();
So you would have something like this:
public class MainRush extends JavaPlugin implements Listener{
private ScoreboardManager manager;
private Scoreboard board;
#Override
public void onEnable(){
//plugin enabled
manager = Bukkit.getScoreboardManager();
board = manager.getNewScoreboard();
}
}
By doing this, you're eliminating the chance of getting a NullPointerException when your plugin is loaded. As a general rule of thumb, you should never get anything from bukkit outside of methods.
i am trying to start apache camel for integration purpose
can you tell what i need to do for camel configuration run this class
Error for running class
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.camel.support.ServiceSupport.<clinit>(ServiceSupport.java:39)
at MainExample.boot(MainExample.java:21)
at MainExample.main(MainExample.java:16)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
And we use camel-core-2.11.0.jar
Here is my calss
MainExample.java
import java.util.Date;
import javax.annotation.processing.Processor;
import org.apache.camel.Exchange;
import org.apache.camel.Main;
import org.apache.camel.builder.RouteBuilder;
#SuppressWarnings("deprecation")
public class MainExample {
private Main main;
public static void main(String[] args) throws Exception {
MainExample example = new MainExample();
example.boot();
}
public void boot() throws Exception {
// create a Main instance
main = new Main();
// enable hangup support so you can press ctrl + c to terminate the JVM
main.enableHangupSupport();
// bind MyBean into the registery
main.bind("foo", new MyBean());
// add routes
main.addRouteBuilder(new MyRouteBuilder());
// run until you terminate the JVM
System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n");
main.run();
}
private static class MyRouteBuilder extends RouteBuilder {
#Override
public void configure() throws Exception {
from("timer:foo?delay=2000")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("Invoked timer at " + new Date());
}
})
.beanRef("foo");
}
}
public static class MyBean {
public void callMe() {
System.out.println("MyBean.calleMe method has been called");
}
}
}
Just add SLF4J libraries to your CLASSPATH. Normally your need SLF4J API (slf4j-api-version.jar) and one implementation e.g. slf4j-log4j-version.jar