A SIMPLE int[ ] array is driving me nuts!

ok, what am I doing wrong? I've read many other posts saying the same thing: arrays giving null pointer exceptions, but I can't find an intelligible answer:
* Demonstrates simple arrays
public class DemonstrateSimpleArrays
    private int[] anIntArray;
    private int[] anotherIntArray;
    public DemonstrateSimpleArrays()
        int[] anIntArray = {1,2,3};
        System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);
        int[] anotherIntArray = new int[3];
        anotherIntArray[0] = 4;
        anotherIntArray[1] = 5;
        anotherIntArray[2] = 6;
        System.out.println(anotherIntArray[0] + "" +
          anotherIntArray[1] + anotherIntArray[2]);
    public void printArrayValues()
        System.out.println(anotherIntArray[0] + "" +    //  Null Pointer Exception occurs here.
          anotherIntArray[1] + anotherIntArray[2]);
        System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);  //  Null Pointer Exception occurs here.
}Thanks!

my apologies: the code in my second emssage was incorrect. it did not include the second printArrayVariables method that I just added. see ammended:
* Demonstrates simple arrays
public class DemonstrateSimpleArrays
    private int[] anIntArray;
    private int[] anotherIntArray;
    public DemonstrateSimpleArrays()
        int[] anIntArray = {1,2,3};
        System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);
        int[] anotherIntArray = new int[3];
        anotherIntArray[0] = 4;
        anotherIntArray[1] = 5;
        anotherIntArray[2] = 6;
        System.out.println(anotherIntArray[0] + "" +
          anotherIntArray[1] + anotherIntArray[2]);
        printArrayValues(anotherIntArray, anIntArray);
    public void printArrayValues()
        System.out.println("Print Array Values:");
        System.out.println(anotherIntArray[0] + "" +   //Still Throws exception when this method is called.
          anotherIntArray[1] + anotherIntArray[2]);
        System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);
    public void printArrayValues(int[] anotherIntArray, int[] anIntArray)
        System.out.println("Print Array Values:");
        System.out.println(anotherIntArray[0] + "" +   //Does not Throw exception (thank goodness!)
          anotherIntArray[1] + anotherIntArray[2]);
        System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);
}

Similar Messages

  • This rummy game is driving me nuts, Please Help me!!!!

    In my project, I am suppose to create an agent that plays a simple version of rummy. To win this game, the agent is dealt seven cards initially, and in order to win, it has to create two sets of combination of cards (one of 3 cards the other of 4), each combination can either have cards of the same rank (eg. 10 Hearts, 10 Clubs, 10 Spades) or the same sequence, but the same suit (2s,3s,4s,5s OR 7c,8c,9c). The cards are saved in an array of seven elements.
    Beside the main SDK, we have our own api for this game, that for example lets you check whether two cards are in the same rank (eg. (10H.sameRank(10D) returns true), or whether they have the same suit or not.
    I have no trouble creating a hand of cards with the same rank, but my problem is with creating a hand of cards with the same sequence.
    I have tried to come up with an algorithm that would allow me to create a hand of cards (of same suit) in the sequence, but without success. This thing is driving me nuts.
    CAN ANYONE GIVE ME ANY GUIDANCE PLEASE!!
    Thanks

    http://forum.java.sun.com/thread.jsp?forum=406&thread=354616

  • Ssrs report from ssas cube , driving me nuts now...

    hi folks:
     This is driving me nuts and I know it's gonna be some small stupid settings.  The question is pretty simple, I want to users to be able to pick up a week from date hierarchy. If I specify a static week, mdx query will run and report shows with
    correct data and format. 
    Now, in the dataset I've created using query designer, I've dragged data hierarchy into the filter and check the parameter box and also put a default value as well.   Technically, when I run this report, I am supposed to see a dropdown list with all
    the available dates but I did not see any dropdownlist and report still runs with default value. 
     Why is this happening? 
    Thanks
     Hui
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

    Hi Hui,
    Just as Gnanadurai said, a report auto runs when all parameters has their own default values. This scenario can also be occurred when there are no available values for the parameters. So if you want to see a drop-down list with all available dates when the
    report runs, we should specify some available values for the parameter. For example, we can specify the available values come from a dataset field. Then the values in the field would be displayed in the drop-down list, we can select some of them to filter
    the report.
    Reference:
    Adding Parameters to Select Multiple Values in a List (SSRS)
    Hope this helps.
    Thanks,
    Katherine Xiong
    If you have any feedback on our support, please click
    here.
    Katherine Xiong
    TechNet Community Support

  • How do you invoke a method with native int array argument?

    Hi,
    Will someone help me to show me a few codes samples on how to invoke a method which has only one argument, an int [] array.
    For exampe:
    public void Method1(int [] intArray) {...};
    Here is some simple code fragment I used:
    Class<?> aClass = Class.forName("Test2");
    Class[] argTypes = new Class[] {int[].class};
    Method method = aClass.getDeclaredMethod("Method_1", argTypes);
    int [] intArray = new int[] {111, 222, 333};
    Object [] args = new Object[1];
    args[0] = Array.newInstance(int.class, intArray);
    method.invoke(aClass, args);I can compile without any error, but when runs, it died in the "invoke" statement with:
    Exception in thread "main" java.lang.IllegalArgumentException: object is not an instance of declaring class
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at Test1.invoke_Method_1(Test1.java:262)
         at Test1.start(Test1.java:33)
         at Test1.main(Test1.java:12)
    Any help is greatly appreciated!
    Jeff

    Sorry, my bad. I was able to invoke static methods and instance methods with all data types except native int, short, double and float, not sure the proper ways to declare them.
    After many frustrating hours, I posted the message for help, but at that time, my mind was so numb that I created a faulted example because I cut and pasted the static method invocation example to test the instance method passing int array argument.
    As your post suggested, "args[0] = intArray;", that works. Thanks!
    You know, I did tried passing the argument like that first, but because I was not declaring the type properly, I ended up messing up the actual passing as well as the instantiation step.
    I will honestly slap my hand three times.
    jml

  • Better way to sort multi dim int array

    I'm tracking key value pairs of ints. I know that the keys will not repeat. I've decided to do this in an int[][] array
    int[][] data = new int[2][many millions]This app crunches a lot of data so I'm shooting for the best memory handling. I push a bunch of key - value pairs into the array. I will likely populate many if not all data and not have to search until I'm done populating so I'm not sorting as I go.
    I know that I can sort the single dim array data[0] but how can I keep the values array data[1] synchronized? I've tried a few things, all have been successful but I'm wondering if there's a better method. Currently I create copy arrays for the keys and values, sort the original keys, and loop through the copy keys. For each copy key I binary search the sorted keys and drop the value in the correct spot. I don't like having to allocate 2X the amount of memory for the swap arrays. Any thoughts?
    Thanks
    ST

    Jos, thanks for the reply. I tried this method but I don't get as much
    storage since each internal array counts as an object.Yes I know; maybe I've got something for you, waidaminnit <dig-dig/>
    <shuffle-shuffle/> Ah, got it. Suppose you wrap your two dim array in
    a simple class that implements this interface:public interface Sortable {
         public int length();
         public int compare(int i, int j);
         public void swap(int i, int j);
    }I think the semantics of the methods are obvious. Given this interface
    you can sort anything you like using this thingy:public class HeapSort {
         private Sortable s;
         private void heapify(int i, int n) {
              for (int r, l= (i<<1)+1; l < n; i= l, l= (i<<1)+1) {
                   if ((r= l+1) < n && s.compare(l, r) < 0) l= r;
                   if (s.compare(i, l) < 0) s.swap(i, l);
         private void phase1() {
              for (int n= s.length(), i= n/2; i >= 0; i--)
                   heapify(i, n);
         private void phase2() {
              for (int n= s.length(); --n > 0; ) {
                   s.swap(0, n);
                   heapify(0, n);
         public HeapSort(Sortable s) { this.s= s; }
         public Sortable sort() {
              phase1();
              phase2();
              return s;
    }kind regards,
    Jos

  • Slope calculation driving me nuts

    Hi all,
    I have a rather odd issue that I can't seem to fix. I have a
    potentiometer monitoring position, from which I am attempting to derive
    velocity. I have smoothed out the displacement curve so it is fairly
    linear, yet any of the linear fit coefficients, Savitzky filters,
    derivatives/differentials (ptbypt or otherwise), build array methods of calculating the slope
    are not working for me. I've searched around and tried to base my
    methods off the shipping examples but to no avail. This is driving me
    nuts and I'm very much under the gun, so if anyone can help me overcome
    my own stupidity I would greatly appreciate it. The picture I've
    attached shows the smoothed displacement graph on the left, as well as
    some of the results I've gotten with derivatives. I've also attached
    the main program and the subvi I am using.
    Thanks again!
    Attachments:
    Ultimate_Calculations1.vi ‏361 KB
    Data1.jpg ‏268 KB
    Toddstron_30031.vi ‏705 KB

    I've experimented with the linear fit but haven't been able to get results, as I get an error due to unequal array sizes. I haven't been able to work around it (I'm a bit of a newbie that probably isn't as good with some of the basics as I should be at this point). Sorry about attaching the wrong version of the VI. I tried saving all the default values but some of them did not work. I've attached another screen shot for your reference.
    Thanks again for your time and patience.
    john
    Attachments:
    Calcs front panel.jpg ‏258 KB
    Toddstron_3003_defaults.vi ‏717 KB
    Ultimate_Calculations_defaults.vi ‏109 KB

  • Returning int array from C to Java as method parameter

    Hello,
    I've been trying to accomplish this
    Java
    int[] myArray = ... (filled with some data);
    int retCode = myNativeCall(myArray);
    if(retCode == 0)
    doSomethingWith(myArray); //myArray gets overwritten with new data (with new size also) during the native call...
    C
    JNIEXPORT jint JNICALL Java_GenChav_rsaEncrypt(JNIEnv *env, jobject obj, jintArray myArray){
    jintArray outbuf;
    int[] new_array = .. // some function will fill this....
    int new_array_length = ...//some function will give me the new size, not big, 512 max...
    jint tmp[new_array_length]; //allocate..need something more ??
    memcpy(tmp, new_array, new_array_lenght);
    outbuf=(*env)->NewIntArray(env, new_array_length);
    (*env)->SetIntArrayRegion(env, outbuf, 0, new_array_length, tmp);
    myArray=outbuf;
    I tought this way I would have a updated myArray ints on the Java program...
    Any thought??

    user5945780 wrote:
    Ok, let's try to be constructive here...
    How I do implement a return type for my method like a int array ?First realized it has nothing to do with JNI. So the same question and answer applies to java only.
    >
    like:
    int[] return = myNativeCall();
    Yes.
    Then I will look for return[0], if it is == to 0, fine, it means a successful calculation by the native code. Not sure what that means. The structure of what you return it up to you.
    It can help when you are unsure of what to do in JNI....write a pseudo representation of what you want to do in a java method. Then translate that java method into JNI, everything in the pseudo method must be in the JNI code.

  • Can you tell me why none of my music will play I had a little box that came up saying all your items are ticked so they will not play on itunes what does this mean it's driving me nuts help!!!

    HI there can you tell me why none of my music will play on itunes it just displays a message saying it cannot be located please help it is driving me nuts
    Jan

    About 5 days ago for no apparent reason at all, about
    7000 songs which i have collected over a number of
    years has just decided that it wont play in ITUNES or
    in any other of my media players. When you click on
    Play over a song nothing happens. The play icon
    doesnt even come up on the screen.
    Steps I have taken so far are:
    1 - Remove all tracks from ITUNES and then re-add the
    folder where all the songs are. This has obviously
    removed all songs, but when I have re-added the
    folder , it has added about 650 tracks back on to the
    playlist. These 650 tracks will play. This leaves
    approx 6400 tracks that it wont play.
    By the way all the songs on my PC are MP3 type and I
    have had no problem playing any of them until last
    week.
    2 - I have re-installed ITUNES and reinstalled
    Quicktime and that has not worked.
    3 - All of my songs are backed up on to a External
    Hard Drive. I have tried to restore the songs and
    also play them directly from the external hard drive.
    I get the same problem when I do this.
    4 - I have enabled and allowed all permissions for
    the account that I am running the PC from.
    I am guessing there must be some settnig or Registry
    Key that is blocking me playing the tracks from the
    PC. I have also tried to launch the songs in Media
    Player and Sonic stage but thsi has not played
    either.
    All the tracks are in the folder structure as they
    were before so I know they are there. I just need to
    somehow unlock them.......
    If anyone has any ideas, I would be very grateful as
    I dont want to lose my entire music collection.
    Also I cannot find anyweher on here that is a Support
    number or email address for Apple as this is an
    ITUNES issue and they should be resolving it for
    me!!!!
    Thanks
    Dell   Windows XP
    Pro  

  • The new tab behavior is driving me nuts. It keeps re-centering on tabs nearest the start of the list when I move a tab. How do I change this?

    The new tab behavior is driving me nuts. It keeps re-centering on tabs nearest the start of the list when I move a tab. How do I change this?
    I don't want to download an app. I would rather add a new string in about config or just change of the ones in there to false. It's making my work life rather difficult, to be forced to go all the way back to the end of my list after moving one tab just to have to do it again. I mean it's to the point where I might consider changing browsers if they had tab scroll bars.
    Edit: At this point I will download any app. Please make this stupid feature stop.

    The result of setting up that code will do exactly as you described: the tabs will be crowded together. I had not noticed any change in behaviour of Firefox with tabs because all the tabs are crowded together, so they cannot scroll, and I very seldom move tabs.

  • ICloud is registered to old iTunes account, how can I delete this account off my phone? It won't let me log out or delete icloud and I can't remember my password or security questions. Please help as its driving me nuts!

    Hi there Apple Community!
    I have a problem with my iCloud - it is registered to my old iTunes account (old work e-mail that doesn't work anymore) and I can't remember my password or security questions, argh.
    Can someone help me delete my iCloud from my phone without restoring my phone as its driving me nuts!
    Many thanks in advance.

    Paulini88!!! wrote:
    Hi there Apple Community!
    I have a problem with my iCloud - it is registered to my old iTunes account (old work e-mail that doesn't work anymore)
    Then update it to new email address. Creating a new AppleID is usually not a good thing as anything on your old account will not be transferred to your new account.
    See this -> Change your Apple ID - Apple Support
    and I can't remember my password or security questions, argh.
    So reset them...
    See this -> If you forgot your Apple ID password - Apple Support
    Can someone help me delete my iCloud from my phone without restoring my phone as its driving me nuts
    Restoring it will not delete it.
    You need to turn it off (Settings > iCloud - Delete account then re-enable it with updated AppleID.
    This is the ONLY way you can do it.

  • Writing txt file to int array

    The project I was assigned is to write a program that takes numbers from a text file (all on one line, separated by spaces) and store them into a 5-element array. The program is supposed to check and see if the array is big enough to hold all the numbers from the text file, and if it isn't, it is supposed to double that array size. I've written the following code and it compiles, but it will not run due to this error:
    Exception in thread "main" java.lang.NullPointerException
         at java.io.Reader.<init>(Reader.java:61)
         at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
         at ArrayReader.main(ArrayReader.java:16)
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    This is what I have so far. If anyone could help me or point out anything I missed it would be greatly greatly appreciated.
    import java.io.*;
    public class ArrayReader
         public static void main(String[] args)
              File file = new File("numberlist.txt");
              FileInputStream fis = null;
              BufferedReader br = new BufferedReader (new InputStreamReader(fis));
              int i = 5;
              int x = 0;
              int[] array;
              array = new int;
              try
                   fis = new FileInputStream(file);
                   for (x = 0; x < array.length; x++)
                             if (x > array.length)
                                  i = i*2;
                                  System.out.println("Array too small. Doubling size to: " + i);
                             else
                                  array[i] = fis.read();
              catch(FileNotFoundException e)
                   System.out.println("File " + file.getAbsolutePath() +
                                            " could not be found on filesystem");
              catch(IOException ioe)     
                   System.out.println("Exception while reading the file" + ioe);
              for (i = 0; i < array.length; i++)
                   System.out.println(array[i]);

    ursusmajx wrote:
    Exception in thread "main" java.lang.NullPointerException
         at java.io.Reader.<init>(Reader.java:61)
         at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
         at ArrayReader.main(ArrayReader.java:16)Start by looking at line 16 in ArrayReader.main. It's not lie 16 in the code you posted here, so either you haven't posted the code you tried to run or you're not running the code you think you are.
    I do see where you are using fis before assigning it a value.
    db

  • "Server either does not have a virtual switch configured or none of the configured virtual switches have an IP address assigned" error driving me nuts!

    OK; have been trying to setup a test VM based RDS deployment for a few days now with no luck.
    this error mentioned above:
    "Server <server name> either does not have a virtual switch configured or none of the configured virtual switches have an IP address assigned" error is driving me nuts!
    I have removed and re-added the RD Virtualization Host role numerous times, each time having the "create a virtual switch" checkbox selected, but it did NOT create any virtual switch.
    I created the external virtual switch manually and tried to create the desktop collection again, no luck with the same error.
    a few questions:
    1. you don't assign IP to a switch! you assign IP to Network Interfaces. why does the error puts it like this?! it is technically wrong.(yeah yeah I know all about how you'd assign IP to managed switches in real world to telnet into them and manage them.
    you know better than me that it is not the case here!)
    2.the RDS Virtualization hosts are using their wifi card as the card for the virtual switch. could that be the reason? I even disabled their unplugged wired NIC just to make sure that the wifi is the only available option for the RDS wizard to use for the
    virtual switch creation; but it didn't use it and it didn't create any virtual switch automatically.
    3.if WIFI nic is indeed the reason, is it your suspension or an official documents is there somewhere stating so (that the WIFI NICS on a Virtualization hosts are not supported as the hub for a virtual switch).
    4.what are the properties of the virtual switch the RDS requires? does it have to be external? why can't it work even with my manually created external switch?
    5.how would I fix it?
    P.S: the environment is made up of 2 laptops, having windows 2012 R2 trial installed on them, using their wifi to connect to the out world. no cable is plugged into their wired NIC card.

    Hi,
    Thank you for posting in Windows Server Forum.
    The simplest short term solution was to connect each computer to a small switch that had no other connectivity. This brought up the link light on the external NIC and allowed the creation of the collection to complete. You need to use an external switch. You
    can create one external switch which might fix the problem.
    Please check below article for information.
    VDI Deployment Error About Virtual Switch
    In addition please referthis article for information regarding virtual switch.
    Hope it helps!
    Thanks.
    Dharmesh Solanki
    TechNet Community Support

  • W henever I try to open an Adobe file I get this message: Adobe Reader could not open ....because it is either not a supported file or because the file has been damaged. This is driving me nuts. Can I purchase somethine from Adobe that will allow me to op

    Whenever I try to open an Adobe file I get this message:
    Adobe Reader could not open ..... because it is either not
    a supported file type or because the file has been damaged
    (for example, it was sent as an e-mail attachment and wasn't
    correctly decoded). This is driving me nuts !! Is there an Adobe
    product that I can purchase that will make my Adobe Reader
    work??? Right now it is useless to me and I have an important
    download taht was sent as an Adobe download file and after
    I downloaded the file Adobe Reader refuses to open it.
    Please Help!!!!

    I am having the same problems!!! How can a person get help from ADOBE? Or do I cancel and find a different program for converting.

  • HT201263 Cannot complete 2 step recovery to re set password as it asks for original password which I've forgotten. ..  hence me doing 2step recovery! It's ridiculous.  and    driving.me nuts. Icannot  use any apps or face time..please help.

    I forgot my original password..my ID was disabled..I did factory restore through iTunes..I was sent email from apple with the 2 step recovery..I had followed instructions only to find one part that asked for my old password before I could re set a new one !
    It's driving me nuts..it's ridiculous and I'm still unable to use any apps or face time..
    Please help if you can..I'm desperate and apple support can't or won't help me so if given up.

    Alternatives for Help Resetting Security Questions and Rescue Mail
         1. Apple ID- All about Apple ID security questions.
         2. Rescue email address and how to reset Apple ID security questions
         3. Apple ID- Contacting Apple for help with Apple ID account security.
         4. Fill out and submit this form. Select the topic, Account Security.
         5.  Call Apple Customer Service: Contacting Apple for support in your
              country and ask to speak to Account Security.
    How to Manage your Apple ID: Manage My Apple ID

  • MS Word 2011 for Mac toolbar missing and cannot get back. tried disabling toolbars, deleting Normal.dotx to no avail. Sometimes just pops up for no reason. Also reinstalled Office.  Any ideas please?  Driving me nuts as cannot use shortcut icons

    I have MS Word 2011 installed on my iMac running Lion.  Have overcome the problem of the hidden Library but still unable to see toolbar with the shortcut icons such as Format paster.  Have researched and tried deleting normal template.  no joy. reinstalled Office. no joy. unchecked standard and formatting toolbars and rechecked and a blank line appears where toolbar icons should be.  Sometimes they magically appear after a few minutes!  Often not.
    this is driving me nuts so please any ideas

    That's awesome G4 dude, thank you.
    I've had this problem since upgrading to the latest release of word 2011. Thre used to b a losenge in the top right corner, when this dissappeared it lost the toolbar strip. Really frikkin' annoying it was. Thanks for the tip!
    So can someone tell Microsoft about this problem? their forums are as useless as their desktop help files.
    J

Maybe you are looking for

  • Process that takes 6 months to finish

    My quesiton is on performance when having a process open for extended amount of time. For example a tuition reimbursment process. A user enters his data at the beginning of the school year to get approval for his course work. Once approved the proces

  • Advise on debugging?

    Hello, Could I ask, does this error mean the Render method cannot loop through the frames of the avi? Because the .avi could not be found? Thank you java.lang.NullPointerException at MyCustomCanvas.render(FrameRenderer.java:90) at MyCustomCanvas.pain

  • How to see the exception raised  in function module...

    DEAR ABAPERS, how can i see that exception, when iam excuting Regards, veera

  • Creating an app that can load other apps?

    I have a SWf application built in flex 4. One part of the application relies on accessing a public variable ("step1") set at the application root, and is accessed with var app:Object = FlexGlobals.topLevelApplication; trace("step one is "+app.step1);

  • Ti4200VTD8X & WDM Capture Malfunction

    Okay, this is my last attempt at fixing this problem before my card goes down to the 100 yard line for a little target practice. I have: Antec 1080 tower w/ 430W PS, 3.3V line running at 3.28V Asus P4S8X, AGP Driver loaded, BIOS updated 512M Kingston