#Error reported: char cannot be dereferenced
##1. Error code
while(s.charAt(i).equals(" ")){
i++;
}
S is a string
## error reason
java: cannot dereference char
char is a basic data type and already a value. Here, the comparison value can be directly used = =.
##Solution 1
but the comparison here is “” (string space)
you can’t directly use the = = symbol
so replace charat() with substring()
substring() returns a string, so you can use equals()
while(s.substring(i,i+1).equals(" ")){
i++;
}
So the problem has been solved
##Solution 2
we can also compare it with ” (character space)
you can directly use the equal sign
while(s.charAt(i)==' '){
i++;
}
Read More:
- [Solved] Feign Call Port Error: HttpMessageNotReadableException:JSON parse error:Illegal character ((CTRL-CHAR, code 31)
- OpenFeign Error: {“code“:1,“msg“:“JSON parse error: Illegal character ((CTRL-CHAR, code 31))
- Java learning unreported exception java.io.IOException ; must be caught or declared to be thrown
- Java parsing xml file encounters special symbols & will be abnormal solutions
- [Solved] Java.util.linkedhashmap cannot be cast to entity class
- [Solved] Tesseract ocr error: JFIF APP0 must be first marker after SOI
- Java error prompt….. cannot be resolved
- [Solved] IDEA plug-in jrbel hot deployment cannot be started error
- [How to Solve]Repeated column in mapping for entity,should be mapped with insert=“false“ update=“false“
- Jtextfield cannot be displayed normally when added to JPanel
- [Solved] Mybatis insert Error: Cause: java.sql.SQLException: SQL String cannot be empty
- Tensorflow Error TypeError: Fetch argument XXXX has invalid typeXXXX,must be a string or Tensor
- [Solved] Idea Build error. The symbol — Lombok cannot be found
- [Solved] Annotation Customize Error: ElementType cannot be resolved to a variable
- [Solved] No validator could be found for constraint ‘javax.validation.constraints.NotBlank’ validating type ‘java.lang.String’
- [Solved] o2o Error: addShopImg error:null / character to be escaped is missing
- [Javac compilation exception] javac compilation prompts that the package in jdk cannot be found error: package jdk.internal.org.objectweb.asm does not exist and error: cannot find symbol
- The controller error: the XX method in the service cannot be found
- [Solved] The war package Error: The reason why the XSD file could not be found