Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I make two variables and store 'array[1]' in the first and 'array[2]' in the second, but when I use 'array[2]' I get a NullPointerExeption

	static File path = new File(Minecraft.getMinecraft().mcDataDir, "//TVMod"); 
public static File[] filesList = path.listFiles();

static File imagePath = new File(Minecraft.getMinecraft().mcDataDir, "//TVMod//TVTexture.png");
static File overlayLocation = new File(Minecraft.getMinecraft().mcDataDir, "//TVMod//");


static File overlayPath1 = new File(Minecraft.getMinecraft().mcDataDir, "\\TVMod\\" + filesList[1].getName()); 
static File overlayPath2 = new File(Minecraft.getMinecraft().mcDataDir, "\\TVMod\\" + filesList[2].getName()); 


public static BufferedImage overlay;
public static BufferedImage image;

        public static void PictureOverlay1() throws IOException{
	overlay = ImageIO.read(new File(overlayPath2, ""));
	image = ImageIO.read(new File(imagePath, ""));

	if(!path.exists()){
	System.out.println("Creating File");
	path.mkdir();

	} else {
		System.out.println("Already Created");

			// create the new image, canvas size is the max. of both image sizes
			int w = Math.max(image.getWidth(), overlay.getWidth());
			int h = Math.max(image.getHeight(), overlay.getHeight());
			BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

			// paint both images, preserving the alpha channels
			Graphics g = combined.getGraphics();
			g.drawImage(image, 0, 0, null);
			g.drawImage(overlay, 0, 0, null);

			// Save as new image
			ImageIO.write(combined, "PNG", new File("C:/Users/Daniel/Documents/Brain Bang/Coding/Minecraft Modding/New  Mods/1.6.4 Television Mod/forge/mcp/src/minecraft/assets/tvmod/textures/blocks/combined.png"));
		}
		}

path.listFiles() probably return an array of 2 elements, but mind that you count from 0 when using arrays (or in programming in general), so filesList[0] and filesList[1] get you the first and second elements. That might not be the whole problem though, because I suppose the error would have been IndexOutOfBoundsException, not NullPointerException. Are you sure the exception raises only on filesList[2]?

Check out my blog!

http://www.whov.altervista.org

Hi

 

I think there might be several problems causing your error (assuming it's an ArrayOutOfBounds and not a NullPointerException) -

the first is that array counting starts from 0 not 1 like Whov said.

the second is - what happens if path.listFiles() doesn't return any entries, perhaps because the directory is empty?

the third is that all those static variable initialisations might occur before mcDataDir has been initialised, so the directory may be invalid.  Better to initialise them in the constructor, and construct the object in your preInitialisation phase.

 

If you fix those things and it still doesn't work, show us your error log?

 

-TGG

 

 

  • Author

Hi

 

I think there might be several problems causing your error (assuming it's an ArrayOutOfBounds and not a NullPointerException) -

the first is that array counting starts from 0 not 1 like Whov said.

the second is - what happens if path.listFiles() doesn't return any entries, perhaps because the directory is empty?

the third is that all those static variable initialisations might occur before mcDataDir has been initialised, so the directory may be invalid.  Better to initialise them in the constructor, and construct the object in your preInitialisation phase.

 

If you fix those things and it still doesn't work, show us your error log?

 

-TGG

 

 

 

 

Thanks I fixed it

 

 if (pictureList != null && pictureList.length>0){
  overlay1 = new File(Minecraft.getMinecraft().mcDataDir, "\\TVMod\\Pictures\\" + pictureList[0].getName());
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.