A static problem and i need help

Page 1 of 1

14 Replies - 421 Views - Last Post: 09 April 2011 - 08:18 PM Rate Topic: -----

#1 baseball435  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 30-November 09

A static problem and i need help

Posted 09 April 2011 - 01:35 PM

well i have been searching google for about an hour now trying to figure out what is wrong. What im trying to do is call a method from a different java file and run it. If that makes sence.

On the file at the top i imported the other java file (EntityGrenade):
import net.minecraft.src.EntityGrenade;


That is in the ItemDet file.

I also have this in the same file in a method called onRightClick:
EntityGrenade.explode();


There i am trying to run the method, explode.

On the EntityGrenade File, the explode method says:
public void explode()
{
	worldObj.createExplosion(null, posX, posY, posZ, 2F);
}



that is the code i am trying to run. When i compile it i get the error

ItemDetonator.java:21: non-static method explode cannot be referenced from a staic context

EntityGrenade.explode();



Then there is a little arrow under the "."

Can someone please please please tell me how to fix this? im soo confused and dont know why its happening. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: A static problem and i need help

#2 softwareEngineer()  Icon User is offline

  • D.I.C Head

Reputation: -28
  • View blog
  • Posts: 247
  • Joined: 08-April 11

Re: A static problem and i need help

Posted 09 April 2011 - 01:50 PM

From what I see is that the function that makes the grenade detonate is static, and what you are doing is not.
Was This Post Helpful? 0
  • +
  • -

#3 exiles.prx  Icon User is offline

  • D.I.C Head

Reputation: 64
  • View blog
  • Posts: 224
  • Joined: 22-November 10

Re: A static problem and i need help

Posted 09 April 2011 - 02:00 PM

You are attempting to call the method explode() in a static way, so therefore you need to declare your method as a static method. public static void explode() should be the method signature within your EntityGrenade class.
Was This Post Helpful? 0
  • +
  • -

#4 baseball435  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 30-November 09

Re: A static problem and i need help

Posted 09 April 2011 - 02:16 PM

Yes i did try that and when i did it started to say, from this code:
worldObj.createExplosion(null, posX, posY, posZ, 2F);


It started to say that posX, posY, and posZ werent static
Was This Post Helpful? 0
  • +
  • -

#5 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 195
  • View blog
  • Posts: 1,620
  • Joined: 13-March 10

Re: A static problem and i need help

Posted 09 April 2011 - 02:23 PM

You have to have the object of that class and use it to invoke the method of that class.

for example:


class Apple
{
public Apple()
{

}

public void printApple()
{
System.out.println("This is the apple");
}

}






class Banana
{
private Apple apple;

public Banana()
{
apple = new Apple();//this is where we create the OBJECT
}

public void fruit()
{
System.out.println("This is the banana and apple is coming!");
apple.printApple();//now we can use THAT apple object to invoke a method of the Apple class
}

}



Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#6 baseball435  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 30-November 09

Re: A static problem and i need help

Posted 09 April 2011 - 02:40 PM

well i did that but now it says:
EntityGrenade is abstract; cannot be instantiated 


what does that mean?
Was This Post Helpful? 0
  • +
  • -

#7 baseball435  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 30-November 09

Re: A static problem and i need help

Posted 09 April 2011 - 03:21 PM

yes i did that but when i compile it says:
ItemDetonator.java:22: cannot find symbol
Symbol: constructor EntityGrenade()
Location: class .net.mc.src.EntityGrenade

eg = new EntityGrenade();
     ^



then it has the little arrow under the n in new. what does this mean now.
Was This Post Helpful? 0
  • +
  • -

#8 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 195
  • View blog
  • Posts: 1,620
  • Joined: 13-March 10

Re: A static problem and i need help

Posted 09 April 2011 - 03:30 PM

It seems to be that you dont know what the constructor is, inheritance (abstract classes) etc.

The error you are getting occurs since you do not have the constructor declared that does not take any parameters.

And about the abstract classes - they cannot be instantiated - meaning that you cant call "new" on them. Make a sublcass, implements all the abstract methods and instantiate an object of that subclass.

If you dont understand that, then read about the basics.

Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#9 softwareEngineer()  Icon User is offline

  • D.I.C Head

Reputation: -28
  • View blog
  • Posts: 247
  • Joined: 08-April 11

Re: A static problem and i need help

Posted 09 April 2011 - 03:36 PM

I think learning the things in this section of the Java Tutorials would help.

I know you probably are really big on Minecraft, so you most likely just picked up a mod and ran with it off an internet tutorial. It would be very beneficial to you if you looked at the link.
Was This Post Helpful? 1
  • +
  • -

#10 baseball435  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 30-November 09

Re: A static problem and i need help

Posted 09 April 2011 - 04:15 PM

View PostsoftwareEngineer(), on 09 April 2011 - 04:36 PM, said:

I think learning the things in this section of the Java Tutorials would help.

I know you probably are really big on Minecraft, so you most likely just picked up a mod and ran with it off an internet tutorial. It would be very beneficial to you if you looked at the link.


haha yes good guess, i do like minecraft. and no your wrong on me just finding an internet tutorial. Ive already made two mods but now im moving onto different things which i havent dealt with before.

My first mod: InstaHouse
My Second Mod: Castle Creation

So no, its not some stupid tutorial off of the internet. I made it myself. Like I said, im just moving onto different things and came across these problems and tried fixing them but it didnt work. So my last resort was here.
Was This Post Helpful? 0
  • +
  • -

#11 softwareEngineer()  Icon User is offline

  • D.I.C Head

Reputation: -28
  • View blog
  • Posts: 247
  • Joined: 08-April 11

Re: A static problem and i need help

Posted 09 April 2011 - 04:20 PM

Well I would think this would be yor first resort.

It does seem though that you might need to include more files from Minecraft, and that you need to change how you are using the detenator method.
Was This Post Helpful? 0
  • +
  • -

#12 baseball435  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 30-November 09

Re: A static problem and i need help

Posted 09 April 2011 - 04:50 PM

well people always say google. So i tried that first :P and i dont think so. thats really all i need
Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9042
  • View blog
  • Posts: 33,540
  • Joined: 27-December 08

Re: A static problem and i need help

Posted 09 April 2011 - 06:20 PM

Post all your code and error messages. :)
Was This Post Helpful? 1
  • +
  • -

#14 baseball435  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 30-November 09

Re: A static problem and i need help

Posted 09 April 2011 - 08:00 PM

View Postmacosxnerd101, on 09 April 2011 - 07:20 PM, said:

Post all your code and error messages. :)


alright here we go

ItemDetonator.java
package net.minecraft.src;

// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 

import java.util.Random;

import net.minecraft.src.EntityGrenade;

public class ItemDetonator extends Item
{
    private EntityGrenade eg;

    public ItemDetonator(int itemIndex)
    {
        super(itemIndex);
    }

    public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
    {
       	eg = new EntityGrenade();
	eg.explode();
    }
}


EntityGrenade.java
package net.minecraft.src;

public class EntityGrenade extends EntityItem
{

    public EntityGrenade(World world)
    {
        super(world);
        setSize(0.5F, 0.5F);
        yOffset = height / 2.0F;
        item = new ItemStack(ItemGrenade.grenadeID);
    }

    public EntityGrenade(World world, Entity entity)
    {
        this(world);
   // Set the position
        setPosition(entity.posX, entity.posY, entity.posZ);
        prevPosX = posX;
        prevPosY = posY;
        prevPosZ = posZ;
    }

    public void onCollideWithPlayer(EntityPlayer entityplayer)
    {
       // Have to override the item's function
    }

    public void explode()
    {
	worldObj.createExplosion(null, posX, posY, posZ, 2F);
    }

}



error code as of now:
ItemDetonator.java:22: cannot find symbol
Symbol: Constructor EntityGrenade
Location: Class net.minecraft.src.EntityGrenade

eg = new EntityGrenade();
     ^
1 Error



And yeah thats it, thanks in advance.

Oh and btw i couldnt help but notice your sig: When in doubt, Google. hahaha proves my point :P
Was This Post Helpful? 0
  • +
  • -

#15 pbl  Icon User is online

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8030
  • View blog
  • Posts: 31,176
  • Joined: 06-March 08

Re: A static problem and i need help

Posted 09 April 2011 - 08:18 PM

You decompiled using JAD code stolen on the net and you think we will help ?
There are a lot of legal implications on that.
Topic closed that's all.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1