Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » "Cannot be resolved to a type" error(I am having an error while coding in java.)
"Cannot be resolved to a type" error [message #1778610] Mon, 18 December 2017 17:27 Go to next message
blinxboy iakm is currently offline blinxboy iakmFriend
Messages: 1
Registered: December 2017
Junior Member
Hi, I am coding a minecraft mod using some tutorials i found on youtube. They are by a youtuber named MrCrayfish. I was on tutorial number three of 1.8 Modding Tutorials.

Anyway, i have relatively little code, but here it is:

package iAkM.UHC;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class TutorialMod {

@EventHandler
public void preInit(FMLPreInializationEvent event)
{

}
@EventHandler
public void init(FMLInializationEvent event)
{

}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{

}
}

I also have a Reference class for MOD_ID. VERSION, AND MOD_NAME. I keep getting these errors:

EventHandler cannot be resolved to a type
EventHandler cannot be resolved to a type
EventHandler cannot be resolved to a type
FMLInializationEvent cannot be resolved to a type
FMLPreInializationEvent cannot be resolved to a type

I have been looking for the answer for quite some time now, can anyone help me with this? Thanks!
Re: "Cannot be resolved to a type" error [message #1778863 is a reply to message #1778610] Fri, 22 December 2017 14:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
You'll need to make sure the library jars are on the classpath.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: "Cannot be resolved to a type" error [message #1805899 is a reply to message #1778863] Sat, 27 April 2019 08:13 Go to previous messageGo to next message
sefiroths sefiroths is currently offline sefiroths sefirothsFriend
Messages: 6
Registered: January 2015
Junior Member
I have the same error with 1.13.2
any ideas?

index.php/fa/35410/0/
index.php/fa/35411/0/
Re: "Cannot be resolved to a type" error [message #1805902 is a reply to message #1805899] Sat, 27 April 2019 10:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
It seems the first import resolves correctly. Can you F3 to the source from that? Is the source what you'd expect with a nested annotation like what I see here:

https://github.com/MinecraftForge/FML/blob/master/src/main/java/net/minecraftforge/fml/common/Mod.java


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: "Cannot be resolved to a type" error [message #1805908 is a reply to message #1805902] Sat, 27 April 2019 17:26 Go to previous messageGo to next message
sefiroths sefiroths is currently offline sefiroths sefirothsFriend
Messages: 6
Registered: January 2015
Junior Member
yes it goes in Mod.class
Re: "Cannot be resolved to a type" error [message #1805909 is a reply to message #1805908] Sat, 27 April 2019 17:28 Go to previous messageGo to next message
sefiroths sefiroths is currently offline sefiroths sefirothsFriend
Messages: 6
Registered: January 2015
Junior Member
but it looks like this:
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.fml.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.function.Supplier;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.ModLifecycleEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

/**
* This defines a Mod to FML.
* Any class found with this annotation applied will be loaded as a Mod. The instance that is loaded will
* represent the mod to other Mods in the system. It will be sent various subclasses of {@link ModLifecycleEvent}
* at pre-defined times during the loading of the game.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Mod
{
/**
* The unique mod identifier for this mod.
* <b>Required to be lowercased in the english locale for compatibility. Will be truncated to 64 characters long.</b>
*
* This will be used to identify your mod for third parties (other mods), it will be used to identify your mod for registries such as block and item registries.
* By default, you will have a resource domain that matches the modid. All these uses require that constraints are imposed on the format of the modid.
*/
String value();

/**
* Annotate a class which will be subscribed to an Event Bus at mod construction time.
* Defaults to subscribing the current modid to the {@link MinecraftForge#EVENT_BUS}
* on both sides.
*
* @see Bus
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface EventBusSubscriber {
/**
* Specify targets to load this event subscriber on. Can be used to avoid loading Client specific events
* on a dedicated server, for example.
*
* @return an array of Dist to load this event subscriber on
*/
Dist[] value() default { Dist.CLIENT, Dist.DEDICATED_SERVER };

/**
* Optional value, only necessary if this annotation is not on the same class that has a @Mod annotation.
* Needed to prevent early classloading of classes not owned by your mod.
* @return a modid
*/
String modid() default "";

/**
* Specify an alternative bus to listen to
*
* @return the bus you wish to listen to
*/
Bus bus() default Bus.FORGE;

enum Bus {
/**
* The main Forge Event Bus.
* @see MinecraftForge#EVENT_BUS
*/
FORGE(()-> MinecraftForge.EVENT_BUS),
/**
* The mod specific Event bus.
* @see FMLJavaModLoadingContext#getModEventBus()
*/
MOD(()-> FMLJavaModLoadingContext.get().getModEventBus());

private final Supplier<IEventBus> busSupplier;

Bus(final Supplier<IEventBus> eventBusSupplier) {
this.busSupplier = eventBusSupplier;
}

public Supplier<IEventBus> bus() {
return busSupplier;
}
}
}
}
Re: "Cannot be resolved to a type" error [message #1805919 is a reply to message #1805909] Sun, 28 April 2019 03:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Well that kind of explains it doesn't it? I.e., the things you're trying to import aren't present in the version of the library you have on your classpath. Perhaps you have an older version where these aren't yet present or you have a newer version where these things have been removed. You'll have to find an appropriate version to use or adjust your code to work with the version you have.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: "Cannot be resolved to a type" error [message #1805926 is a reply to message #1805919] Sun, 28 April 2019 14:12 Go to previous message
sefiroths sefiroths is currently offline sefiroths sefirothsFriend
Messages: 6
Registered: January 2015
Junior Member
That's right, thanks
Previous Topic:Install & Update Nightmares
Next Topic:Payara Tools plugin for Eclipse won't install
Goto Forum:
  


Current Time: Fri Mar 29 04:49:08 GMT 2024

Powered by FUDForum. Page generated in 0.03963 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top