This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Thomasims3's profile picture

[Solved][Java] IPeripheral implementation gives error with my peripheral

Started by Thomasims3, 13 February 2013 - 11:17 PM
Thomasims3 #1
Posted 14 February 2013 - 12:17 AM
Hello,

I am rewritting CCPortable, a mod that adds PDAs to Computercraft and I'm stuck on the TileEntity part.
I think the code is correct (and eclipse doesn't give errors) but when i lauch it, I get this crash log:

2013-02-13 12:07:36 [FINER] [ForgeModLoader] Sending event FMLConstructionEvent to mod CCPortable
2013-02-13 12:07:36 [INFO] [STDERR] Exception in thread "Minecraft main thread" java.lang.NoClassDefFoundError: CCPortable/common/TileEntityPDA
2013-02-13 12:07:36 [INFO] [STDERR]  at java.lang.Class.getDeclaredMethods0(Native Method)
2013-02-13 12:07:36 [INFO] [STDERR]  at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
2013-02-13 12:07:36 [INFO] [STDERR]  at java.lang.Class.getDeclaredMethods(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.common.FMLModContainer.gatherAnnotations(FMLModContainer.java:310)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.common.FMLModContainer.constructMod(FMLModContainer.java:455)
2013-02-13 12:07:37 [INFO] [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2013-02-13 12:07:37 [INFO] [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.reflect.Method.invoke(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.EventBus.post(EventBus.java:268)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:140)
2013-02-13 12:07:37 [INFO] [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2013-02-13 12:07:37 [INFO] [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.reflect.Method.invoke(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
2013-02-13 12:07:37 [INFO] [STDERR]  at com.google.common.eventbus.EventBus.post(EventBus.java:268)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:83)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.common.Loader.loadMods(Loader.java:479)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:161)
2013-02-13 12:07:37 [INFO] [STDERR]  at net.minecraft.client.Minecraft.a(Minecraft.java:410)
2013-02-13 12:07:37 [INFO] [STDERR]  at asq.a(SourceFile:56)
2013-02-13 12:07:37 [INFO] [STDERR]  at net.minecraft.client.Minecraft.run(Minecraft.java:744)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.Thread.run(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR] Caused by: java.lang.ClassNotFoundException: CCPortable.common.TileEntityPDA
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:185)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.ClassLoader.loadClass(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.ClassLoader.loadClass(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  ... 31 more
2013-02-13 12:07:37 [INFO] [STDERR] Caused by: java.lang.NoClassDefFoundError: dan200/computer/api/IPeripheral
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.ClassLoader.defineClass1(Native Method)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.ClassLoader.defineClass(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.security.SecureClassLoader.defineClass(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:174)
2013-02-13 12:07:37 [INFO] [STDERR]  ... 33 more
2013-02-13 12:07:37 [INFO] [STDERR] Caused by: java.lang.ClassNotFoundException: dan200.computer.api.IPeripheral
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:185)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.ClassLoader.loadClass(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at java.lang.ClassLoader.loadClass(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  ... 37 more
2013-02-13 12:07:37 [INFO] [STDERR] Caused by: java.lang.NullPointerException
2013-02-13 12:07:37 [INFO] [STDERR]  at org.objectweb.asm.ClassReader.<init>(Unknown Source)
2013-02-13 12:07:37 [INFO] [STDERR]  at net.minecraftforge.transformers.EventTransformer.transform(EventTransformer.java:29)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.relauncher.RelaunchClassLoader.runTransformers(RelaunchClassLoader.java:228)
2013-02-13 12:07:37 [INFO] [STDERR]  at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:173)
2013-02-13 12:07:37 [INFO] [STDERR]  ... 39 more

Here is the code of the TileEntity:

package CCPortable.common;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral;
public class TileEntityPDA extends TileEntity implements IPeripheral {
public IComputerAccess computer;
public int id;
public int pda;
public int side = -1;
// public static World world;
@Override
public String getType() {
  return "PDA_receiver";
}
@Override
public String[] getMethodNames() {
  String[] methods = { "alert", "write", "setCursorPos" };
  return methods;
  // ME WANT TERM FUNCTIONS
}
@Override
public Object[] callMethod(IComputerAccess computer, int method,
   Object[] arg) throws Exception {
  EntityPlayer ply = (EntityPlayer) CCPortable.allPLYs.get(this.pda);
  ObjectPDA pda = (ObjectPDA) CCPortable.allPDAs.get(this.pda);
  switch (method) {
  case 0:
   if (arg.length == 2 &amp;&amp; arg[0] instanceof Double &amp;&amp; arg[1] instanceof Double)
	this.worldObj.addBlockEvent((int) ply.posX, (int) ply.posY,
	  (int) ply.posZ, Block.music.blockID, (Integer) arg[0],
	  (Integer) arg[1]);
   else
	throw new Exception("Invalid arguments to function");
  case 1:
   if (arg.length == 1 &amp;&amp; arg[0] instanceof String) {
	pda.write((String) arg[0]);
	CCPortable.allPDAs.put(this.pda, pda);
   } else {
	throw new Exception("Invalid arguments to function");
   }
  case 2:
   if (arg.length == 2 &amp;&amp; arg[0] instanceof Double &amp;&amp; arg[1] instanceof Double) {
	pda.setCursorPos((Integer) arg[0], (Integer) arg[1]);
	CCPortable.allPDAs.put(this.pda, pda);
   } else {
	throw new Exception("Invalid arguments to function");
   }
  }
  return null;
}
@Override
public boolean canAttachToSide(int sidee) {
  if (this.side == -1) {
   this.side = sidee;
   return true;
  }
  return this.side == sidee;
}
@Override
public void attach(IComputerAccess acomputer) {
  /*this.computer = acomputer;
  this.computer.mountFixedDir("rom/apis/receiver",
	"mods/CCPortable/receiver.lua", true, 0);*/
}
@Override
public void detach(IComputerAccess computer) {
  /*this.computer.unmount("rom/apis/receiver");
  this.computer = null;
  this.side = -1;*/
}
public int getID() {
  return this.id;
}
public void setPDA(int id) {
  this.pda = id;
}
public void readFromNBT(NBTTagCompound nbt) {
  super.readFromNBT(nbt);
  this.id = nbt.getInteger("ID");
  this.pda = nbt.getInteger("PID");
}
public void writeToNBT(NBTTagCompound nbt) {
  super.writeToNBT(nbt);
  nbt.setInteger("ID", this.id);
  nbt.setInteger("PID", this.pda);
}
}
If you need to see the rest of the code, it is on my GitHub: https://github.com/T...ims/CCPortable/

Thanks for reading.

Thomasims
Skullblade #2
Posted 14 February 2013 - 01:00 AM
Just so you know… PDAs are officially planned in development…fyi
immibis #3
Posted 14 February 2013 - 01:33 AM
How are you trying to run it? In Eclipse?
Cloudy #4
Posted 14 February 2013 - 01:38 AM
You've packaged it wrong.
Thomasims3 #5
Posted 14 February 2013 - 03:19 AM
Just so you know… PDAs are officially planned in development…fyi
Yes.. I have a lot of new features planned to compete :)/>

How are you trying to run it? In Eclipse?
I tried in Eclipse and out of Eclipse (MultiMC)

You've packaged it wrong.
What do you mean? do I have to put the TileEntity in a special package?
It works if I don't implement IPeripheral
Lyqyd #6
Posted 14 February 2013 - 04:45 AM
Moved to Peripheral Help and Discussion.
Orwell #7
Posted 14 February 2013 - 05:03 AM
Let's say you put all the compiled files into CCPortable.zip, then make sure your tile entity file is at this exact path:
CCPortable.zip/CCPortable/common/TileEntityPDA.class

Chances are that you get this error because it can't find the class file at that path while doing reflection.
Thomasims3 #8
Posted 14 February 2013 - 05:48 AM
Let's say you put all the compiled files into CCPortable.zip, then make sure your tile entity file is at this exact path:
CCPortable.zip/CCPortable/common/TileEntityPDA.class

Chances are that you get this error because it can't find the class file at that path while doing reflection.
Oh that. yes it's in the right folder, I think the problem comes from the peripheral implementation because I can get it to work if I remove "implements IPeripheral"at the top.
EDIT: by "I can get it to work" I mean that it doesn't crash the game
Orwell #9
Posted 14 February 2013 - 06:02 AM
Let's say you put all the compiled files into CCPortable.zip, then make sure your tile entity file is at this exact path:
CCPortable.zip/CCPortable/common/TileEntityPDA.class

Chances are that you get this error because it can't find the class file at that path while doing reflection.
Oh that. yes it's in the right folder, I think the problem comes from the peripheral implementation because I can get it to work if I remove "implements IPeripheral"at the top.
EDIT: by "I can get it to work" I mean that it doesn't crash the game
That probably has to do with the reflection. That still doesn't mean it's a fault in the implementation of IPeripheral, but rather that the reflection mechanism can't find your class where it should be. So in the end it's more likely that you made a mistake, wouldn't know which though. IPeripheral has always worked for me. Can you post a print screen of the contents of your zip file or something? Or just type out the structure? Up to TileEntityPDA.class at least.
Thomasims3 #10
Posted 14 February 2013 - 08:26 AM
I've been chatting with a guy who tests the code on my github and he says that he doesn't have that problem. anyway, here is the structure:

CCPortable.zip
    -CCPortable
        -client
            -ClientProxy.class
            -GuiPDA.class
        -common
            -BlockReceiver.class
            -CCPortable.class
            -CommonProxy.class
            -ObjectPDA.class
            -ItemPDA.class
            -ItemPDAPart.class
            -TileEntityPDA.class
            -PacketHandler.class(not yet implemented)

If you want compiled code it's also on my GitHub.
Cloudy #11
Posted 14 February 2013 - 09:21 AM
Actually, you didn't package it wrong.


Caused by: java.lang.ClassNotFoundException: dan200.computer.api.IPeripheral

When your class is instanciated, IPeripheral doesn't exist - either because CC isn't installed, or because your mod is being loaded before. Ensure it loads after using the methods included in FML.
Thomasims3 #12
Posted 14 February 2013 - 09:49 AM
Oh, I didn't even think about that, indeed the mod comes before computercraft in my mods folder.
Thanks for pointing that out Cloudy.
I'll try changing the order it loads the mods tomorow.
Orwell #13
Posted 14 February 2013 - 02:21 PM
I always add this to my @Mod annotation:

@Mod( modid = "xxx", name = "xxx", version = "x.x.x", dependencies = "required-after:ComputerCraft;after:CCTurtle")
Thomasims3 #14
Posted 15 February 2013 - 12:17 AM
It's working thanks everyone for your help. Now I can continue on adding more features :)/>
I always add this to my @Mod annotation:

@Mod( modid = "xxx", name = "xxx", version = "x.x.x", dependencies = "required-after:ComputerCraft;after:CCTurtle")
I didn't know how to deal with the dependecies in @mod, thanks!