Error: incompatible types: Object cannot be converted to char

Sam Ghanem

I've implemented a method to reverse a String using stack as ArrayList, but an error says error: incompatible types: Object cannot be converted to char. How can I fix it?

Here is the stack class:

public static class stackl extends ArrayList {
    public boolean isEmptyS() {
        return isEmpty();
    }

    public void push(Object el) {
        add(0, el);
    }

    public Object pop() {
        return remove(0);
    }
}

And here is my method:

public static void reverse(String s) {
    stackl s1 = new stackl();
    for (int j = 0; j < s.length(); j++) {
        char ch = s.charAt(j);
        s1.push(ch);
    }

    while (!s1.isEmpty()) {
        char ch = s1.pop();
        System.out.println(ch);
    }
}
Peter Lawrey

You can convert a char to a Character with auto-boxing. Try

Character ch = s.charAt(j);

Also, it would make sense to have a generic stack just like the built in Stack (have a look at the code for Stack as an example)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error: incompatible types: Object cannot be converted to char

From Dev

error: incompatible types: Object cannot be converted to MyClass

From Dev

Error:(28, 58) error: incompatible types: Object cannot be converted to Address

From Dev

incompatible types: char[] cannot be converted to CharSequence

From Dev

Incompatible types: Object cannot be converted to ParseObject

From Dev

incompatible types: Object cannot be converted to CoreLabel

From Dev

Error: incompatible types: double cannot be converted to JTextField

From Dev

error: incompatible types: MainFragment cannot be converted to Activity

From Dev

error: incompatible types: int[][] cannot be converted to int

From Dev

Error:(124, 62) error: incompatible types: Class cannot be converted to Context

From Dev

Java: toString error "error: incompatible types: int cannot be converted to String"

From Dev

Why am I getting, "incompatible types: Object cannot be converted to String" with this?

From Dev

JAVA incompatible types: Object cannot be converted to my type

From Dev

incompatible types object cannot be converted to t where t is a type variable

From Java

error: incompatible types: <anonymous Callback<List<UserDataResponse>>> cannot be converted to OnNoteListener

From Dev

app setBackground() error: incompatible types: int cannot be converted to Drawable

From Dev

JAVAFX error incompatible types: FXMLLoader cannot be converted to node

From Dev

error: incompatible types: NewsLoader cannot be converted to Loader<List<News>>

From Dev

How to fix the error: incompatible types: MenuFragment cannot be converted to Fragment in android?

From Dev

Android Studio: error: incompatible types: MainActivity cannot be converted to Application

From Dev

I'm coding part of an RPG game and there's an error saying "incompatible types: char cannot be converted into boolean" (java, bluej)

From Dev

incompatible types: Node cannot be converted to Tab

From Java

incompatible types: int cannot be converted to T

From Java

Java incompatible types: int cannot be converted to int[]

From Dev

incompatible types: HomeFragment cannot be converted to Fragment in Android

From Java

Java : incompatible types; int cannot be converted to string

From Dev

Incompatible types: Fragment cannot be converted to NavigationDrawerFragment

From Dev

incompatible types: void cannot be converted to int

From Dev

incompatible types: BigInteger cannot be converted to int

Related Related

  1. 1

    Error: incompatible types: Object cannot be converted to char

  2. 2

    error: incompatible types: Object cannot be converted to MyClass

  3. 3

    Error:(28, 58) error: incompatible types: Object cannot be converted to Address

  4. 4

    incompatible types: char[] cannot be converted to CharSequence

  5. 5

    Incompatible types: Object cannot be converted to ParseObject

  6. 6

    incompatible types: Object cannot be converted to CoreLabel

  7. 7

    Error: incompatible types: double cannot be converted to JTextField

  8. 8

    error: incompatible types: MainFragment cannot be converted to Activity

  9. 9

    error: incompatible types: int[][] cannot be converted to int

  10. 10

    Error:(124, 62) error: incompatible types: Class cannot be converted to Context

  11. 11

    Java: toString error "error: incompatible types: int cannot be converted to String"

  12. 12

    Why am I getting, "incompatible types: Object cannot be converted to String" with this?

  13. 13

    JAVA incompatible types: Object cannot be converted to my type

  14. 14

    incompatible types object cannot be converted to t where t is a type variable

  15. 15

    error: incompatible types: <anonymous Callback<List<UserDataResponse>>> cannot be converted to OnNoteListener

  16. 16

    app setBackground() error: incompatible types: int cannot be converted to Drawable

  17. 17

    JAVAFX error incompatible types: FXMLLoader cannot be converted to node

  18. 18

    error: incompatible types: NewsLoader cannot be converted to Loader<List<News>>

  19. 19

    How to fix the error: incompatible types: MenuFragment cannot be converted to Fragment in android?

  20. 20

    Android Studio: error: incompatible types: MainActivity cannot be converted to Application

  21. 21

    I'm coding part of an RPG game and there's an error saying "incompatible types: char cannot be converted into boolean" (java, bluej)

  22. 22

    incompatible types: Node cannot be converted to Tab

  23. 23

    incompatible types: int cannot be converted to T

  24. 24

    Java incompatible types: int cannot be converted to int[]

  25. 25

    incompatible types: HomeFragment cannot be converted to Fragment in Android

  26. 26

    Java : incompatible types; int cannot be converted to string

  27. 27

    Incompatible types: Fragment cannot be converted to NavigationDrawerFragment

  28. 28

    incompatible types: void cannot be converted to int

  29. 29

    incompatible types: BigInteger cannot be converted to int

HotTag

Archive