Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7988615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:30:35+00:00 2026-06-04T12:30:35+00:00

package macroreader; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class MacroReader { public static

  • 0
    package macroreader;

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;

    public class MacroReader {

        public static Macro[] macroArray = new Macro[20];

        public static int macroID;

        public static BufferedReader br;

        public static void main(String[] args) throws IOException {
            br = new BufferedReader(new FileReader("Macros.txt"));
            String currentLine;
            while((currentLine = br.readLine()) != null) {
                if(currentLine.equalsIgnoreCase("#newmacro")) {
                    br.mark(1000);
                    createMacro();
                    br.reset();
                }
            }
            if (br != null) {
                br.close();
            }
        }

    public static void createMacro() throws IOException {
        String currentLine;
        macroID = getEmptyMacro();
        while((currentLine = br.readLine()) != null && !currentLine.equalsIgnoreCase("#newmacro")) {
            macroArray[macroID].readMacro(currentLine);
        }
        macroArray[macroID].inUse = true;
        macroArray[macroID].printData();
    }

    public static int getEmptyMacro() {
        for(int i = 0; i < macroArray.length; i++) {
            if(!macroArray[i].inUse) {
                return i;
            }
        }
        return 0;
    }

}

rather than assigning the values read from the file reader to the specified object in the array, in this case ‘macroID’, it assigns the values to all objects in the array

just edited in the whole file now but the issue is around the createMacro() void

here is my Macro class

package macroreader;

public class Macro {

    public static String key;
    public static String[] commands = new String[20];
    public static boolean inUse;

    public static void readMacro(String input) {
        if (!input.equals("")) {
            if (input.startsWith("key = ")) {
                key = input.substring(6);
                System.out.println("Key Value for Macro set to " + key);
            } else {
                for (int i = 0; i < commands.length; i++) {
                    if (commands[i] == null) {
                        commands[i] = input;
                        System.out.println("Command [" + input + "] assigned");
                        break;
                    }
                }
            }
        }
    }

    public static void printData() {
        System.out.println("Macro Key: " + key);
        for(int i = 0; i < commands.length; i++) {
            if(commands[i] != null) {
                System.out.println(commands[i]);
            }
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:30:39+00:00Added an answer on June 4, 2026 at 12:30 pm

    As I suspected – your inUse is static, so it will always be the same for all instances of the class. As are your other class members.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package jtextareatest; import java.io.FileInputStream; import java.io.IOException; import javax.swing.*; public class Jtextareatest { public static
package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
package mp1similar; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.StringTokenizer;
package mp1similar; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.StringTokenizer;
package database; import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import database.Dbconnect; public class
package employee; import employee.nidhin.staples; import java.util.*; import java.io.*; public class Employee { public static
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
package com.test.methods; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException;
package javaapplication1; import java.io.*; /** * * @author simon */ public class Main {
package pkgPeople; import java.io.Serializable; import java.text.DecimalFormat; public class Person implements Serializable{ private String name;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.