problem « cast « Java Data Type Q&A

1. Java Custom ListCellRenderer casting problem (SSCCE included)

I am trying to create a custom ListCellRenderer in order to give different foreground colors in each line, depending on the input of the jList. I am not an expert or ...

2. Probably a casting problem - Java

I wrote the following code:

public class Point2
    private double _radius , _alpha;    

    public Point2 ( int x , int y )

3. Problem understanding a casting issue

Can someone explain to me how the two lines under the comment are compilable?

A a = new A();
B b = new B();
C C = new C();

// How can these work?
((G) a).methodG(a);
((B) ...

4. Casting Problem

Hello, I am new to this forum and sorta new to Java programming. Here is my problem. I have a piece of Lotus script that I am basically converting to Java line by line. Probably not best practice I know. Question when I try to cast a character to an integer I get errors and I cannot find the correct way ...

5. casting problem

Because it is not possible to cast Object directly to a primitive such as int or char. Prior to Java 5.0, it wasn't possible at all. Now however, you can using auto(un)boxing, just as long as you do the right casting: ch = (Character)st.pop(); How this works: 1) The object is retrieved from the pop() method. 2) It is cast to ...

6. Casting Problem *Help Please

7. Problem with casting

Are there different rules for casting for different types of operators(like assignment and compound operators) I mean when byte b=1; long l=1000; b=(byte)l; //compiler asks for casting here. And when byte b=1; long l=1000; b+=l; //which is b=b+l,and the result of b+l here is long,then why doesn't compiler ask for casting when assigning to long to byte as above exmaple.And will ...

8. Casting problem. Image to BufferedImage

RenderedImage rendImage = myCreateImage(); // Write generated image to a file try { // Save as JPEG file = new File("newimage.jpg"); ImageIO.write(rendImage, "jpg", file); } catch (IOException e) { } // Returns a generated image. public RenderedImage myCreateImage() { int width = 384; int height = 288; // Create a buffered image in which to draw BufferedImage bufferedImage = new BufferedImage(width, ...

9. Casting problem

10. Problems with Casting

Hello Everyone, This question is most likely very entry level to most of you, but I'm new to programming. Please bare with me. I have an application that passes data from an Array into a Vector, a LinkedList and an ArrayList. Iam having problems display the data in the Collections. Instead of seeing the values in the collections I see what ...

11. casting problem

Hello all I have the below casting problem in my servlet program for stock trading system: "java.lang.ClassCastException: trade.equity.XXXEquity cannot be cast to java.lang.Comparable" The XXXEquity is a subclass of Equity, code looks like: class Equity implements, java..util.Comparator{ public int compare(Object o1, Object o2) { int status = 0; if(o1 instanceof Equity && o2 instanceof Equity) { Equity e1 = (Equity) ...

12. Casting problem

class Ab { private int x; } public class Bc extends Ab { private int z; protected Bc(int z) { this.z=z; } public static void main(String[] args) { Ab a=new Bc(4); System.out.println((Bc)a.z);/*why this line gives the compiler error of cannot find symbol?*/ Bc b=(Bc)a; System.out.println(b.z);//while this one compiles fine??please clear my doubt... } }

13. Casting problem

Hi All, I am unable to understand a very simple casting conversion of classes. Please help me clear my concept.!!! Here is the code. ------------- public class Employee { private String name; private double salary; public Employee(String n, double s){ name = n; salary = s; } public String getName() { return name; } public void setName(String name) { ...

14. Cast problem

Heh, that was my exact same question the first time I messed with Iterators. In a regular for loop you are allowed to modify your iterator any way you'd like but when iterating over a collection using an Iterator you must not change the structure of the collection as Henry already stated.

15. Casting Problem

16. Casting Problems

You can't cast to it at Compile time if I am understanding your question correctly. When using Reflection, you are essentially giving up compile-time type checking and all the conveniences that come with it in order to gain the ability to "dynamically cast" as people seem to always describe it. Read up on Reflection and examine some coding examples. Reflection is ...

17. Casting problem

public class SudokuBoard { private ArrayList[][] initialBoard, board; protected final static int ROW = 9, COLUMN = 9; public final static int EMPTY = 0; public SudokuBoard() { initialBoard = new ArrayList[ROW][COLUMN]; board = new ArrayList[ROW][COLUMN]; for (int y = 0; y < board.length; y++) for (int x = 0; x < board[y].length; x++) { ArrayList cellInitial = new ArrayList(); ArrayList ...

18. Problem with my cast

19. Casting problem

Hi every body, I am getting following exception while running the following code. I checked it and casted it carefully, but I do not know why it is displaying the error double diffperc1=diff/previousPrice*100; diffperc1=Math.abs(diffperc1); if (diffperc1 >= 25){ NumberFormat formatter=new DecimalFormat("0.##"); String stringdiffperc=formatter.format(diffperc1); double diffperc=Double.parseDouble(stringdiffperc); } And the error is as java.lang.NumberFormatException: For input string: "25,89" at java.lang.NumberFormatException.forInputString( at java.lang.FloatingDecimal.readJavaFormatString( at ...

21. Problem With Casting

First, way too much code. In the future, please trim it down to just what it necessary to demonstrate the problem, even if that means creating a small program from scratch--an [SSCCE|]. Arindam_Choudhury wrote: D:\working>javac -g list/*.java list\ cannot find symbol symbol : variable lock location: class list.DListNode node.lock = true; ^ 1 error but when i try ((LockDListNode)node).lock = true, ...

22. casting problem

(Integer)seq[2]==0 I'm trying to use this in an if statement. The value of seq[2] is 1 but I can't figure out how to get it to work. seq is an Object[] seq[2]==0 Incompatible operand types Object and int (Integer)seq[2]==0 ClassCastException: Cannot cast "1" to java.lang.Integer (int)seq[2]==0 Cannot cast from Object to int What is the proper way to do this?

23. Casting problem

24. Casting Problem

25. Casting Problem

26. casting problem

27. Problem with Casting

28. casting problems

29. casting problem

Hello, I want to cast an object into a subclass and use a method from this object. This is part of the code so you can see what i'm trying to do. Controller c = Mediator.getMediator().getController(); (c.getClass() c).method(); I know that there is a cast(Object obj) method in for Class, but I don't see how to use it here.

30. Casting problem

Maybe I am wrong but I don't understand your code as in why did you do it this way: 1. The Bookmark class creates a JTree and adds a selection listener which is the TreeController. Why do you then have the createNodes() function in TreeController ? I think the TreeControlloer class should override valueChanged() and everything else should be in Bookmark ...