ArrayList and double[]

private double[] findAverageFace(ResultSet rs, int rows){
        String path;
        Scanner scanner;
        int picn = 0;
        double[] avgFace = new double[rows * rows];
        try{
            //System.out.println("scanning the result set");
            double[] pic;
            while(rs.next()){
                path = rs.getString(1); //the path to the matrix
                //System.out.println("path: " +path);
                scanner = new Scanner (new File(path));
                pic = new double[rows * rows];
                for(int i=0; i<rows*rows; i++){
                    pic[i] = scanner.nextFloat();
                    avgFace[i] += pic;
//lets add a clone of the pic array
// k++;
//System.out.println("\tmatrix: " + k);
//matricesToolbox.MatrixToolbox.printMatrix(avgFace);
facesArrayList.add(pic.clone());
picn++;
//System.out.println("pic n : "+ picn);
for(int i=0; i<rows*rows; i++)
avgFace[i] /= picn;
return(avgFace);
}catch(Exception e){
e.printStackTrace();
return(null);
private ArrayList calculateDifferenceFaces(double[] avgFace){
ArrayList xArrayList = new ArrayList();
double[] pic;
double[] phi = new double[avgFace.length];
for(int i=0; i< facesArrayList.size(); i++){
pic = (double[]) facesArrayList.get(i);
for(int j=0; j< pic.length*pic.length; j++){
System.out.println(pic[j] + " minus " + avgFace[j]);
//System.out.println(avgFace[j] + "");
phi[j] = pic[j] - avgFace[j];
//System.out.print(phi[j] + " ");
xArrayList.add(phi);
return(xArrayList);
}why in line "System.out.println(pic[j] + " minus " + avgFace[j]);" i get the same values for both pic and avgFace, although in the 1st method i add a clone of pic  facesArrayList.add(pic.clone()); ??                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

I would suggest;
- using a debugger. This will show if the arrays are the same or not. avgFace will be the same each time for each pics as its the same array.
- use nextDouble() as nextFloat() is less accurate (I am guessing not a problem here)]
- don't use pic.clone(), just create a new array at the start of each loop.

Similar Messages

  • Float and Double - 5.1 divide by 3.0

    Hi everyone,
    I am quite new to java programming in term of using it. I wrote a test class to learn about float and double. However when I wrote the below code, I got a strange result. So, I wonder if java's float and double have any kind of exception I should be aware of. This won't happen if I just change from 3 to other numbers. Any suggestion? Thanks in advance.
    public class MathTest {
    public static void main (String args[]) {
    float f1 = 5.1F;
    float f2 = 3.0F;
    double d1 = 5.1;
    double d2 = 3.0;
    System.out.println("Float result : " + f1/f2);
    System.out.println("Double result : " + d1/d2);
    Result:
    Float result : 1.6999999
    Double result : 1.7

    This is due to the way that binary numbers convert to digital numbers and is expected. See these threads for explanations:
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=%2Bprecision+%2Bwrong+double&col=developer-forums&rf=0&chooseCat=allJava&subCat=siteid%3Ajava

  • With Mavericks I have to hold command key down and double click to get a sub folder to open in a new window.  Can I go back to just double clicking ?

    With Mavericks I have to hold command key down and double click to get a sub folder to open in a new window.  Can I go back to just double clicking ?

    Of course. To do it, open a Finder window, go to Finder menu (on the menu bar) > Preferences > General, and untick "Open folders in tabs instead of new windows".

  • Outlook 2010 apostrophe, single and double quotes are changes to question mark while sending mails to other internet receipient.

    We are using MS Outlook 2010 as our mail client. But we have noticed that whenevr we sent a mail to any other internet mail recipient all the "apostrophe", "single" and "double quotes" have automatically converted to ?. We have
    done almost all the workaround found in this site such as
    1.New a message and focus on the message window > click File > Options > Mail > Spelling and Autocorrect… > Proofing > AutoCorrect Options… > AutoFormat > clear the box before “Straight quotes” with “smart quotes”
    2. Used different encoding. We presently using US-ASCII for outgoing message. etc.
    Need your help to sort out these issues urgently.
    Waiting for a solution.

    Hi,
    What is your account type? IMAP, POP or Exchange?
    Send an email from the webmail, ask the recipient if this issue persists.
    As far as I know, this problem is always related to the encoding for outgoing messages, and here I suggest you try UTF-8:
    Go to File -> Options -> Advanced -> International options -> Uncheck "Automatically select encoding for outgoing messages", then select "Unicode (UTF-8)" beside "Preferred encoding for outgoing messages" -> OK.
    Hope this helps.
    Regards,
    Melon Chen
    TechNet Community Support

  • No DNS and Double NAT

    Hello, I've recently encountered a very frustrating bug in my system that I could use some help troubleshooting.  I've read several similar posts, some are resolved while others are not, however none of the resolutions have worked for my situation.  Here it goes:
    I have an old macbook pro, a new macbook air, a white macbook and 2 iPhone 4s's all connected to the internet via WiFi through an AirPort Extreme.  The AE is connected to a cable modem which has internet service through Cablevision in NY.  There is also an AT&T Microcell hooked up to the AE to boost my cell signal.   All of this equipment has been working flawlessly together for a long time.  Until recently.  It could have started after an update, there have been several lately on all of the equipment including the firmware in the AE.  Anyway, I'll be connected without any issues - all lights green and happy - when suddenly, the internet will drop off and the AirPort Utility will pop up and warn me that:
    1) On the "internet" icon, it will say "disconnected"  
    2) On the AE icon, it says "No DNS server and Double NAT"
    After a few minutes and nothing done on my part, the lights turn green, the internet reconnects and all is well again. 
    This happens frequently and is really beaching a nuisance.  Due to the frequency of the disconnection, I can no longer download a large file, update, or anything.  Streaming video is impossible.
    So far, I have tried bridge mode and cycled the power in the order recommended to no avail.  When I do that, the AE turns green, but the internet says "not connected".  I have also read that there might be too many IP addresses which is not sitting well with my ISP, so I disconnected everything including unplugging the Microcell.  Lastly, there are no other wireless phones or devises in the house.  All to no avail.
    I should also mention that this began occurring on my Time Capsule, which I replaced with the AE in an attempt to fix this issue. 
    Any help would be greatly appreciated.
    Joe

    Sounds very similar to what I've been trouble shooting for 2 months now, only I have DSL from AT&T and I don't see the Double NAT warning.  My last post on the problem is here. 
    My only emergency solution for getting by day to day on the internet is to unplug the AE and connect one Mac directly to the DSL modem.  There's no shared connection or WiFi.  I looked at hosting WiFi from the Mac, but the only security available with that is WEP which isn't considered secure.  Even with this set up, I think (seat of the pants) that there are quality of service problems. 
    I've replaced the Airport Extreme with 2 different new units and the DSL modem with a new unit to no avail.  The Genius Bar and Apple phone support couldn't solve this, nor have 2 calls to AT&T support and one visit from an AT&T repairman.
    I would like to know how to better test or quantify the poor quality of connection that seems to be the problem.

  • TS1843 I am getting the following error messages- No DNS Server and Double SAT.  Can anyone walk me through a fix?

    Airport Express- No internet connection. I am getting the following error messages- No DNS Server and Double SAT.  Can anyone walk me through a fix

    Try putting these numbers in Network>TCP/IP>DNS Servers, for the Interface you connect with...
    208.67.222.222
    208.67.220.220
    Then Apply. For 10.5/10.6 Network, highlight Interface>Advanced button>DNS tab>little + icon.
    Might also put them in the Airport Express, no idea what Double SAT is!?

  • I have upgraded to an Iphone 6 and am at IOS 8.2.  My calendar alerts no longer show up as notifications on my phone.  I have gone into settings and double checked that notifications for calendar was on and it is. Any ideas on a fix?

    I have upgraded to an Iphone 6 and am at IOS 8.2.  My calendar alerts no longer show up as notifications on my phone.  I have gone into settings and double checked that notifications for calendar was on and it is. Any ideas on a fix?

    I have iPhone 4s but the same problem with calendar on 8.2 iOS - no sound, no notification appears - but everything is switched on.

  • Printer suddenly started printing blurry and double vision like

    Printer suddenly started printing blurry and double vision like. I have cleaned all i can and aligned the printer heads muliple times, but no difference

    I did a quick search and came across this. Although it is for a 432, hopefully this imformation helps as canon printers are assembled relatively simular.
    http://forums.usa.canon.com/t5/Printer-Multifunction-Support/I-had-a-paper-jam-on-my-MX432-and-since...
    MY EQUIPMENT:
    EOS Rebel T4i
    EF-S 18-55mm f/3.5-5.6 IS II
    EF-S 55-250mm f/4-5.6 IS II
    (2) B+W 5.8 010 UV - Haze 1x MRC (F - PRO Series filter)
    HOYA 58mm HMC Multi-Coated ND8 Filter

  • Single and double quotes entered in form field cause corruption?

    I am creating a database change request system using in APEX 2.2 and the main form has a description field (clob) and a API_description field (varchar2(4000)) that are text area fields on the page. The form seems to have trouble when the string data entered into the text area page items on the form contain single and double quotes.
    <br><br>
    I have pasted my test data below in this problem description(this is not true sql but it gets the point accross). I use the wizard created insert process to get the data into the db from the text fields in the wizard generated form, then use the wizard created fetch process to get the data back out and rendered on the same form. When I use the test data below, sometimes a few characters dissappear from my input data on the way out, sometime form fields go away, and their html is interspersed with the previous form field's data on the page. And I get different results on different tests with the same data.
    <br><br>
    Do I have to do something special for a vanilla htmldb text page item on a form to be able to receive single and double quotes in the string input in order to avoid that string data confusing the processing on the way in to the Database or on the way out for rendering?
    <br><br>
    Do I have to escape the characters? How do I do this?
    <br><br>
    The "varchar2(1) := ‘A’" part of the below TEST DATA string seem to cause the most trouble. The behavior is erratic - sometimes the pattern works, sometimes html is interspersed in one place, sometimes another (on the way back out)
    <br><br>
    START TEST DATA:
    Add column pcl3_data_ind varchar2(1) to edc_tran,edc_log, edc_recreate_tran table
    Or
    Create a file with following sql in it
    Insert into sometable values(‘A’,sysdate);
    Or
    create new table as follows
    create table “someschema”.“sometable”
    (id number not null,
    Name varchar2(20) not null,
    Join_date sysdate
    Active varchar2(1) := ‘A’
    END TEST DATA:
    <br><br>
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Here is an example of the test data being displayed after being fetched back out of oracle (this will look like gibberish when rendered in the forum system (end of problem description except for example):
    <br><br>
    env
    Add column pcl3_data_ind varchar2(1) to edc_tran,edc_log, edc_recreate_tran table
    Or
    Create a file with following sql in it
    Insert into sometable values(‘A’,sysdate);
    Or
    crete new tableas follws
    crate table “somesca”.“sometable”
    har2(20) not null,
    Join_date sysdate
    Active varchar2(1) := ‘A’
    woextarea>
    <a class="eLink" title="Edit" href="javascript:popupURL('f?p=4000:371:204538675714370::::P371_ID,FB_FLOW_ID,FB_FLOW_PAGE_ID:1034609472735510,104,2');" tabindex="999"><img src="/i/e.gif" alt="Edit" class="eLink" /></a></td></tr><tr><td nowrap align="right"><label ...

    I found a good php related post that has a nice set of the potentially problematic characters (this is in the context of word pasted into IE I think). I am pretty confident that at least single curly quotes do not work well in apex 2.2). I would not be surprised if some of the others were trouble as well.:
    http://lists.evolt.org/archive/Week-of-Mon-20030602/141975.html
    here is the list
    $trans_tbl[chr(34)] = '"' ;          //      quote
              $trans_tbl[chr(38)] = '&' ;          //      ampersand
              $trans_tbl[chr(60)] = '<' ;          //      less-than
              $trans_tbl[chr(62)] = '>' ;          //      more-than
              $trans_tbl[chr(128)] = '€' ;     //      euro
              $trans_tbl[chr(129)] = '€' ;      //     euro
              $trans_tbl[chr(130)] = '‚' ;      //     low quote
              $trans_tbl[chr(131)] = 'ƒ' ;      //     florin
              $trans_tbl[chr(132)] = '„' ;      //      double low quote
              $trans_tbl[chr(133)] = '…' ;      //     ellipsis
              $trans_tbl[chr(134)] = '†' ;     //     dagger
              $trans_tbl[chr(135)] = '‡' ;      //     double dagger
              $trans_tbl[chr(136)] = 'ˆ' ;      //     circumflex
              $trans_tbl[chr(137)] = '‰' ;      //     per thousand
              $trans_tbl[chr(138)] = 'Š' ;      //     S caron
              $trans_tbl[chr(139)] = '‹' ;      //     left angle quote
              $trans_tbl[chr(140)] = 'Œ' ;      //     OE ligature
              $trans_tbl[chr(142)] = 'Ž' ;      //     Z caron
              $trans_tbl[chr(145)] = '‘' ;      //     left single quote
              $trans_tbl[chr(146)] = '’' ;      //     right single quote
              $trans_tbl[chr(147)] = '“' ;      //     left double quote
              $trans_tbl[chr(148)] = '”' ;      //     right double quote
              $trans_tbl[chr(149)] = '•' ;      //     bullet
              $trans_tbl[chr(150)] = '–' ;      //     en dash
              $trans_tbl[chr(151)] = '—' ;      //     em dash
              $trans_tbl[chr(152)] = '˜' ;      //     small tilde
              $trans_tbl[chr(153)] = '™' ;      //     trademark
              $trans_tbl[chr(154)] = 'š' ;      //     small s caron
              $trans_tbl[chr(155)] = '›' ;      //     right angle quote
              $trans_tbl[chr(156)] = 'œ' ;      //     oe ligature
              $trans_tbl[chr(158)] = 'ž' ;      //      small z caron
              $trans_tbl[chr(159)] = 'Ÿ' ;      //     Y with diaeresis
    <br>
    -Geoffrey

  • I am changing laptops and have tried to download and install Acobat 9 Standard from the Adobe website, but get message that my serial number is invalid. I log in and double check my account and it shows as a valid serial number.  Now what?

    I am changing laptops and have tried to download and install Acrobat 9 Standard from the Adobe website, but get message that my serial number is invalid. I log in and double check my account and it shows as a valid serial number.  Now what?

    If you had it on a laptop that crashed and you threw away, it is still considered as activated on that machine.  YOu should contact Adobe by chat or by phone and have them deactivate for you.
    Here is a link to a page with options to help make contact:
    http://www.adobe.com/support/download-install/supportinfo/
    If you are getting a message that indicates the serial number is not valid, you should look thru the following:
    Error "The serial number is not valid for this product" | Creative Suite
    http://helpx.adobe.com/creative-suite/kb/error-serial-number-valid-product.html

  • What 's the difference between quote ' and double quote "?

    what's the difference between quote' and double quote "?
    when we use each one?
    Exemple of use of each case?

    'c' is a char, ie. a primitive type representing a single character
    "c" is an instance of the String class length 1.

  • My trackpad in Macbook is not working properly. The tap and double tap is not working but other gestures are working. Please help me..thanks

    My trackpad in Macbook is not working properly. The tap and double tap is not working but other gestures are working. Please help me..thanks

    Portables and Magic Trackpad: Jumpy or erratic trackpad operation
    Might be something from that link that will help.

  • I have just bought four songs from iTunes store using my iMac. I can play the music on my iMac and throughout my Apple TV. However after several restarts and double checks I can't get the four tunes to sync with either my iPhone or my iPad.

    I have just bought four songs from iTunes store using my iMac. I can play the music on my iMac and throughout my Apple TV. However after several restarts and double checks I can't get the four tunes to sync with either my iPhone or my iPad. All the software is up to date.

    do you use the same Apple ID on your iMac, your iPhone and iPad? This is a requirement.

  • In an album, many pictures would show on the screen and double clicking one would enlarge it for adjustments. Now one larger photo shows and along the bottom severa smaller ones. Options which used to be at the top right of screen no longer show. Whel

    In Aperture album about 16 photos would show on screen and double clicking on one would enlarge it for adjustments. Now one larger image shows with about 7 photos at bottom. Options for controlling this no longer appear at top right. How do I correct this?

    Do you mean the "View" controls are missing in your Toolbar?
    To add these controls back to the Toolbar, use the View menu and select "Customize Toolbar". Drag the View Controls back to the Toolbar.

  • How to handle both single click and double click from mouse

    hey,
    I looked in past threads and didn't get a proper answer for capturing both single and double click from the mouse.
    in most applications the single click action does not interfere with the double click action, for example in a text editor, single click sets the cursor in between the text, double click marks a word, triple click marks a sentence, they do not bother each other, they all can happen first the single then the double and then the triple, but what if i have a very distinct action for each of the actions, the e.getClickCount() returns every time the number of clicks and if i use
    if(e.getClickCount()==1)
        doSingleClick();
    if(e.getClickCount()==2)
        doDoubleClick();it will always do first the single click and then the double click, which works fine with the example i gave, but not with what i want to do, so i was thinking to over come this that i will use another thread to run my tasks if dt has past since the last click and by the last click counts to perform the correct action and go to sleep until the next mouse click notify it, what do you think?
    run this to get what i mean...
    package blah;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MouseClickTest {
         static long previousTime = System.currentTimeMillis();
         public static void main(String[] args) {
              JPanel panel = new JPanel();
              JButton component = new JButton("Hit me, please");
              component.addMouseListener(new MouseAdapter(){
                   public void mouseClicked(MouseEvent me){
                        if(me.getClickCount()==1)
                             System.out.println("Now I will do single click action");
                        if(me.getClickCount()==2)
                             System.out.println("Now I will do DOUBLE click action");
    //                    System.out.println("Click count: " + me.getClickCount());
              panel.add(component);
              Launcher.launch(panel);
    package blah;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Launcher {
         public static JFrame launch (Container contents, String title, Color backgroundColor) {
              JFrame frame = new JFrame (title);
              if (backgroundColor != null) {
                   frame.setBackground (backgroundColor);
                   contents.setBackground (backgroundColor);
              } else {
                   frame.setBackground (contents.getBackground());
              frame.getContentPane().add (contents, BorderLayout.CENTER);
              frame.pack();
              frame.addWindowListener (new WindowAdapter() {
                   public void windowClosing (WindowEvent e) {
                        System.exit (0);
              frame.setVisible (true);
              return frame;
         public static JFrame launch (Container contents, String title)      {
              return launch (contents, title, null);
         public static JFrame launch (Container contents, Color backgroundColor) {
              return launch (contents, contents.getClass().getName(), backgroundColor);
         public static JFrame launch (Container contents) {
              return launch (contents, contents.getClass().getName());
    }

    Read my comments and solution in this posting; [http://forums.sun.com/thread.jspa?forumID=57&threadID=705244]
    and then choose a better design for your application.

Maybe you are looking for

  • How many of these objects should I be able to insert per second?

    I'm inserting these objects using default (not POF) serialization with putAll(myMap). I receive about 4000 new quotes per second to put in the cache. I try coalescing them to various degrees but my other apps are still slowing down when these inserts

  • Importing field values in iPhoto 08

    Hi, I've been trying out Portfolio to organize my images but have come to the conclusion that it is too much software for my needs. The thing is that I now have about 300 images with keywords and other info now sitting in Portfolio. One solution woul

  • Java to DB2 Errors

    1) We have DB2 9.1.2 Express C server on SUSE Linux 10.2 kernel v2.6 2) We have JBoss 4.0 application server & Apache web server on other 2 linux boxes. 3) We are using Eclipse for Java development with Hibernate as intermediate layer. 4) While doing

  • Nested query in BPEL JDeveloper

    Hi, Can anyone help me with nested query writing in BPEL (JDeveloper) the query is : SELECT LENGTH, WIDTH, HEIGHT, WEIGHT, LENGTH*WIDTH* HEIGHT AS ITEM_CUBE FROM ITEM_SUPP_COUNTRY_DIM WHERE ITEM= <Level1 item> AND DIM_OBJECT= (SELECT CASE_NAME FROM I

  • Solaris JVM Process Growth

    Hi, I am investigating a problem where we experience continual growth of our JVM process. The overall process size and native heap size of the JVM process continually grow at the same rate. I am monitoring these using the commands 'ps - o pid,vsz,rss