Follow up: I realize my code above wasn't the correct version. Here it is fixed.
#################################################
marten <- nimbleCode ({
# Priors and constraints
beta0 ~ dunif(-20,20) # intercept for density
beta1 ~ dnorm(0,0.01) # Effect of ddi on density
beta2 ~ dnorm(0,0.01) # Effect of snow
beta3 ~ dnorm(0,0.01) # Effect of ladder fuels
beta4 ~ dnorm(0,0.01) # Effect of fisher
beta5 ~ dnorm(0,0.01) # Effect of bobcat
sigma ~ dunif(0,2400)
p0 ~ dunif(0,5) # lambda = baseline trap encounter rate
for(g in 1:ngrid) { # For each grid cell
mu[g] <- exp(beta0 + beta1 * ddi[g]
+ beta2 * snow[g] + beta3 * ladder[g] + beta4 * fisher[g] + beta5 * bobcat[g]) * pixArea
probs[g] <- mu[g] / EN # probability of an activity center being located in grid cell g
} #g, grid cells
EN <- sum(mu[1:ngrid])
psi <- EN/M
for (i in 1:M){ # For each individual (n+nz=M)
# Make activity centers
z[i] ~ dbern(psi)
s[i] ~ dcat(probs[1:ngrid])
x0g[i] <- grid[s[i],1]
y0g[i] <- grid[s[i],2]
#logit(p0[i]) <- alpha0 + alpha1 * sex[i]
for (j in 1:J){ # For each hair snare
Dist2[i,j] <- sqrt((x0g[i] - trapmatrix[j,1])^2 + (y0g[i] - trapmatrix[j,2])^2)
p[i,j] <- z[i] * p0 * exp(-(1 / (2 * sigma * sigma)) * Dist2[i,j] * Dist2[i,j])
y[i,j] ~ dbern(p[i,j]) # p = probability of detection/encounter
} #j, hair snares
} #i, individuals
N <- sum(z[]) # population size (N)
})