Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. I NEED HELP URGENTLY!

I NEED HELP URGENTLY!

Scheduled Pinned Locked Moved Java
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matjaz xyz
    wrote on last edited by
    #1

    public static void IzbrisZivali(ArrayListSeznam) throws ConcurrentModificationException // brisanje zivali
    , IOException
    // IzbrisZivali je ime funkcije, (Arraylist - dinamicna tabela, Zivali - nase zivali, Seznam - uporabljala bom tole za iskanje mojega vnosa)
    {

    	BufferedReader vhod=new BufferedReader(new InputStreamReader(System.in)) ; // odpiranje bralnika
    	{
    		System.out.println("Vnesi točno ime živali, ki bi jo radi izbrisali: ");
    		String IzbrisZivali=vhod.readLine(); // preberemo ime
    		int v=0; // spremenljivka nam pomaga, ce se ne najde te zivali v nasem seznamu
    		
    		for(Zivali Element: Seznam) //za vsak element iz seznama
    
    			if(IzbrisZivali.equals(Element.getIme())) // ce je ime iskane zivali isto kot ime trenutne zivali v nasem seznamu...
    			{
    				
    				Seznam.remove(Element); // jo odstranimo iz nasega seznama zivali
    				System.out.println("Žival " + IzbrisZivali + " je bila izbrisana");
    				v++;
    				
    			}
    		
    		if(v==0) // ce ne najdemo zivali, to sporocimo
    		{
    			System.out.println();
    			System.out.println("Na seznamu ni živali z imenom " + IzbrisZivali);
    			System.out.println();
    		}
    	}
    }
    

    How can i fix that? What should be changed. Please solve me this problem as im sitting here and staring at my computer for 2 hours! Please! The problem is ConcurrentModificationException

    Regards, Matjaž

    C T 2 Replies Last reply
    0
    • M Matjaz xyz

      public static void IzbrisZivali(ArrayListSeznam) throws ConcurrentModificationException // brisanje zivali
      , IOException
      // IzbrisZivali je ime funkcije, (Arraylist - dinamicna tabela, Zivali - nase zivali, Seznam - uporabljala bom tole za iskanje mojega vnosa)
      {

      	BufferedReader vhod=new BufferedReader(new InputStreamReader(System.in)) ; // odpiranje bralnika
      	{
      		System.out.println("Vnesi točno ime živali, ki bi jo radi izbrisali: ");
      		String IzbrisZivali=vhod.readLine(); // preberemo ime
      		int v=0; // spremenljivka nam pomaga, ce se ne najde te zivali v nasem seznamu
      		
      		for(Zivali Element: Seznam) //za vsak element iz seznama
      
      			if(IzbrisZivali.equals(Element.getIme())) // ce je ime iskane zivali isto kot ime trenutne zivali v nasem seznamu...
      			{
      				
      				Seznam.remove(Element); // jo odstranimo iz nasega seznama zivali
      				System.out.println("Žival " + IzbrisZivali + " je bila izbrisana");
      				v++;
      				
      			}
      		
      		if(v==0) // ce ne najdemo zivali, to sporocimo
      		{
      			System.out.println();
      			System.out.println("Na seznamu ni živali z imenom " + IzbrisZivali);
      			System.out.println();
      		}
      	}
      }
      

      How can i fix that? What should be changed. Please solve me this problem as im sitting here and staring at my computer for 2 hours! Please! The problem is ConcurrentModificationException

      Regards, Matjaž

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      You can't iterate this way over your list (Seznam) while removing elements at the same time. Instead you should you use an iterator and call remove on the iterator:

      Iterator iter = Seznam.iterator();
      while (Seznam.hasNext()) {
      Zivali element = iter.next();
      ...
      ...
      if (.....) {
      iter.remove();
      }

      }

      BTW: this is a forum not a chat, so you can't request "URGENT HELP!". Your question is not more urgent than other questions. If it is really urgent, then you should pay somebody to fix the problem for you. And please, use a better title next time you ask a question, everybody knows that if you ask a question, you want some help... Please, read the posting guidelines at the top of this message board.

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • M Matjaz xyz

        public static void IzbrisZivali(ArrayListSeznam) throws ConcurrentModificationException // brisanje zivali
        , IOException
        // IzbrisZivali je ime funkcije, (Arraylist - dinamicna tabela, Zivali - nase zivali, Seznam - uporabljala bom tole za iskanje mojega vnosa)
        {

        	BufferedReader vhod=new BufferedReader(new InputStreamReader(System.in)) ; // odpiranje bralnika
        	{
        		System.out.println("Vnesi točno ime živali, ki bi jo radi izbrisali: ");
        		String IzbrisZivali=vhod.readLine(); // preberemo ime
        		int v=0; // spremenljivka nam pomaga, ce se ne najde te zivali v nasem seznamu
        		
        		for(Zivali Element: Seznam) //za vsak element iz seznama
        
        			if(IzbrisZivali.equals(Element.getIme())) // ce je ime iskane zivali isto kot ime trenutne zivali v nasem seznamu...
        			{
        				
        				Seznam.remove(Element); // jo odstranimo iz nasega seznama zivali
        				System.out.println("Žival " + IzbrisZivali + " je bila izbrisana");
        				v++;
        				
        			}
        		
        		if(v==0) // ce ne najdemo zivali, to sporocimo
        		{
        			System.out.println();
        			System.out.println("Na seznamu ni živali z imenom " + IzbrisZivali);
        			System.out.println();
        		}
        	}
        }
        

        How can i fix that? What should be changed. Please solve me this problem as im sitting here and staring at my computer for 2 hours! Please! The problem is ConcurrentModificationException

        Regards, Matjaž

        T Offline
        T Offline
        TorstenH
        wrote on last edited by
        #3

        This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible. For example, it is not generally permissible for one thread to modify a Collection while another thread is iterating over it. That's what the documentation says. You might figure out what happens when you make your function non-static. And please debug your code. - do not name variables with capital letter ("Element") That's really dangerous and can have side effects as Object names are started with a capital letter (e.g."System", "BufferedReader"). - always use English comments. regards Torsten

        I never finish anyth...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups