error « cast « Java Data Type Q&A





1. Compilation error: casting    stackoverflow.com

Can somebody explain me why the following piece of code fails to compile. The error is: "Possible loss of precision." :

byte a = 50;
byte b = 40;
byte sum = (byte)a + ...

2. Error when typecasting in java    stackoverflow.com

Hey guys, am trying to write to do type casting in java, but i keep getting

run: 
[(E,1), (H,1), (F,2), (G,2), (I,5), ( ,7)]
(H,1)
class datacompression.tuple
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot ...

3. Java: I get a class cast exception error pointing to class I didn't even import    stackoverflow.com

my problem is simple, I have the code I have written to first scale the image down and then crop to desired dimensions (obtained by the Constants class).

if(image != null){
  ...

4. error in casting    stackoverflow.com

public class xyArea{
public static void main(String arg[]){
  XYSeries series = new XYSeries("Average Weight");
  series.add(20.0, 20.0);
  series.add(40.0, 25.0);
  series.add(55.0, 50.0);
  series.add(70.0, 65.0);
  XYDataset xyDataset = new ...

5. Error when using Reflections in Java    stackoverflow.com

I'm having a casting issue in this code but have no idea how to correct it.

public void showFrame(String className, Object controller) throws Exception{
    try {
   ...

6. Why casting error?    coderanch.com

Hi ranchers, I am really confused by it.See below code: for (int i = 0; i < objects.length; i++) { Reflector r = new Reflector(objects[i]); Set interfaces = r.getInterfaces(); Iterator interfaceIter = interfaces.iterator(); while (interfaceIter.hasNext()) { //System.out.println(objectNames[i] + ":" + interfaceIter.next()); Class inter = (Class) interfaceIter.next(); I use debug to see where error happens and found that Class inter = (Class) ...

7. type casting error!    coderanch.com

if i change this code to class BasicMath { public static void main(String[] args) { Adder adder = new Adder(); byte y= adder.addAndReturn((byte)127,(byte)127); // arguments casted and passing to the function System.out.println("Added value is"+y); } } class Adder { byte addAndReturn(byte firstNum, byte secondNum){ byte t = (byte)(firstNum + secondNum);// -------------> this statement return (t); } } then why is it ...

8. casting List to a userdefined object doesn't give compile time error    coderanch.com

Please help me understand that while casting List to any user defined object (which doesnt falls in hierarchy of List even), why compiler doesn't reports a compiletime error? public class TestClassCast { public List getList(){ return new ArrayList(); } /** * */ public TestClassCast() { // TODO Auto-generated constructor stub } /** * @param args */ public static void main(String[] args) ...

9. Can't Figure out why I get the cast error in this program at line 39    coderanch.com

I keep getting this error. I don't understand why this is happening? I included the error with my println statements which work right up to the read... ANY help would be appreciate. I only have a few hairs left.. run: Writing to file !0 Writing to file !1 Writing to file !2 here! Packet created! Exception in thread "main" java.lang.ClassCastException: java.lang.String ...





10. Cast error    java-forums.org

import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;; public class formfillerbot { private String bUrl; public formfillerbot (String url) throws Exception { bUrl = url; } public void fill () throws Exception{ WebClient wb = new WebClient (); Page p = (HtmlPage) wb.getPage(bUrl); HtmlForm f = ((HtmlPage) p).getFormByName("xxxxxxxx"); HtmlRadioButtonInput r = f.getElementById("xxxxxxxxxx"); r.click(); HtmlSubmitInput s = (HtmlSubmitInput) ...

11. Error casting    java-forums.org

Hello Forum, I am retrieving records from myslq database to oracle database, in mysql, i have a date field and a time field for each record, in oracle i have a timestamp field, what i am doing is extracting the two mysql fields, then parsing to a java.util.Date and finally passing that to the destination database as a java.sql.date type. currently ...

12. class cast exception error    forums.oracle.com

13. Class cast exception error    forums.oracle.com

15. Casting error    forums.oracle.com