ViperLordX ViperLordX - 5 months ago 20x
Java Question

NullPointerException with no stack trace

Java, for some reason, is giving me a

. I know that this is usually easy to fix, but in this case, I can't figure out why it's throwing it in the first place. Why can't I figure it out? Well, because it has no stack trace! Here's my code:

package redempt.divinity.ability.modifier.modifiers;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;
import redempt.divinity.ability.AbilityType;
import redempt.divinity.ability.modifier.ProjectileModifier;

public class NoGravity extends ProjectileModifier {
Vector vector;
Location lastpos;
public void onUse(Player player, Entity projectile) {
vector = player.getLocation().getDirection().normalize();
lastpos = projectile.getLocation();
public String getName() {
return "No gravity";
public Material getRepresentation() {
return Material.FEATHER;
public AbilityType getType() {
return AbilityType.PROJECTILE;
public void onHit(EntityDamageByEntityEvent event) {
public void onTick(Entity entity) {
try {
if (lastpos == null) {
lastpos = entity.getLocation();
if (entity.getLocation().getBlock().getType().equals(Material.AIR)) {
lastpos = entity.getLocation();
} catch (Exception e) {

is called every tick,
is called before it starts calling
, and here's the console output:

[11:26:52 INFO]: Exception
[11:26:52 WARN]: java.lang.NullPointerException
... this repeats often

So what the hell does this mean, why does it happen, and how do I fix it?


Probably issue with JVM, pass this argument to it in order to have full stack trace:


Now, NPE is there because something out there is null and you try to call a method from it. Potential candidates are entity since you call entity.getLocation(), then entity.getLocation(), since you call entity.getLocation().getBlock(), or even object you get when calling entity.getLocation().getBlock().getType() Check them out too not only lastpos .