Arrary.equal(charAt) cannot be found

charat cannot be dereferenced
charat (java)
char to string
character equals java
s charat i - 'a
java cannot be dereferenced
char cannot be dereferenced equalsignorecase
char cannot be dereferenced compareto

I am coding a program that searches for a specific character and displays it's position as soon as it is found in a string, which is input by the user. I've tried changing the syntax around on line where the error is popping up, but the same error continues to occur. I am very new to coding so I would really appreciate the help!!

import java.util.Scanner;

public class Lab10
{
   public static String character;
   public static String input;
   public static int position;
   public static StringBuilder str = new StringBuilder(input);


      public static void main(String[] args)
      {         
         Scanner keyboard = new Scanner(System.in);

         System.out.print("Enter a string: ");
         input = keyboard.nextLine();

         System.out.print("Enter a character: ");
         character = keyboard.nextLine();

         System.out.println(" ");

         getPosition();

         System.out.print("The position of the first '" +   character +"' found is" + position);        
       }

     public static int getPosition()
     {
        for (position = 0; position <= str.length(); position++)
        {  
            char charAt = str.charAt(position);

            if (character.equals(charAt))
            {
               return position;
            }
            else
            {
               position++;
            }      
         }
         return position;
     }

}

Thank you everyone for pointing out my syntax error. It compiled just fine after I fixed the error, BUT, a whole other error came up when I tried compiling it in the terminal/cmd

Exception in thread "main" java.lang.ExceptionInInitializerError Caused     by: java.lang.NullPointerException  at java.lang.S

its equals() my friend :D ,i've been throw many similar issues xD.

would recommend using intellij ide to avoid syntax errors.

charAt().equals() causes "char cannot be dereferenced", If you use something like this, it will work: if (raw.charAt(3) == '-' && raw.charAt(7) == '-') { System.out.println("2 Hyphens at 3 and 7"); } else if (raw.charAt(3)  A char is a primitive; a Character (or indeed a String) is an object, and therefore a reference type. You use '==' with primitives and .equals() with objects. String.charAt() returns a char , so the message was telling you that .equals() is not appropriate.

This should be character.equals(charAt)) not character.equal(charAt))and you need to compare String with a String not Char with a String.

charAt equals element of array, Like to check whether some character equals some character out of an array I defined. charAt(verb.length()-1) is a char and you could write a method that checks are you trying to find out if a string contains a vowel? better, but being a beginner to java, I cannot really understand everything about it). Given two given arrays of equal length, the task is to find if given arrays are equal or not. Two arrays are said to be equal if both of them contain same set of elements, arrangements (or permutation) of elements may be different though. Note : If there are repetitions, then counts of repeated elements must also be same for two array to be equal.

For comparing two characters it is better to use == because equals method is used for strings and objects.

 if (character == charAt){
     return position;
 }

charAt is not a function Error - JavaScript, Unfortunately, charAt() only works on strings and not arrays, so you could reference (not equal) and && (logical operator AND) for my if statement condition. This method returns the character located at the String's specified index. The string indexes start from zero. Syntax. Here is the syntax of this method − public char charAt(int index) Parameters. Here is the detail of parameters − index − Index of the character to be returned. Return Value. This method returns a char at the specified

Java.lang.String.charAt() Method, An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing. Declaration. Java String Array Examples. Oct 14, 2015 Array, Core Java, Examples, Snippet, String comments A Java String Array is an object that holds a fixed number of String values. Arrays in general is a very useful and important data structure that can help solve many types of problems.

String.prototype.charAt(), The String object's charAt() method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string. If the index cannot be converted to the integer or no index is provided, the default is current iteration and returning an array with the individual character // and 'i'  A string representing the character (exactly one UTF-16 code unit) at the specified index. If index is out of range, charAt() returns an empty string. Description. Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character—in a string called stringName—is stringName

Java String charAt() method with example, The Java String charAt() method returns the character at the specified index. Please Improve this article if you find anything incorrect by clicking on the  Two separate arrays/objects that look the same are not compared by value. To make it clearer; only the primitive values can be compared for equality - i.e. boolean, string, number. The special values null and undefined also act this way.

Comments
  • It is equals and not equal.
  • A String will never equal a char. Exactly what is the code intended to do?
  • I've never heard of intelliji. What exactly is it?
  • its an awesome ide for jave development .fast , responsive and shipped with the best suggestions for bug fixes and variable naming, you can get it from the official website for free at jetbrains.com/idea/download
  • thank you so much for the suggestion! Would you know how i could fix the most recent error that i added to my question? This is the second time an error has popped up in my terminal and not when compiling :(
  • actually one advantage of using IDE is error report that shows you the line on which you have the error , just look at the debugging log ,or even more , try adding breakpoints to your code blocks and trace the execution flow line by line to know exactly how your code is complied and where the error might be
  • I'm trying to see where there could be some more discrepancies, but I'm not sure what an error relating to NullPointerException would be. I've hear of this error.