Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

    the program is suppost to compare the lines of one textbox individually to all the individual lines in another to try and find a match and if it finds a match it reports it in another textbox under Valid Nodes but if there is more than 1 it goes to a textbox under Duplicated Nodes with the amount of nodes and their line number and if it doesnt find a match then that to get reported in a seperate textbox under Unassigned Nodes and it does this for all of the lines of the first textbox.
    its designed for filtering permission nodes so that i dont have to spend hours going through and double checking plugin permission nodes every time i want to validate access permissions, in time plugins require me to add and alter permission nodes sdo after a while it can become a bit of a mess so i have to re-validate everything to make sure its still ok.

    The result im looking for is that any text that appears more than once in the script textbox should be shown in the duplicated nodes textbox with "x<times duplicated>, <script location for each>,", the f should be in the unnasigned nodes textbox and the rest should be in the valid nodea textbox
        private void btnStartMousePressed(java.awt.event.MouseEvent evt) {                                      
            // TODO add your handling code here:
            int[] TextCoOrds = {0,0,0,0}; //var save line location values     .
            String[] Temp = {"",""};//array for comparing selected text.
            String OutputY = "";//used to output the location on the script of the duplicated line.
            int DupCheck = 0;//stores duplication amount.
            String PrevY;//stores previous duplicate line number.
            prgProgress.setMaximum(txtInput.getLineCount());//sets the progress bar maximum to max lines in script.
            for(int x = 0;x < txtInput.getLineCount();x++){//start looping through input textbox.lines
                TextCoOrds[0] = 0;//set text selection astart location to 0.
                TextCoOrds[1] = txtInput.getText().length();//set text selection end location to the end of that line.
                txtInput.select(TextCoOrds[0], TextCoOrds[1]);//use the above values to select the text.
                Temp[0] = txtInput.getSelectedText();//store the selected text to the first portion of the temp array.
                for(int y = 0;y < txtScript1.getLineCount();y++){//start looping through script textbox lines
                    TextCoOrds[2] = 0;//set text selection a start location to 0.
                    TextCoOrds[3] = txtScript1.getText().length();//set text selection end location to the end of that line.
                    txtScript1.select(TextCoOrds[2], TextCoOrds[3]);//select text in line in script textbox using above values.
                    Temp[1] = txtScript1.getSelectedText();//save selected text to other part of array
                    if(Temp[0].equals(Temp[1])){//compare the two array values, if they match proceed.
                        DupCheck++;//increase dupcheck by 1;
                        if(DupCheck > 1){//if dupcheck is higher than 1(multiple duplications)
                            PrevY = String.valueOf(y);//store y as previous location       
                            txtDuplicated.setText(Temp[0] + " " + "x" + DupCheck + ", " + OutputY + y);//output in duplicate box the duplicated line with how many duoplicates and line locations.
                            OutputY = PrevY + y;//add location of y for next run.  
                    } else if(DupCheck < 1){//if dupcheck  is lower than 1 proceed.
                        txtUnnasigned.setText(Temp[0]);//add node to the unnassigned textbox.
                    } else if(DupCheck == 1){//if it is equal to 1.
                        txtValid.setText(Temp[0]);//add it to the valid textbox.
                    }
                    }
                }
                DupCheck = 0;//reset dupcheck
                prgProgress.setValue((txtInput.getLineCount()/100)*x);//validate progressbar to script progress
            }
        }

    its a null pointer exception but i dont know where in the line it is
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at com.mycompany.permissions_analyzer.Main.btnStartMousePressed(Main.java:231)
    	at com.mycompany.permissions_analyzer.Main$2.mousePressed(Main.java:85)
    	at java.desktop/java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:288)
    	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6633)
    	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    	at java.desktop/java.awt.Component.processEvent(Component.java:6401)
    	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
    	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
    	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4544)
    	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
    	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
    	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Last edited by FA_Nighthawk; April 21st, 2020 at 06:47 AM. Reason: Required Info Update

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

    What does the code do when it is executed? Can you post something that shows what the code currently does with comments showing what is wrong and what the desired results should be.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2020
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

    it wont let me attatch the zip file

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

    Why do you need to post a zip file?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2020
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

    so that you can work it out from the project itself

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

    Can you add some debugging code that prints out what the code does when it executes?
    Then copy that output and paste it here to show the problem.
    Add some comments describing what is wrong with that output and show what the desired output should be.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2020
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

    there

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Hi can sombody Help me with this code? i get no errors but it doesnt work so im stuck

    i dont know where in the line it is
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.mycompany.permissions_analyzer.Main.btnStartMo usePressed(Main.java:231)
    Look at the code on line 231 and find the variable with the null value. If you can not see what variable has the null value,
    add a print statement just before line 231 that prints the values of all the variables used on line 231.
    The print out will show you which variable has the null value.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    FA_Nighthawk (April 21st, 2020)

Similar Threads

  1. [SOLVED] My fleet of squares doesnt work (simple high school work)
    By macko939 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 20th, 2014, 02:56 PM
  2. no errors on japplet but it doesnt work!!!!
    By game06 in forum Java Theory & Questions
    Replies: 16
    Last Post: May 2nd, 2013, 09:20 AM
  3. Why doesnt my constructor work?
    By hairLess in forum What's Wrong With My Code?
    Replies: 13
    Last Post: July 25th, 2012, 11:38 AM
  4. HI, could someone please tell me why my code doesnt work?
    By joelmeler in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 3rd, 2011, 01:37 AM
  5. My program doesnt want to do its math point my errors out please
    By Redlight in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2010, 01:56 PM