Eclipse debugging for null pointer exception - java

I am getting a NullPointerException as shown below.
However, the debugger is not able to bring it up when enabled in this method, the code is getting invoked with reflections. Can you please provide me ideas\techniques to be able to debug this code?
[10/18/16 18:20:47:933 EST] 00000051 DWLExceptionU E java.lang.NullPointerException
at com.dwl.base.notification.NotificationManager$NotificationChannel.notify(NotificationManager.java:662)
at com.dwl.base.notification.NotificationManager$NotificationType.notify(NotificationManager.java:402)
at com.dwl.base.notification.NotificationManager.notify(NotificationManager.java:1454)
at com.dwl.base.notification.bean.impl.NotificationBean.notify(NotificationBean.java:142)
at com.dwl.base.notification.EJSLocalCSLNotification_e2801c59.notify(EJSLocalCSLNotification_e2801c59.java)
at com.dwl.base.notification.EJSProxy$$NotificationLocal.notify(Unknown Source)
at au.com.xxxxx.mdm.notification.NotificationHelper.sendNotification(NotificationHelper.java:75)
at au.com.xxxxxx.mdm.behaviour.SingleCustomerViewId.triggerNotification(SingleCustomerViewId.java:159)
at au.com.xxxxxxx.mdm.behaviour.SingleCustomerViewId.execute(SingleCustomerViewId.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at com.dwl.base.extensionFramework.JavaExtensionSet.invoke(JavaExtensionSet.java:159)
at com.dwl.base.extensionFramework.ExtensionHandler.executeExtension(ExtensionHandler.java:251)
at com.dwl.base.DWLCommonComponent.handleExtensions(DWLCommonComponent.java:1380)
at com.dwl.base.DWLCommonComponent.postExecute(DWLCommonComponent.java:509)
at com.dwl.tcrm.common.TCRMCommonComponent.postExecute(TCRMCommonComponent.java:263)
at com.dwl.tcrm.coreParty.component.TCRMPersonComponent.addPerson(TCRMPersonComponent.java:1641)
at com.dwl.tcrm.coreParty.component.TCRMPartyComponent.addPerson(TCRMPartyComponent.java:3079)
at com.dwl.tcrm.coreParty.component.TCRMPartyComponent.addPartySimple(TCRMPartyComponent.java:2813)
at com.dwl.tcrm.coreParty.component.TCRMPartyComponent.addParty(TCRMPartyComponent.java:2471)
at com.dwl.tcrm.coreParty.controller.TCRMCorePartyTxnBean.addPerson(TCRMCorePartyTxnBean.java:1764)
at Proxy5aa32899_c04f_46c5_9706_69af241cd3c4.addPerson(Unknown Source)
at Proxy5aa32899_c04f_46c5_9706_69af241cd3c4.addPerson(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at com.dwl.base.requestHandler.DWLTxnBP.processPersistentObject(DWLTxnBP.java:262)
at com.dwl.base.requestHandler.DWLTxnBP.execute(DWLTxnBP.java:115)
at com.dwl.base.requestHandler.DWLTxnProcessor.processTx(DWLTxnProcessor.java:98)
at com.dwl.unifi.tx.manager.CTxRxFacade.processTxNormal(CTxRxFacade.java:681)
at com.dwl.unifi.tx.manager.CTxRxFacade.processTx(CTxRxFacade.java:544)
at com.dwl.base.requestHandler.DWLRequestHandler.processTransaction(DWLRequestHandler.java:1187)
at com.dwl.base.requestHandler.DWLRequestHandler.processTx(DWLRequestHandler.java:591)
at com.dwl.base.requestHandler.DWLServiceControllerBase.processRequest(DWLServiceControllerBase.java:253)
at com.dwl.base.requestHandler.beans.EJSRemoteCSLDWLServiceController_2c54996d.processRequest(EJSRemoteCSLDWLServiceController_2c54996d.java)
at com.dwl.base.requestHandler.beans._EJSRemoteCSLDWLServiceController_2c54996d_Tie.processRequest(_EJSRemoteCSLDWLServiceController_2c54996d_Tie.java:1)
at com.dwl.base.requestHandler.beans._EJSRemoteCSLDWLServiceController_2c54996d_Tie._invoke(_EJSRemoteCSLDWLServiceController_2c54996d_Tie.java)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:669)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:523)
at com.ibm.rmi.iiop.ORB.process(ORB.java:523)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1575)
at com.ibm.rmi.iiop.Connection.doRequestWork(Connection.java:3039)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2922)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:64)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)

Can you please provide me ideas\techniques to be able to debug this code?
Since you said the method is called from reflection, you can see that in the stacktrace.
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
So, keep reading up from that.
I'm guessing you intentionally edited the xxxx values, so these are your libraries that are being dynamically called.
at au.com.xxxxx.mdm.notification.NotificationHelper.sendNotification(NotificationHelper.java:75)
at au.com.xxxxxx.mdm.behaviour.SingleCustomerViewId.triggerNotification(SingleCustomerViewId.java:159)
at au.com.xxxxxxx.mdm.behaviour.SingleCustomerViewId.execute(SingleCustomerViewId.java:129)
Then, the rest of the call stack just goes through some other code library within the same package.
at com.dwl.base.notification.NotificationManager$NotificationChannel.notify(NotificationManager.java:662)
at com.dwl.base.notification.NotificationManager$NotificationType.notify(NotificationManager.java:402)
at com.dwl.base.notification.NotificationManager.notify(NotificationManager.java:1454)
at com.dwl.base.notification.bean.impl.NotificationBean.notify(NotificationBean.java:142)
at com.dwl.base.notification.EJSLocalCSLNotification_e2801c59.notify(EJSLocalCSLNotification_e2801c59.java)
at com.dwl.base.notification.EJSProxy$$NotificationLocal.notify(Unknown Source)
So, the problem definitely starts at NotificationHelper.sendNotification(NotificationHelper.java:75), but it cannot easily be determined the path that the code took in order to reach its eventual destination or what exactly caused the exception without inspecting the source of (NotificationManager.java:662)

Related

How to resolve "Caused by: org.hibernate.HibernateException: Unable to access lob stream"

I have recently Upgraded my application.
Upgradation details:
- Java 6 to Java 8
- Hibernate 3 to Hibernate 3.6.10
- Spring 2.5 to Spring 4
- JBoss EAP 6 to JBoss EAP 7
I am trying to save some values which include some text values and files(Clob). The data is getting saved but I am getting an exception on the next hibernate operation.
Caused by: org.hibernate.HibernateException: Unable to access lob stream
at org.hibernate.type.descriptor.java.ClobTypeDescriptor.unwrap(ClobTypeDescriptor.java:117)
at org.hibernate.type.descriptor.java.ClobTypeDescriptor.unwrap(ClobTypeDescriptor.java:46)
at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$3$1.doBind(ClobTypeDescriptor.java:83)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2559)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2495)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2822)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at com.honeywell.cdd.dao.RptGrpDAOImpl.removeUnConfigGrpMTDT(RptGrpDAOImpl.java:2373)
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 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:112)
... 68 more
Caused by: java.sql.SQLException: could not reset reader
at org.hibernate.engine.jdbc.ClobProxy.resetIfNeeded(ClobProxy.java:178)
at org.hibernate.engine.jdbc.ClobProxy.getCharacterStream(ClobProxy.java:89)
at org.hibernate.engine.jdbc.ClobProxy.invoke(ClobProxy.java:121)
at com.sun.proxy.$Proxy133.getCharacterStream(Unknown Source)
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 org.hibernate.engine.jdbc.SerializableClobProxy.invoke(SerializableClobProxy.java:74)
at com.sun.proxy.$Proxy132.getCharacterStream(Unknown Source)
at org.hibernate.type.descriptor.java.ClobTypeDescriptor.unwrap(ClobTypeDescriptor.java:114)
... 98 more
I am not able to find out exact cause of this exception.
> The Same Code is working fine in the older configuration
"The Same Code is working fine in the older configuration"
is not really relevant ... unless you want to submit a but report to someone.
Lets look at what the nested exception:
Caused by: java.sql.SQLException: could not reset reader
The stacktrace indicates that something is calling getCharacterStream() on a Clob proxy and that is failing when the proxy attempts to reset the proxy's reader. The failure is (presumably) occurring because the JDBC object wrapped by the proxy doesn't allow a reader to be reset.
So why is this happening?
Again ... presumably ... something in your application has tried to call getCharacterStream() twice on a Clob proxy.
My guess is that you are (implicitly) using Clob objects as if they were in-memory files ... to avoid reading them when you don't need to. Except that sometimes you need to, and this is interfering with the persisting.

Minecraft Java Plugin - Trouble with resetting and setting scoreboard

I made a plugin and throughout development I have had some troubles with scoreboard. This time I really hit a wall whereas I don't know how I'm going to solve this on my own. I need some help.
I can steer you in the right direction though. After looking at the Error message and changing my code a little I figured out that the problem lies in the way that I reset score (in method SetScoreBoard() Line 726).
My code: https://pastebin.com/M5kFr2Lr (Read the pastebin)
public void SetScoreBoard(Player p) {
scoreboard = boardMap.get(p.getUniqueId());
scoreboard.resetScores(score15.get(p.getUniqueId()));
scoreboard.resetScores(score14.get(p.getUniqueId()));
scoreboard.resetScores(score13.get(p.getUniqueId()));
scoreboard.resetScores(score12.get(p.getUniqueId()));
scoreboard.resetScores(score11.get(p.getUniqueId()));
scoreboard.resetScores(score10.get(p.getUniqueId()));
scoreboard.resetScores(score9.get(p.getUniqueId()));
scoreboard.resetScores(score8.get(p.getUniqueId()));
scoreboard.resetScores(score7.get(p.getUniqueId()));
scoreboard.resetScores(score6.get(p.getUniqueId()));
scoreboard.resetScores(score5.get(p.getUniqueId()));
scoreboard.resetScores(score4.get(p.getUniqueId()));
scoreboard.resetScores(score3.get(p.getUniqueId()));
scoreboard.resetScores(score2.get(p.getUniqueId()));
scoreboard.resetScores(score1.get(p.getUniqueId()));
boardMap.put(p.getUniqueId(), scoreboard);
updateScoreBoard(p);
}
The error:
Caused by: java.lang.NullPointerException
at pillars.EssemCSH.main.Main.SetScoreBoard(Main.java:729) ~[?:?]
at pillars.EssemCSH.main.Main.onPlayerLeave(Main.java:1046) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_161]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
... 12 more

Textures not appearing in minecraft mod

I am trying to mod minecraft 1.11.2 in eclipse and I put all the texure files in the right place but they just won't load. I tried rewriting some of the java to see if I had made a mistake but nothing changed.
This is my error code:
[11:22:57] [Client thread/INFO]: Created: 16x16 textures-atlas
[11:23:00] [Client thread/ERROR] [FML]: Exception loading model for variant wowkcraft:itemobsidianingot#inventory for item "wowkcraft:itemobsidianingot", normal location exception:
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model wowkcraft:item/itemobsidianingot with loader VanillaLoader.INSTANCE, skipping
at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:153) ~[ModelLoaderRegistry.class:?]
at net.minecraftforge.client.model.ModelLoader.loadItemModels(ModelLoader.java:323) ~[ModelLoader.class:?]
at net.minecraft.client.renderer.block.model.ModelBakery.loadVariantItemModels(ModelBakery.java:175) ~[ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:153) ~[ModelLoader.class:?]
at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:122) [SimpleReloadableResourceManager.class:?]
at net.minecraft.client.Minecraft.init(Minecraft.java:541) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:387) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: java.io.FileNotFoundException: wowkcraft:models/item/itemobsidianingot.json
at net.minecraft.client.resources.FallbackResourceManager.getResource(FallbackResourceManager.java:69) ~[FallbackResourceManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:65) ~[SimpleReloadableResourceManager.class:?]
at net.minecraft.client.renderer.block.model.ModelBakery.loadModel(ModelBakery.java:334) ~[ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.access$1600(ModelLoader.java:124) ~[ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader$VanillaLoader.loadModel(ModelLoader.java:923) ~[ModelLoader$VanillaLoader.class:?]
at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:149) ~[ModelLoaderRegistry.class:?]
... 20 more
[11:23:00] [Client thread/ERROR] [FML]: Exception loading model for variant wowkcraft:itemobsidianingot#inventory for item "wowkcraft:itemobsidianingot", blockstate location exception:
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model wowkcraft:itemobsidianingot#inventory with loader VariantLoader.INSTANCE, skipping
at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:153) ~[ModelLoaderRegistry.class:?]
at net.minecraftforge.client.model.ModelLoader.loadItemModels(ModelLoader.java:331) ~[ModelLoader.class:?]
at net.minecraft.client.renderer.block.model.ModelBakery.loadVariantItemModels(ModelBakery.java:175) ~[ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:153) ~[ModelLoader.class:?]
at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:122) [SimpleReloadableResourceManager.class:?]
at net.minecraft.client.Minecraft.init(Minecraft.java:541) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:387) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: net.minecraft.client.renderer.block.model.ModelBlockDefinition$MissingVariantException
at net.minecraft.client.renderer.block.model.ModelBlockDefinition.getVariant(ModelBlockDefinition.java:78) ~[ModelBlockDefinition.class:?]
at net.minecraftforge.client.model.ModelLoader$VariantLoader.loadModel(ModelLoader.java:1239) ~[ModelLoader$VariantLoader.class:?]
at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:149) ~[ModelLoaderRegistry.class:?]
... 20 more
Caused by: java.io.FileNotFoundException: wowkcraft:models/item/itemobsidianingot.json
You're missing an Item Model json. The error is buried a little deeply, as there are several possible errors that lead to a model being unable to load, so the initial error ("failed to load model") is on top of the underlying error (in this case, "file not found").
Taken from the Documentation entries I wrote on the subject, with some minor alterations and updates:
As with blocks, items need models too.
{
"parent": "item/generated",
"textures": {
"layer0": "example:items/basic"
}
}
That's pretty much all that's needed for it to work once the item is registered. The only important thing is that the filename match the registry name used to register the block and should be in all lowercase (1.11+ file names are required to be lowercase, prior to that it is just case sensitive).
Name the model JSON file matching the registry name and save it at src\main\resources\assets\example\models\item\ (where example is the mod ID specified in the #Mod annotation of your main mod class).
Additionally create a texture for your item, name it basic.png and save it to src\main\resources\assets\example\textures\items\ (The file is referenced by the model via "layer0": "example:items/basic" which says "find a .png file named 'basic' inside the items folder of the resource location example")
The item model here uses a parent of item/generated, which means that the single supplied texture will be used (as with most non-block items) and will be held in the player's hand in a default orientation. There is also item/handheld which specifies different display orientations (for tools). Items may also supply their own "display" attribute, overriding those from the parent, but is not needed in 99.9% of uses.
Registering the item:
Item item = new CustomItem();
string registryname = "my_item";
item.setRegistryName(registryname);
item.setUnlocalizedName(item.getRegistryName().toString());
GameRegistry.register(item);
There is an important reason to use item.setUnlocalizedName(item.getRegistryName().toString()); as well! It insures that your item's unlocalized name contains your mod ID to avoid language file conflicts between mods. It is unlikely, but entirely avoidable.
Registering the item model:
final ModelResourceLocation fullModelLocation = new ModelResourceLocation(item.getRegistryName().toString(), "inventory");
ModelBakery.registerItemVariants(item, fullModelLocation);
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
{
public ModelResourceLocation getModelLocation(ItemStack stack)
{
return fullModelLocation;
}
});
Note that this section must be located client-side only (i.e. the client proxy) as many of the referenced classes do not exist on the dedicated server.
Registering items with variants e.g. Saplings, has to be done a different way, using ModelLoader.setCustomModelResourceLocation(item, metadata, resourceLocation) although it lets us use a Blockstate file to specify our variants (which is much preferred to the alternative).
For 1.12+ modders:
This also works in 1.11, but is required in 1.12 and forward
GameRegistry.register() is now private. Instead you must register things in the RegistryEvent.Register<T> event through an event handler. Simply subscribe to the RegistryEvent.Register<Item> or RegistryEvent.Register<Block> event (as well as others: an event is fired for each registry type) in order to register items and blocks. Simply call event.getRegistry().add(...) or event.getRegistry().addAll(...) for every object that needs to be registered. addAll will accept an array or list. You can see an example of this here.
For models, you do the same thing as above, but in the ModelRegistryEvent instead. You can see an example of this here although heavily modified to allow for additional variations in models not discussed here (supporting custom MeshDefinitions and StateMappers).

"Different objects with the same identifiers" error

I'm using in a Java project RMI + Hibernate and I'm experiencing problems related to NotUniqueException with the error "Different objects with the same identifier".
I've got several doubts:
I'm pretty surre that I don't copy nor create new objects with the same ide
ntifiers. Is it possible that RMI creates a new object from another one when I use it?
Which method is using Hibernate to know that two objects are the same? equals?
I know that Serializable is related to Hibernate but I don't know in what way?
How can I solve the "Differents objects error" using RMI at the same time?
Is it correct every time I use delete or save over an object use merge before?
The stack traces is:
org.orm.PersistentException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [dcl.Administrador#10]
at org.orm.PersistentSession.saveOrUpdate(PersistentSession.java:648)
at org.orm.PersistentManager.saveObject(PersistentManager.java:274)
at dcl.AdministradorDAO.save(AdministradorDAO.java:240)
at dcl.BdAdministrador.guardarAdministrador(BdAdministrador.java:62)
at dcl.BdAdministrador.actualizarAdministrador(BdAdministrador.java:109)
at dcl.BdPrincipal.actualizarAdministrador(BdPrincipal.java:555)
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 sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Thanks in advance.
If you're doing something like returning a hibernate object from an RMI method, then passing it back into another one, then you'll potentially need to reattach the object to the session. (see What is the proper way to re-attach detached objects in Hibernate?).
Perhaps give some more info on what you're attempting if this doesn't help.

Problem with rest web service?

I have a rest web service, that retrives data from my sql database using hibernate technology. While running, the web sevice throws error below
java.lang.NoClassDefFoundError: Could not initialize class com.sample.restlet.HibernateSessionFactory
com.sample.restlet.EmployeeResource.(EmployeeResource.java:22)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:158)
com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:148)
com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getInstance(PerRequestFactory.java:175)
com.sun.jersey.server.impl.resource.PerRequestFactory$AbstractPerRequest.getInstance(PerRequestFactory.java:132)
com.sun.jersey.server.impl.application.WebApplicationContext.getResource(WebApplicationContext.java:160)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:64)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:543)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:502)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:493)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:308)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:314)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:239)
I dont get why this problem is coming. Please help.
A java.lang.NoClassDefFoundError: Could not initialize class XXX means that the class is found, but its initialization failed. Possible cause include:
missing dependent classes.
an exception thrown during execution of a static initialization block in the class.
Don't you get more info in the server logs? Any Caused by?
Providing the code of com.sample.restlet.HibernateSessionFactory might help too?

Categories