Results 1 to 6 of 6
  1. #1
    sujskiz is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Talking Why is my java program giving this error??

    So i'm new to java and i'm having a bit of problem with my code when i try converting char to char[] array it gives me this error:
    The constructor example(char[]) is undefined

    Here is the main code:
    Java Code:
    read = new Scanner(new BufferedReader(new FileReader("Example.txt")));
    while (read.hasNext())
    	            {
    	               String str = read.next(); 
    	                char[] myChar = str.toCharArray();
    	                example arrayChar = new Dexmaple(myChar);
    	                
    	           }
    and my example class:
    Java Code:
    private char[] reading = new char[20];
     public example(char myChar)
    	   
    	  {
    		  for(int i = 0; i < reading.length; i++)
    		  {
    		         this.reading[i] = myChar;
    		  }
    	  }
    Can someone help me with it??

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,411
    Rep Power
    5

    Default Re: Why is my java program giving this error??

    You are not showing enough of your code for anyone to be able to properly help you. However, from what I see it looks like you are assigning myChar to each position in reading.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    sujskiz is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default Re: Why is my java program giving this error??

    Yeh thats exactly what i'm trying to do i want to read character by charcter from the file and put them into array to compare to another array i have set up
    Say fro example in my file i got this following info
    A T N D F G J P L
    S T N D R Y J I L
    and so on

    and my array which i'm comparing to
    private char[] correctAnswers = { 'A', 'T', 'N', 'D', 'F', 'Y', 'J', 'I', 'L' };

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,411
    Rep Power
    5

    Default Re: Why is my java program giving this error??

    But you need to show all of your code, including your class declarations, etc.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Why is my java program giving this error??

    Quote Originally Posted by jim829 View Post
    You are not showing enough of your code for anyone to be able to properly help you.
    Actually they have.

    The example class (should be Example) constructor has a single char parameter and yet they are attempting to pass a char array. Exactly what the error message says: no char array constructor found.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,411
    Rep Power
    5

    Default Re: Why is my java program giving this error??

    Ah! I was focusing on Dexmaple.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 3
    Last Post: 03-01-2013, 06:16 PM
  2. My code keeps giving me NullPointerException error
    By linx2001 in forum New To Java
    Replies: 4
    Last Post: 11-07-2012, 04:47 PM
  3. JavaCompiler giving an error WITHOUT ide
    By divs1210 in forum Advanced Java
    Replies: 9
    Last Post: 04-09-2011, 01:04 AM
  4. Java code giving error
    By alfarida in forum New To Java
    Replies: 3
    Last Post: 11-10-2010, 07:11 PM
  5. Replies: 1
    Last Post: 07-23-2010, 02:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •