Cannot cast from SOMETHING to SOMETHING (Error in 1.4) (Works in 1.6)

Our company have developed an accounting program, and it is already near completion.
We developed it with JavaBean and Eclipse in Windows Environment with JRE 1.6.0_05
When we tried to compile and run the program in our linux environment (Server) that runs on 1.4 , the casting error occured..
we have written a program to generate all casting errors that occurred in our project.
import java.math.*;
import java.util.*;
public class testnow {
     public static void main(String[] args){
          //Declare ALL Primitive!
          int TestINT = 150;
          Boolean TestBOOL = true;
          String TestSTR = "Streng" + "th";
          BigDecimal TestDCM = BigDecimal.valueOf(20);
          Date TestDATE = new Date();
          //Declare ALL Object
          Object TestINTObj = 150;
          Object TestSTRObj = "Strength";
          Object TestDCMObj = BigDecimal.valueOf(20);
          Object TestBOOLObj = true;
          Object TestDATEObj = new Date();
          if(TestINT == (Integer)TestINTObj){
               System.out.println("TEST Integer PASSED");
          if(TestSTR.equals((String)TestSTRObj)){
               System.out.println("TEST String PASSED");
          if(TestDCM.equals(TestDCMObj)){
               System.out.println("TEST Decimal PASSED");
          if(TestBOOL == (Boolean)TestBOOLObj){
               System.out.println("TEST Boolean PASSED");
          if(TestDATE.equals((Date)TestDATEObj)){
               System.out.println("TEST Date PASSED");
}the following is what happened when i run javac testnow.java
1. ERROR in testnow.java
(at line 6)
Integer TestINT = 150;
^^^^^^^
Type mismatch: cannot convert from int to Integer
2. ERROR in testnow.java
(at line 7)
Boolean TestBOOL = (Boolean)true;
^^^^^^^^^^^^^
Cannot cast from boolean to Boolean
3. ERROR in testnow.java
(at line 11)
Object TestINTObj = (Object)150;
^^^^^^^^^^^
Cannot cast from int to Object
4. ERROR in testnow.java
(at line 14)
Object TestBOOLObj = true;
^^^^^^^^^^^
Type mismatch: cannot convert from boolean to Object
4 problems (4 errors)
in our windows development JRE 1.6 , it run well and gives the following output :
TEST Integer PASSED
TEST String PASSED
TEST Decimal PASSED
TEST Boolean PASSED
TEST Date PASSED
how do we solve this? i mean we have been using this "convenience" casting all over our code . :(
please help
thanks a lot.
Cheers and God Bless,
Chowi

You've got a lot of problems there, and not all of them are due to Java version incompatibilites. I'll take them in the order I see them. public static Object FindDataInTable(ArrayList TargetTable, String TypeColumn,
         String TargetColumn, Object TargetData, String ReturnedColumn){ The convention is to give methods and variables names that start with lowercase letters. That makes your code easier to read, which makes it easier for us to help you. Later on, I see you also use a mix of underscores and camelcase. Underscores should be used only in constant names; class, method and variable names should use only camelcase.
Also, if you don't have a good reason to make that first argument an ArrayList, you should declare it as a List instead. That leaves the calling code the option of using a different List implementation should they need to.
Next, you assign a primitive value to an Object reference: Object ReturnedObject = 0; That requires autoboxing, as others have pointed out, which didn't exist in JDK 1.4. Even if you could use autoboxing though, that assignment would be a bad idea; a variable of type Object should be assigned a default value of {color:000080}null{color}, not a number. However, you may not need to declare that variable at all, as I explain later.
Next you use a "foreach" loop, another feature that was added in JDK 1.5; you'll have to switch to the old-style loop if you want this code to work under JDK 1.4. While you're at it, you should declare your "SingleRow" variable inside the loop, since it's not used anywhere else: for (Iterator it = TargetTable.iterator(); it.hasNext(); ) {
    Model_DatabaseQuery SingleRow = (Model_DatabaseQuery)it.next(); Next I see you using matches() to compare String values: if(TypeColumn.matches("String")){
    if(((String)TargetData).matches((String)CheckData)){ You get away with that because the strings contain only letters, but you need to look up the docs for matches() so you'll understand why you shoudn't be using it here. But this is nothing compared to the next issue: if((Integer)TargetData == (Integer)CheckData){ // WRONG WRONG WRONG That can't possibly have worked right, no matter what version of Java you ran it under. You NEVER use == to compare the values objects! You should have been using equals() for all those comparisions, not matches(), and definitely not ==.
But I don't see why you're doing all those checks on the column type anyway. All you ever do after that is compare the same two values, so just do it: for (Iterator it = targetTable.iterator(); it.hasNext(); ) {
    Model_DatabaseQuery SingleRow = (Model_DatabaseQuery)it.next();
    Object CheckData = SingleRow.Get_object(TargetColumn);
    if (CheckData != null && CheckData.equals(TargetData)) {
        return SingleRow.Get_object(ReturnedColumn);
} If there are other columns that you're supposed to ignore, you may still need to check the column type, but you could do that in one {color:000080}if{color} statement; you don't have to check them all separately.

Similar Messages

  • Photoshop suddenly does not print to Epson 3880 - PROBLEM: Cannot print from Photoshop  After restart error message appears:  - "There was an error opening your printer. Printing functions will not be available until you have selected a printer and reopen

    PROBLEM: Cannot print from Photoshop
    After restart error message appears:
    — “There was an error opening your printer. Printing functions will not be available until you have selected a printer and reopened any documents.”
    • All print commands are greyed out and unavailable — even to call up the printer commands cannot be done.
    The printer printed fine until about 2 weeks ago when this error message appeared.  Printing continues from Pages, I-photo, preview etc. —  only Photoshop fails.
    The printer has been turned on and off, as have open documents been closed and open etc..   Preferences reset.  Repeatedly I have read through blogs and forums and attempted to contact Adobe — all without results
    Epson support struggled to find reason and several solutions were tried and they assume this is an Adobe problem.
    Running Mac Powerbook X 10.10.2 / Photoshop CS6 13.0.6.x64
    Attempting unsuccessfully to print to Epson 3880
    What Adobe support will be of help.
    Robert Darling —  2/19, 20, 21,22,23/2015

    Probably best to ask in Photoshop General Discussion
    This forum is about the Cloud as a delivery process, not about using individual programs
    If you start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • Navigation Cannot Start from this location. ERROR ...

    Navigation used to work fine on my X6, but since having to do a hard reset of the phone (due to other problems!) I cannot use the Navigation.
    Everytime I get the error 'navigation cannot start at this location' and it doesn't seem like the phone can ever pick up my location.
    I have tried un-installing and re-installing the application but to no-avail!
    I haven't even wasted my time calling Nokia Support, as they are totally useless!
    Does anyone have any ideas on how to fix this please?
    I am gutted, my phone used to be amazing, now it seems as soon as I resolve one issue, there becomes another!!

    After a huge update of my maps 3.06 using wifi direct to my N8 anytime I tried using destination on my phone only to get an error message "car navigation cannot start from this location". It didn't matter where I wanted to go to I got the same message. I use navigation more than any other app on my phone even phoning and texting and this is why I stay with Nokia so to loose my navigation would be a diaster. I googled the problem and found some tips to delete "cities" and any map files I could find but to no avail. I did a hard reset but stillI couldn't navigate and  in OVI Store Installed Apps I could see Ovi maps and navigation 3.6 and also 3.08. I googled how to delete Ovi Suite Installed apps and got the tip to install Nokia Suite 7.1 which I did and deleted every file with map in i's namet . I was left with a file maps 3.08 4kb in size which couldn't be deleted but I continued and installed Maps 3.06 again and after a little fine tuning I can now navigate with data turned off again. Yahoooeeeeee

  • Cannot print from Firefox - 'an unknown error has occurred'

    Whenever I attempt to print from Firefox, I get 'an unknown error occurred while printing'. This is after I choose my printing preferences and hit OK.
    I have tried resetting the printer options in about:config, reinstalling Firefox completely, and removing the printer-reboot-let Windows reinstall. Same error no matter what.
    I have Windows 7 Home 64bit
    Printer is HP D110

    I have the same error on both iPad & iPhone when connection is made but seems to sync when I manually sync.

  • Cannot boot from OSX DVD - ACPI error

    I am unable to boot from my OSX installation DVD. While booting I receive the following message:
    Panic (cpu 0 caller 0x003A934F) Unable to find driver for this platform: ACPI.
    I have tried re-installing the combo updater and flashing the PRAM, without any success.
    Can anyone PLEASE HELP? My hard drive needs repair and I must boot from DVD in order to gain access to make the repairs with the Disk Utility.
    Much thanks!

    Will it run the Extended Tests from Apple Hardware Test (Boot while holding "D")?
    If it won't boot from the install disk, it is not a problem with any software on your hard drive. It has to be a hardware problem; probably the DVD drive, since OSX is mostly working. If you have another Mac that can read DVDs and has FireWire, put the DVD in that Mac and boot it in Target Disk Mode (hold "T" while booting. Connect it to the Mac Pro with a FireWire cable, and boot the Mac Pro while holding Option. If the DVD shows up, select it and click the straight, right-pointing, arrow.
    If that doesn't work, try booting the Mac Pro in Target Disk Mode (Boot while pressing "T"), connect it to another Mac via FireWire, and try to repair the Mac Pro disk with Disk Utility (Tiger version), or Disk Warrior (version 4 or later).

  • HT3275 I cannot restore from Time Machine. Error 8003.

    This is what happened in sequence:
    • I had problems with Microsoftt Word. I checked the disk utilities and got a message saying that I needed to reformat the disk. I erased the disk and reinstalled Lion.
    * I restored all my files from my external disk using Time Machine, and all the files seemed to be restored without any problem, but they didn't appear on my hard disk. Time Machine was trying to backup while I was restoring the disk, and I wonder if this could have affected things.
    • I tried to back up again, but the files in Time Machine were grayed out. I opeed a new finder window and pressed Command + shift + C, and I could see the old back up files. I tried again, but got an errror -8003 message after a while.
    " I checked the external disk with disk utility and it appears to be OK. My hard disk is also OK.
    * I tried going into Time Machine and restoring a few of the applications to my hard disk. I got a message saying they are already on my hard disk (so perhaps the first restore did work after all), but I can't see them anyway. I also got a message saying that the applications on the back up disk were locked.
    My life is on the files backed up in Time Machine. I would be grateful for any help or advice.

    I could solve the problem by restoring everything manually from my back up disk. I still have some issues, but at least all my files are safe.

  • Cannot boot from Windows 8 notebook - Error: Operating system version is incompatible with Startup Repair

    Hi all,
    I have searched through forums, but could not find the solution to my problem:
    I have a notebook ASUS with Windows 8 preinstalled.
    Yesterday I was doing some housecleaning jobs with some freeware tool (don't remember the name).
    Afterwards I have not been able to boot into Windows.
    CURRENT SITUATION: When I switch the PC on, after the welcome screen of ASUS and Windows 8 the system goes to a blank screen (no cursor, no mouse, CTRL+ALT+DEL not working).
    On next reboot, it does not start automatically the Recovery/Repair procedure and goes through the same steps again. It's not a loop, it just hangs.
    Looking into c:\windows\system32\LogFiles\Srt\srttrail.txt I see the following error message at the bottom of the file on the time of my last boot attempt: "Operating system version is incompatible with Startup Repair"
    I tried several things without success, so now I want to solve the problems one by one and first thing is to understand what might be causing the "Operating system version is incompatible with Startup Repair" error and how it can be solved.
    Thanks for reading

    Hi,
    Any update here?
    I agreed with the others.  First, if we have any backup available to restore Windows 8.1, we may take use of that.
    If we don't have any backup available, we'd better contact the manufacturer side for a deeper help.
    Or as Janek Fehn suggested, make a clean install of Windows 8, then update to Windows 8.1 again.
    Best regards
    Michael Shao
    TechNet Community Support

  • Cannot print from internet - gives unknown error message. Disabled add on and restarted still has the problem. What do I need to do?

    Version 6.01. Windows vista home premium and windows xp (both dell laptops) The one with vista is primary and the windows XP laptop is connected wirelessly both internet and printer.

    Version 6.01. Windows vista home premium and windows xp (both dell laptops) The one with vista is primary and the windows XP laptop is connected wirelessly both internet and printer.

  • I've tried all the suggestions from previous posts about error 2002f and none work for me. I am selling my macbook air so erased the drive. When I select my wireless connection the globe turns then gives me the mentioned error. Nothing seems to work. Help

    Tried changing wpa options and having no security but that doesn't work. I have talk talk fibre so connection speed no issues.  I have an external HD with back up on but I don't think that has anything on to help me here.

    Tried changing wpa options and having no security but that doesn't work. I have talk talk fibre so connection speed no issues.  I have an external HD with back up on but I don't think that has anything on to help me here.

  • Cannot cast boolean to BigDicemal??

    i am new in reporting
    i am using iReport 3.0...
    i want to show my line in report if a field value is greater than 5000
    my field type is BigDecimal
    i wrote formula as
    (($F{AvgAmount}.intValue() >= 5000 )? true : false )
    when i check expression result is Expression successfully validated.
    when i Run report error accour
    Errors compiling .\BranchWiseAverage.jasper.
    net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. Cannot cast from boolean to BigDecimal                 value = (java.math.BigDecimal)(((((java.math.BigDecimal)field_AvgAmount.getValue()).intValue() >= 5000 )? true : false ));//$JR_EXPR_ID=14$                         <---------------------------------------------------------------------------------------------------------------> 2. Cannot cast from boolean to BigDecimal                 value = (java.math.BigDecimal)(((((java.math.BigDecimal)field_AvgAmount.getOldValue()).intValue() >= 5000 )? true : false ));//$JR_EXPR_ID=14$                         <------------------------------------------------------------------------------------------------------------------> 3. Cannot cast from boolean to BigDecimal                 value = (java.math.BigDecimal)(((((java.math.BigDecimal)field_AvgAmount.getValue()).intValue() >= 5000 )? true : false ));//$JR_EXPR_ID=14$                         <---------------------------------------------------------------------------------------------------------------> 3 errors      at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:193)     at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:591)     at java.lang.Thread.run(Unknown Source)
    Compilation running time: 328
    how can i remove this error.
    thanks

    Hi Les,
    where there is a will, there is a script:
    Get-ADUser -Filter * -SearchBase "OU=Departments,dc=contoso,dc=com" -Properties * | select Name, @{ n = "Enabled"; e = { [int]$_.Enabled } }, Canon* | export-csv departments.csv
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • IdeaCenter A310, Cannot boot from CD – Code 5

    Installed a developers/trial version of Windows 8 on my A310, only it appears to have somehow completely removed my recovery partition.
    Now I have no working OS on the computer and when I attempt to boot with a Windows 7 CD to reinstall I get a 'Cannot boot from CD – Code 5' error.
    Why won't it boot from the CD? How can I reinstall Windows? Pleaseee help.

    Hi ToxicVoices and welcome to the forum,
    If you hit F12 at the bios splash screen, it should bring up a list of bootable devices. Does the cd drive show up there?
    If you hit F11, it should take you into the recovery environment if the recovery partition is still there.  If the recovery is still there, you should be able to restore from a backup up, (if you made a backup).  If no backup, you would have to restore to factory settings.
    Dave 
    T430u, x301, x200T, x61T, x61, x32, x41T, x40, U160, ThinkPad Tablet 1838-22R, Z500 touch, Yoga Tab 2 Windows 8.1, Yoga Tablet 3 Pro
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"!
    If someone helped you today, pay it forward. Help Someone Else!
    English Community   Deutsche Community   Comunidad en Español   Русскоязычное Сообщество

  • BootCamp cannot load from disk code 5

    I tried to install Windows 7 using BootCamp from an ISO image DVD I made. Now when I restart my iMac, it takes me to a black screen with the "cannot load from disk code: 5" error message. The "option key" and "eject key" don't work at all and no matter how many times I restart it, it always goes back to this screen where I can't seem to press anything and the dvd is stuck. Please help.

    I burned my disc at 2 speed in Toast. Burned my XP iso like this too, and that worked (not on early 2011 mbp's)
    I even deleted the bootcamp partition and resized the osx partition to the max. That way i have a clean partition/install each time i trie. Used partition size is standard (20gb) so that shouldn't be an issue. And the iso i'm using for win7 is being used by al lot of others and they seem to have no problems and claim it to be a bootable disk.
    The only probable solution i've found is a workaround in which you launch your install from a different running OS, and go from there. However i'm not such a windows fan i got a full working pc. Just my mbp's so this really isn't an option and it seems a bit far off because i got a concrete error code.
    I'll try to get a copy of parallels to test my iso, but i don't want to emulate, i just need boot camp to work!

  • My Canon MP620 appears to be connected, yet every time I try to print something, it says error.  I have tried to unplug and track the error, but I cannot figure out why. Please help! this is such an inconvenience!

    My Canon MP620 appears to be connected, yet every time I try to print something, it says error.  I have tried to unplug and track the error, but I cannot figure out why. Please help! this is such an inconvenience!

    What Mac model? What Mac OS version?
    FYI, this forum is for Apple hardware made before 1999.

  • I am having this error coming out everytime I import an XML from woowave sync,something like I haven

    I am having this error coming out everytime I import an XML from woowave sync,something like I haven't got the right presets installed. It did work on another machine though, so I was wondering whats wrong with my Premiere CS6 install? Should I reinstall Premiere or Windows. I am in the middle of doing something.
    thanks you
    regards
    Tina

    This might sound weird, but here's an idea which worked for me re music that was newly added to itunes and showed up in my ipod but wouldn't play - I simply played the tracks in itunes first, just a second of time or so will do it, not the whole track, then connect the ipod and sync again and this time they played - hope this helps.

  • I cannot print from firefox. I can print from open office. It seems to have something to do with when frames open because in IE, I can print a whole page, but when I try to use a print button embeded in a page or frame it does not work.

    Cannot print from firefox at all.
    In Internet Explorer, I was able to print by pushing the print button, but when opening a frame, like in mapquest, the embedded print button brings up an options window that has print frames options in it, but when hit OK in this box, a second error box comes up with a yellow exclamation point and nothing prints. I have a feeling that it is the same problem with both browsers, but would prefer using firefox. Can you help with this?

      Yes, I tried that.   The files were ordered by their original numbers as imported from the camera, but I batched them through Phocoshop to downsize all of them into a more manageable file size.   I opened that destination folder from quick time  from where it said select image sequence.   I clicked on the first one and opened it.   The result was a large image with an arrow indicating a movie was ready to go.   When I pressed the arrow, though, I realized it had only imported that one frame so there was no movie.   The files are Jpgs and are about 450 KB each. 
        To your knowledge are there any links to iMovie tutorials or quick time tutorials that may address this situation?  Maybe there will be one I haven't looked at yet. 
        Thanks

Maybe you are looking for