# A void function says "parameter p is not used" and giving a null pointer exception

**URL:** <https://discourse.processing.org/t/a-void-function-says-parameter-p-is-not-used-and-giving-a-null-pointer-exception/48469>\
**Category:** Beginners\
**Created:** [April 26, 2026, 5:12am UTC](https://discourse.processing.org/t/a-void-function-says-parameter-p-is-not-used-and-giving-a-null-pointer-exception/48469 "2026-04-26T05:12:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aribobari](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aribobari/32/21767_2.png) [@Aribobari](https://discourse.processing.org/u/Aribobari)\
**Post date:** [April 26, 2026, 5:12am UTC](https://discourse.processing.org/t/a-void-function-says-parameter-p-is-not-used-and-giving-a-null-pointer-exception/48469/1 "2026-04-26T05:12:15Z")

</div>

I am working on a deck loading and shuffling program as a jumping off point to code a playable card game, but the function I am using to get the face of each card is returning a null pointer exception on the first if statement. split would put anything before ’ ’ at the zero’th position if i’m not mistaken and the code seems to be getting past the similar code for the card backs fine (that is calling to the one’th position in its array).

```auto
void getCardFace(String s, PImage p){
  String[] ary = new String[2];
  ary = split(s,' ');
   if(ary[0]=="GenNuis"){
     p = GenNuisImg;
   }else if(ary[0]=="ShamGna"){
     p = ShamGnaImg;
   }else if(ary[0]=="BrotCly"){
     p = BrotClyImg;
   }else if(ary[0]=="HeavBol"){
     p = HeavBolImg;
   }else if(ary[0]=="MageBol"){
     p = MageBolImg;
   }else if(ary[0]=="SubSham"){
     p = SubShamImg;
   }else if(ary[0]=="OpenRad"){
     p = OpenRadImg;
   }else if(ary[0]=="BrokMic"){
     p = BrokMicImg;
   }else if(ary[0]=="ConfTra"){
     p = ConfTraImg;
   }else if(ary[0]=="MagAdap"){
     p = MagAdapImg;
   }else if(ary[0]=="Verney"){
     p = VerneyImg;
   }else if(ary[0]=="GalvSta"){
     p = GalvStaImg;
   }else if(ary[0]=="HullTit"){
     p = HullTitImg;
   }else if(ary[0]=="ShiHotl"){
     p = ShiHotlImg;
   }else if(ary[0]=="ShepMag"){
     p = ShepMagImg;
   }else if(ary[0]=="HomeInv"){
     p = HomeInvImg;
   }else if(ary[0]=="Prod"){
     p = ProdImg;
   }else if(ary[0]=="WizProd"){
     p = WizProdImg;
   }else if(ary[0]=="LucTrad"){
     p = LucTradImg;
   }else if(ary[0]=="ConfCra"){
     p = ConfCraImg;
   }else if(ary[0]=="VernEss"){
     p = VernEssImg;
   }else if(ary[0]=="OmnScho"){
     p = OmnSchoImg;
   }else if(ary[0]=="ForgHor"){
     p = ForgHorImg;
   }else if(ary[0]=="SpelFoc"){
     p = SpelFocImg;
   }else if(ary[0]=="MagGath"){
     p = MagGathImg;
   }else if(ary[0]=="BubCaul"){
     p = BubCaulImg;
   }else if(ary[0]=="QueQbie"){
     p = QueQbieImg;
   }else if(ary[0]=="RedBOak"){
     p = RedBOakImg;
   }else if(ary[0]=="OchrGou"){
     p = OchrGouImg;
   }else if(ary[0]=="BloBerr"){
     p = BloBerrImg;
   }
}

```

---

<div class="post-metadata">

**Author:** ![Aribobari](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aribobari/32/21767_2.png) [@Aribobari](https://discourse.processing.org/u/Aribobari)\
**Post date:** [April 26, 2026, 5:18am UTC](https://discourse.processing.org/t/a-void-function-says-parameter-p-is-not-used-and-giving-a-null-pointer-exception/48469/2 "2026-04-26T05:18:38Z")

</div>

I didn’t know how to format the code properly when I first posted this

edit: i just fixed it

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 26, 2026, 10:23am UTC](https://discourse.processing.org/t/a-void-function-says-parameter-p-is-not-used-and-giving-a-null-pointer-exception/48469/3 "2026-04-26T10:23:25Z")

</div>

Welcome to the forum,

In Java string variables must _ **not be compared** _ using the `==` operator because it doesn’t compare the sequence of characters inside the strings rather it tests to see if they are the same _ **string object** _

The following shows how to compare strings in your code

```java
  if(ary[0].equals("GenNuis")){
     p = GenNuisImg;
   }else if(ary[0].equals("ShamGna")){
     p = ShamGnaImg;
   ...

```

This performs a case sensitive test if you are not concerned about whether it uses upper or lower case then use the `equalsIgnoreCase` instead.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 26, 2026, 4:58pm UTC](https://discourse.processing.org/t/a-void-function-says-parameter-p-is-not-used-and-giving-a-null-pointer-exception/48469/4 "2026-04-26T16:58:04Z")

</div>

Hello @Aribobari

Some references:

_[== (equality) / Reference / Processing.org](https://processing.org/reference/equality.html)_

_[Troubleshooting · processing/processing4 Wiki · GitHub](https://github.com/processing/processing4/wiki/Troubleshooting#why-dont-these-strings-equal)_

`:)`

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 26, 2026, 5:32pm UTC](https://discourse.processing.org/t/a-void-function-says-parameter-p-is-not-used-and-giving-a-null-pointer-exception/48469/5 "2026-04-26T17:32:06Z")

</div>

> [@quark](#):
>
> ```auto
> if(ary[0].equals("GenNuis")){
> p = GenNuisImg;
> }else if(ary[0].equals("ShamGna")){
> p = ShamGnaImg;
> ...
> 
> ```

Alternatively, we can instead call **equals()** from the literal string:

```auto
  final String imageName = ary[0];

  if ("GenNuis".equals(imageName)) {
     p = GenNuisImg;
   } else if ("ShamGna".equals(imageName)) {
     p = ShamGnaImg;
   ...

```

Doing so we guard ourselves against a NullPointerException when invoking method **equals()**; b/c a String literal can’t be `null`. 💡

But a more manageable solution is associating each PImage value to its corresponding image name String key using a HashMap container for it:

> **[HashMap / Reference](https://processing.org/reference/hashmap)**
>
> A HashMap stores a collection of objects, each referenced by a key. This is similar to an Array, only instead of accessing elements with a numeric index, a String is used. (If you…

```auto
import java.util.Map;

static final String EXT = ".png", IMAGE_FILENAMES[] = {
  "GenNuis", "ShamGna", "BrotCly", "HeavBol", "MageBol", 
  "SubSham", "OpenRad", "BrokMic", "ConfTra", "MagAdap", 
  "Verney", "GalvSta", "HullTit", "ShiHotl", "ShepMag", 
  "HomeInv", "Prod", "WizProd", "LucTrad", "ConfCra", 
  "VernEss", "OmnScho", "ForgHor", "SpelFoc", "MagGath", 
  "BubCaul", "QueQbie", "RedBOak", "OchrGou", "BloBerr"
};

static final int CAPACITY = (int) (IMAGE_FILENAMES.length / .75) + 1;
final Map<String, PImage> images = new HashMap<String, PImage>(CAPACITY);

void setup() {
  // ...

  loadAllImagesIntoHashMap();
}

void loadAllImagesIntoHashMap() {
  images.clear();
  for (final String s : IMAGE_FILENAMES) images.put(s, loadImage(s + EXT));
}

PImage getCardFace(String imageName) {
  final int spaceIndex = (imageName = trim(imageName)).indexOf(' ');
  if (spaceIndex > 0) imageName = imageName.substring(0, spaceIndex);
  return images.get(imageName);
}

```

Now your function **getCardFace()** is much more compact and its _imageName_ parameter can handle a String containing the name for the PImage, regardless it contains other elements separated by a space. 👨‍🔧
