Implementing Arrays - Problem!

Hi,
I am an novice Java programmer and i am having some trouble with arrays, I have written a program that calculates grades, but it does not use arrays. I would like to use arays in my program and at the same time have it support up to 50 people. Please help me in this matter, thanks,
Martin
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class GradeWatch9{//start of class definition GradeWatch
public static void main ( String args[] ) {//start of main method
//string declarations
String firstname;
String secondname;
String studentid;
String midtermgrade;
String finalgrade;
String listings="";
String option;//variable used to receive user's option <-1>//<0>
//character declarations
char actualgrade;//letter grade assigned to total points earned
char lettergrade=0;//assignment of a letter grade
//integer declarations
int loop=0;//(this will be converted fr. option//will compare result)
int studentid_int;
int midterm_grade=0;
int final_grade=0;
double midterm_gradevalue=0;//point calculations
double final_gradevalue=0;//point calculations
double total_gradevalue=0;//total points possible out of 100
do
//input dialogs (5) with validations
boolean firstnamecheck=false;
firstname = JOptionPane.showInputDialog("Enter The Student's First Name: ");
for ( int j=0; j<firstname.length(); j++ )
if(!Character.isLetter(firstname.charAt(j)))
firstnamecheck=false;
firstname=JOptionPane.showInputDialog("Invalid Entry: \n You have entered an integer. \nPlease Re-enter Sudent's first name: ");
boolean secondnamecheck=false;
secondname = JOptionPane.showInputDialog("Enter The Student's Last Name: ");
for ( int j=0; j<secondname.length(); j++ )
if(!Character.isLetter(secondname.charAt(j)))
secondnamecheck=false;
secondname=JOptionPane.showInputDialog ("Invalid Entry: \n You have entered an integer. \nPlease Re-enter Sudent's last name: ");
boolean studentidcheck=false;
do
studentid = JOptionPane.showInputDialog("Student Id is the Student's Social Security Number.\nEnter The Student's ID #: ");
if (studentid.length()!=9)
JOptionPane.showMessageDialog(
null,
"INVALID ENTRY: PLEASE ENTER 9 DIGITS WITHOUT DASHES.",
"ERROR", JOptionPane.ERROR_MESSAGE);
else {
for ( int j=0; j < studentid.length(); j++ ){
if(!Character.isDigit(studentid.charAt(j)))
JOptionPane.showMessageDialog(
null,
"INVALID ENTRY: YOU HAVE ENTERED LETTERS.",
"ERROR", JOptionPane.ERROR_MESSAGE);
else {
studentid_int= Integer.parseInt(studentid);
if (studentid_int<0)
JOptionPane.showMessageDialog(
null,
"INVALID ENTRY: YOU HAVE ENTERED A NEGATIVE NUMBER.",
"ERROR",
JOptionPane.ERROR_MESSAGE);
else studentidcheck=true;
} while (studentidcheck==false);
midtermgrade = JOptionPane.showInputDialog("This is worth 40% of Student's Grade.\nEnter Mid-term Grade: ");
midterm_grade = Integer.parseInt( midtermgrade);
while ( (midterm_grade < 0) || (midterm_grade > 100) )
midtermgrade=JOptionPane.showInputDialog ("Invalid Entry!\nA grade entered must be between (0-100).\nPleae Re-Enter Mid-term Grade: ");
midterm_grade = Integer.parseInt( midtermgrade);
finalgrade = JOptionPane.showInputDialog("This is worth 60% of Student's Grade.\nEnter Final Grade:");
final_grade= Integer.parseInt( finalgrade);
while ( (final_grade<0) || (final_grade > 100) )
finalgrade= JOptionPane.showInputDialog ("Invalid Entry!\nA grade entered must be between (0-100).\nPleae Re-Enter the Final's Grade: ");
final_grade= Integer.parseInt( finalgrade);
DecimalFormat twoDigits = new DecimalFormat( "0.00");
//calculations for grades
//midterm is worth 40% of grade
midterm_gradevalue = midterm_grade * .4;
//final is worth 60% of grade
final_gradevalue = final_grade * .6;
//calculates the final grade for the student in class
total_gradevalue = midterm_gradevalue + final_gradevalue;
//if else statement for grade allotment
if (total_gradevalue>=90)
lettergrade='A';
else if (total_gradevalue>=80)
lettergrade='B';
else if (total_gradevalue>=70)
lettergrade='C';
else if (total_gradevalue>=60)
lettergrade='D';
else if (total_gradevalue>=50)
lettergrade='F';
//Shows Output of Information Entered (5) of one student
JOptionPane.showMessageDialog
(null, "Student: " + secondname + " , " + firstname +
"\nMid-Term Points Earned: " + midterm_gradevalue +
"\nFinal Points Earned: " + final_gradevalue +
"\nTotal Points Earned: " + total_gradevalue +
"\nGrade Assigned: "+ lettergrade,
"\n STUDENT ID #: " + studentid,
JOptionPane.PLAIN_MESSAGE);
/*Askes user whether or not to input an additional student*/
option = JOptionPane.showInputDialog("Enter < 0 > to input a student. \nEnter < -1 > to quit. ");
//converts string input into integer loop
loop = Integer.parseInt( option );
listings +="Student ID #: " + studentid +
"\n [ " + secondname + ", " + firstname + " ] " +
"\n Midterm Points Earned: " + midterm_gradevalue +
"\n Final Points Earned: " + final_gradevalue +
"\n Total Points Earned: " + total_gradevalue +
"\n**********Grade Assigned: "+ lettergrade + "\n";
} while ( loop !=-1);
JOptionPane.showMessageDialog(
null, listings,
"Class Results: ",
JOptionPane.PLAIN_MESSAGE);
System.exit ( 0 );
}//end of programming method
}//end of class definition

You should use a List instead, it will be more maintainable if you want this program to work for more students, without having to edit the souce:
List students = new ArrayList(); // Create a List
// To add students
students.add(student);
// To iterate through them
Iterator it = students.iterator();
while(it.hasNext)
Student s = (Student)it.next();
// For direct access
Student s = (Student)students.get(index);
class Student extends Object
private String firstName;
private String secondName;
private String id;
private String midtermGrade;
private String finalGrade;
public Student()
// Add a setter/getter for each variable
also override toString()
now with this bean, you could open an option pane passing a JList that was create with the passed in List

Similar Messages

  • A quick Array Problem

    hey all,
    i'm having a dumb array problem, I cannot figure out what I've done wrong !
    I've set up an empty array of JButtons (because that '4' is actually a variable in my code)
    HERE IS THE CODE
    //===========================
    JButton[] buttons = new JButton[4] ;
    for (int g = 0; g < 4; g++)
    Imag[g].setIcon(imageIcons[g]);     
    buttons[g].setEnabled(true);
    System.out.print (buttons[g] + " " + g + "\n");
    //===========================
    My Error is a null pointer exception. And when I take out the:
    buttons[g].setEnabled(true);
    line, I just get the ouput, and it is:
    null 0
    null 1
    null 2
    null 3
    Ok, I know I'm probably making one dumb little mistake, but I have no idea what it is right now, Please Help !! thanks,
    Kngus

    When you want to use an array, you declare it (which you did), construct it (which you did), and initialize it (which the VM did). When you initialize an array of primitives, the primitives get their default value (0 for signed int types, 0.0 for float types, false for boolean, null-character for char) and so do object references (null).
    You are setting up an array of object references. When the VM initializes it, the elements of the array (i.e. the references to the JButtons) are set to null. That's why you're getting the NullPointerException. You need additional code, something along the lines of this:
    for(int j = 0; j < buttons.length(); j++) {
        buttons[j] = new JButton();
    }Now, your buttons array will contain references to JButtons rather than null.
    AG

  • Transposin​g Array Problem

    I need to get the information from a table which has been populated at an earlier point in the program, and convert it to numbers, and then break it up into its individual elements. Both ways of doing this in my attached vi work, but the one method throws three 0's in between columns, when I resize the 2D array to 1D. Any idea why? Is there an easier way to go about this?
    Thanks, Geoff
    Attachments:
    Array Problem.vi ‏26 KB

    Your original table contains 3 extra row which generate 3 rows of zeroes. Your 2D array actually contains 35 elements. the reshape function truncates to 20 elements. After transposing, you throw away nonzero elements while before rehshaping all zeroes are in the tail giving the false apperance of correct behavior.
    The attached modification gives you a button to fix the table size so it works correctly.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ArrayProblemMOD.vi ‏41 KB

  • Having problem implementing array in code?

    I am trying to write a code that will ask the user to either enter in a name of a reds baseball player, a batting average, or a slugging percentage. When this is entered the name of that corresponding player will pop up along with his stats. The code that I have so far is written below. I just need help in the three areas of my if statements so that if the user types in a name, average, or slug percentage then that player and stats will come up from the file in my program(stats.txt).
    import javax.swing.*;
    import java.io.*;
    public class BattingStats
    public static void main(String[]args) throws IOException
    String option=selectOption("Select a search option"))
    getPlyrName();
    //need help here?
    if(option.equals("listBatAvg"))
    //need help here?
    if(option.equals("listSlug"))
    //need help here?
    private static void readSomeLines() throws IOException
    String filename="stats.txt";
    FileReader fr=new FileReader( filename);
    BufferedReader br=new Buffered Reader (fr);
    String sLine=br.readLine();
    while (sLine != null)
    String[] stats = sLine.split("\t");
    sLine=br.readLine();
    br.close();
    public static String selectOption (String prompt)
    String option=" ";
    int choice= JOptionPane.showOptionDialog(null, prompt, "Cinncinnati Reds player stats", JOptionPane.DEFAULT_OPTION, new Object[]
    "Search for a particular players stats", "List stats in decending order based on slugging percentage"
    if (choice==0)
    option="searchPlyr";
    if(choice==1)
    option="listBatAvg";
    if(choice==2)
    option="listSlug";
    return option;
    public static String getPlyrName () throws IOException
    String name=JOptionPane.showInputDialog(null, "Enter players name?");
    return name;
    }

    I assume that there will be more than one line in each txt file. Your code appears to loop through the file lines but does nothing with them. I think you need something like:
    import java.util.ArrayList;
    ArrayList allResults = new ArrayList();   //Declared at the top of your program
    allResults.add(stats);
    I reproduce your code below with some amendments.  I think you would have a hard time compiling this without my amendments.  I am not sure about some of the details but atleast it will now compile.  You should compile and run your code regularly so that you only have one or two errors to deal with.  You should add occasional System.out.println("Message") statements to help you understand what the code is doing.  You can comment them out when you are confident.
    import javax.swing.*;
    import java.io.*;
    public class BattingStats
         public static void main(String[]args) throws IOException
              // OK Java is object oriented so get rid of static and
              // create a BattingStats object
              BattingStats b = new BattingStats();
         public BattingStats()
              String player = "";
              String option=selectOption("Select a search option"); //Removed surplus bracket
              try
                   player = getPlyrName();
              catch (IOException ioe)
                   System.out.println("Error in getting Player name");
                   System.out.println("Program terminating");
                   System.exit(1);
                   //need help here?     <<< Sort out file reading first
              if(option.equals("listBatAvg"))
                   //need help here?
              if(option.equals("listSlug"))
                   //need help here?
         private void readSomeLines() throws IOException    // Static removed
              String filename="stats.txt";
              FileReader fr=new FileReader( filename);
               //BufferedReader br=new Buffered Reader (fr);
              BufferedReader br=new BufferedReader (fr);
              String sLine=br.readLine();
              while (sLine != null)
                   String[] stats = sLine.split("\t");
                   sLine=br.readLine();
                   //The above is fine but surely you have more than one line
                   //if so your data is being read and dropped.
                   // I guess you need to create an ArrayList and add each
                   // stats line to it
              br.close();
         public String selectOption (String prompt)   //Static removed
              String option=" ";
              //int choice= JOptionPane.showOptionDialog(null, prompt, "Cinncinnati Reds player stats", JOptionPane.DEFAULT_OPTION, new Object[]
              //"Search for a particular players stats", "List stats in decending order based on slugging percentage"
              String[] optionArray = {
                        "Player stats",
                        "Batting average",
                        "Slugging percentage"
              int choice= JOptionPane.showOptionDialog(
                        null,
                        prompt,
                        "Cinncinnati Reds player stats",
                        JOptionPane.DEFAULT_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        optionArray,
                        optionArray[1]
              if (choice==0)
                   option="searchPlyr";  //Where is this used
              if(choice==1)
                   option="listBatAvg";
              if(choice==2)
                   option="listSlug";
              return option;
         public String getPlyrName () throws IOException   //Static removed
              String name=JOptionPane.showInputDialog(null, "Enter players name?");
              return name;
    }Please note that by highlighting the code and pressing the code button it keeps the formatting. This is why you can see the indents above.

  • MS Office Report Express VI and Array Problem

    Hello all,
    I have a strange issue with the MS Office Report VI that's included with the Report Generation Toolkit. I created an Excel template which I linked using the "Custom template for Excel" preference and applied all the named ranges. However, two of the named ranges that I am inputting are 1D Arrays of doubles. Now the problem:
    When I input the arrays to their specific name range (it's only 6 values), instead of inputting just the array values into the cells, it inputs like this:
    0    Value
    1    Value
    2    Value
    6    Value
    It pushes the "Value" to the column next to the name range because of the 0-6.
    It does this with both arrays so it screws up all the formulas. Any one know how to remove the 0-6 and just input the values?
    Thanks all 
    Solved!
    Go to Solution.

    Greetings, I wrote a program that generates an array of data and stores a data table, just as a chart, just starting to program, I hope that my program can be useful
    Atom
    Certified LabVIEW Associate Developer
    Attachments:
    write_excel.vi ‏60 KB

  • Assigning value to a two-dimensional byte array - problem or not?

    I am facing a really strange issue.
    I have a 2D byte array of 10 rows and a byte array of some audio bytes:
    byte[][] buf = new byte[10][];
    byte[] a = ~ some bytes read from an audio streamWhen I assign like this:
    for (int i=0; i<10; i++) {
        a = ~read some audio bytes // this method properly returns a byte[]
        buf[i] = a;
    }the assignment is not working!!!
    If I use this:
    for (int i=0; i<10; i++) {
        a = ~read some audio bytes
        for (int j=0; j<a.length; j++) {
            buf[i][j] = a[j];
    }or this:
    for (int i=0; i<10; i++) {
        System.arraycopy(a, 0, buf, 0, a.length);
    }everything works fine, which is really odd!!
    I use this type of value assignment for the first time in byte arrays.
    However, I never had the same problem with integers, where the problem does not appear:int[] a = new int[] {1, 2, 3, 4, 5};
    int[][] b = new int[3][5];
    for (int i=0; i<3; i++) {
    b[i] = a;
    // This works fineAnybody has a clue about what's happening?
    Is it a Java issue or a programmers mistake?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Back again! I'm trying to track down the problem.
    Here is most of my actual code to get a better idea.
    private void test() {
         byte[][] buf1 = new byte[11][];
         byte[][] buf2 = new byte[11][];
         AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(audioFile);
         byte[] audioBytes = new byte[100];
         int serialNumber = 0;
         while (audioInputStream.read(audioBytes) != -1) {
              if (serialNumber == 10) {
                   serialNumber = 0; // breakpoint here for debugging
              // Fill buf1 -- working
              for (int i=0; i<audioBytes.length; i++) {
                   buf1[serialNumber] = audioBytes[i];
              // Fill buf2 -- not working
              buf2[serialNumber] = new byte[audioBytes.length];
              buf2[serialNumber] = audioBytes;
              serialNumber++;
    }I debugged the program, using a debug point after taking 10 "groups" of byte arrays (audioBytes) from the audio file.
    The result (as also indicated later by the audio output) is this:
    At the debug point the values of buf1's elements change in every loop, while buf2's remain unchanged, always having the initial value of audioBytes!
    It's really strange and annoying. These are the debugging results for the  [first|http://eevoskos.googlepages.com/loop1.jpg] ,  [second|http://eevoskos.googlepages.com/loop2.jpg]  and  [third|http://eevoskos.googlepages.com/loop3.jpg]  loop.
    I really can't see any mistake in the code.
    Could it be a Netbeans 6.1 bug or something?
    The problem appears both with jdk 5 or 6.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • RAID 5 array problem

    Hi,
    I've a problem arising from the replacement of a drive in a Proliant ML370 G3 RAID 5 array.
    What happened is one disc in the array failed. I replaced it and selected the "F1" rebuild option. The system then appeared to start the rebuild, both the green arrow and the green HD icon on the replaced disc flashing. However, when I returned to the server, over a week later, I found that the HD light had gone out but the green arrow continued to flash on occasion. I had expected the HD icon to remain illuminated and the arrow to flash every so often. When I checked in Disc Manager (Windows 2003 Server) this reported that although both partitions allocated to the array were healthy, there was no fault tolerance. I have since rebooted the server which then responded that the same disc had failed and presented me with a rebuild option.
    I've now tried to rebuild this array three times without success, the result being the same each time I try. What am I missing?
    I'd appreciate any suggestions
    Phil

    You gave a very nicely detailed list of datum ... thanks, that's rare!
    Now ... one other bit ... you mention media being on the Thunderbolt RAID5 ... is everything there, including cache/database/previews/project-file, or just the media? I know that if say everything else was on the system drive, this would probably happen ... the media is the 'easiest' part of the disc-in/out chain as it's mostly "simple" reading of files, those other things are heavy read/write items. I'm assuming you've probably put most of it on that RAID, as the folks on the Tweaker's Page would oft posit.
    Neil

  • NULL ARRAY PROBLEM... in DOCUMENT/LITERAL type web service

    let method signature is like this,
    public int ABC(String[] a);
    i am sending an null array from client side, like
    ABC(null);
    but on web service layer i am getting an array with length 1
    and element of this array is null.
    for example, {null} where i should get simple null, not an array with null element.

    My guess is that it is because .NET defaults to generating a document style interface whereas JDeveloper defaults to generating an RPC style interface. The end result is that JDeveloper wraps the document interface in something that looks document like - thus your client. To see how to handle this right now, check out this sample - you have to parse the XML:
    http://otn.oracle.com/tech/webservices/htdocs/series/net/content.html
    In the preview of JDeveloper 9.0.3 which is due quite soon - next few weeks roughly (crossing my fingers) - JDeveloper will wrap .NET document based Web services in a much more elegant wrapper - giving you exactly what you are looking for - a method called Validate rather than a vector of Elements.
    What I don't understand in your sample, however, is that you have WSDL generated from JDeveloper versus WSDL generated from .NET. Did you also do an implementation of the validate method in Java too?
    Mike.

  • Object Array problem in Websphere WebServices

    Hi,
    Can someone help me out with a situation that I am stuck with in WebServices.
    I have a WebService which returns a DTO which has a getter and setter for an array of another type of DTO object.
    Sample:-
    public class MyDTO extends AnotherDTO implements Serializable {
    private InnerDTO qcDtoList[] = new InnerDTO[0];
    public MyDTO() {
    public InnerDTO[] getQcDtoList() {
    return qcDtoList;
    public void setQcDtoList(InnerDTO[] resEDXDTOs) {
    qcDtoList = resEDXDTOs;
    But when I generate the WSDL for the webservice using WSAD 5.1 that uses the above DTO, the server side generated skeleton file looks like:-
    public class MyDTO extends AnotherDTO implements java.io.Serializable {
    private InnerDTO[] qcDtoList;
    public MyDTO() {
    public InnerDTO[] getQcDtoList() {
    return qcDtoList;
    public void setQcDtoList(InnerDTO[] qcDtoList) {
    this.qcDtoList = qcDtoList;
    As you can see from above, my initialization info is not available in the generated skeleton. I also tried putting the initialization in the constructor, with no effect.
    What could be the reason for this? And is it possible to initialize my InnerDTO without losing it in the generated skeleton?
    I simply want to initialize the object array.
    If I need to modify my WSDL, what additional annotations should I add on the WSDL to get the desired effect?
    I use WSAD's (Websphere Studio App Developer) IBM Websphere Webservices protocol and the JDK version is 1.3.1 and WSAD version is 5.1.
    I would really appreciate if you can throw light on this?
    Thanx and Regds,
    Prashanth.

    Thank you for the quick response. I looked at the example you suggested and made the following changes. Now I'm receiving an "Invalid datatype" error on the "SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer))" statement. I must be missing something simple and I just can't put my finger on it.
    PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
    v_categories IN ARCHIVE.integer_aat,
    rs OUT RSType)
    AS
    /* PURPOSE: Return Search Results for the Category and Keyword Provided
    VARIABLES:
    v_categories = Document Categories array entered
    v_term = Keyword entered
    rs = Result Set
    TYPE tbl_integer IS TABLE OF INTEGER;
    tbl_cat tbl_integer;
    BEGIN
    FOR i IN 1 .. v_categories.COUNT
    LOOP
    tbl_cat.EXTEND(1);
    tbl_cat(i) := v_categories(i);
    END LOOP;
    OPEN rs FOR
    SELECT A.ID,
    B.CATEGORY,
    A.FILENAME,
    A.DISPLAY_NAME,
    A.COMMENTS
    FROM TBL_ARCHIVE_DOCUMENTS A,
    TBL_ARCHIVE_DOC_CAT B,
    TBL_ARCHIVE_DOC_KEYWORDS C
    WHERE A.ID = B.ID
    AND A.ID = C.ID
    AND B.CATEGORY IN (SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer)))
    AND C.KEYWORD = v_term
    ORDER BY A.ID;
    END SEL_SEARCH_RESULTS;

  • Associative Array problem in Oracle Procedure

    Hi,
    I've searched through the internet and this forum and haven't been able to resolve a problem using associative array values within an IN clause. Everything I've read states that I can't use the associative array directly in the SQL statement. I have to convert it to a table and then I can use it. Unfortunately, I'm receiving an "ORA-21700: object does not exist or is marked for delete" error when trying to access the table I've populated from the array. Please note that I have verified the table is actually being populated during the loop. I'm catching the error when referencing it in the SELECT statement.
    I've declared the following in the ARCHIVE package specification:
    TYPE RSType IS REF CURSOR;
    TYPE integer_aat IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
    TYPE integer_table IS TABLE OF INTEGER;
    The procedure is as follows:
    PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
    v_categories IN ARCHIVE.integer_aat,
    rs OUT RSType)
    AS
    /* PURPOSE: Return Search Results for the Category and Keyword Provided
    VARIABLES:
    v_categories = Document Categories array
    v_term = Keyword entered
    rs = Result Set
    tbl_cat ARCHIVE.integer_table := ARCHIVE.integer_table();
    BEGIN
    FOR i IN 1 .. v_categories.COUNT
    LOOP
    tbl_cat.EXTEND(1);
    tbl_cat(i) := v_categories(i);
    END LOOP;
    OPEN rs FOR
    SELECT A.ID,
    B.CATEGORY,
    A.FILENAME,
    A.DISPLAY_NAME,
    A.COMMENTS
    FROM TBL_ARCHIVE_DOCUMENTS A,
    TBL_ARCHIVE_DOC_CAT B,
    TBL_ARCHIVE_DOC_KEYWORDS C
    WHERE A.ID = B.ID
    AND A.ID = C.ID
    AND B.CATEGORY IN (SELECT * FROM TABLE(tbl_cat))
    AND C.KEYWORD = v_term
    ORDER BY A.ID;
    END SEL_SEARCH_RESULTS;
    Any help would be greatly appreciated and thanks in advance,
    Matt

    Thank you for the quick response. I looked at the example you suggested and made the following changes. Now I'm receiving an "Invalid datatype" error on the "SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer))" statement. I must be missing something simple and I just can't put my finger on it.
    PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
    v_categories IN ARCHIVE.integer_aat,
    rs OUT RSType)
    AS
    /* PURPOSE: Return Search Results for the Category and Keyword Provided
    VARIABLES:
    v_categories = Document Categories array entered
    v_term = Keyword entered
    rs = Result Set
    TYPE tbl_integer IS TABLE OF INTEGER;
    tbl_cat tbl_integer;
    BEGIN
    FOR i IN 1 .. v_categories.COUNT
    LOOP
    tbl_cat.EXTEND(1);
    tbl_cat(i) := v_categories(i);
    END LOOP;
    OPEN rs FOR
    SELECT A.ID,
    B.CATEGORY,
    A.FILENAME,
    A.DISPLAY_NAME,
    A.COMMENTS
    FROM TBL_ARCHIVE_DOCUMENTS A,
    TBL_ARCHIVE_DOC_CAT B,
    TBL_ARCHIVE_DOC_KEYWORDS C
    WHERE A.ID = B.ID
    AND A.ID = C.ID
    AND B.CATEGORY IN (SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer)))
    AND C.KEYWORD = v_term
    ORDER BY A.ID;
    END SEL_SEARCH_RESULTS;

  • I've had this 2D array problem for ages and would apprecoate any help :)

    I've posted a few times about this in the past and with your guys help I have gradually advanced.
    Basically, all I want to do at the moment is fill the lowest position a counter can go in in a game of Connect Four.
    The first counter goes to the bottom, then if you place another counter in the same column it goes above the previous counter you put in that same column and so on...
    I have set up my 2D array and initialised integers for each player so when a counter is red the player = 1 and when yellow player = 2.
    Here is my code...
    CircleGrid [][] cArray = new CircleGrid[col][row]; //Declare array
    static final int row = 6;
    static final int col = 7;
    for (int i = 0; i < col; i++)
                        for (int h = 0; h < row; h++)
                             cArray[i][h] = new CircleGrid();
                             gameCenter.add(new CircleGrid());
                   JOptionPane.showConfirmDialog(game, "Welcome to Frenzy Fours. Press 'OK to begin or 'Cancel' to go back.", "Game", JOptionPane.OK_CANCEL_OPTION);
                   /*if (cArray[col-1][row] && cArray[col-2][row] == 1) //This doesn't work at all...array out of bounds !?
                        System.out.println("testing");
    public class CircleGrid extends JPanel implements MouseListener, MouseMotionListener
             int ifRed;
             int notIfRed;
                 boolean ifEmpty;
              String currentColour = "White";
              final int empty = 0;
              final int competitorOne = 1;
              final int competitorTwo = 2;
                 public CircleGrid()
                   ifRed = 1;
                   notIfRed = 0;
                   int redCircles = 0;
                   int yellowCircles = 0;
                   ifEmpty = true;
                   addMouseListener(this);
                 public void alternateColour()
                   ifEmpty = !ifEmpty;
                   repaint(); //Repaint upon changes
                 public void paintComponent(Graphics g)
                 if (ifEmpty)
                   g.setColor(Color.WHITE); //Set all of the ovals to white
             else if (ifRed == clicks)
                   position--;
                   addMouseListener(this);
                    g.setColor(Color.RED); //Paint red
                    currentColour = "Red";
                    System.out.println(getColour());
                    System.out.println(playerOneMove());
              else if (notIfRed == clicks)
                   addMouseListener(this);
                   g.setColor(Color.YELLOW); //Paint yellow
                   currentColour = "Yellow";
                   System.out.println(getColour());
                   System.out.println(playerTwoMove());
                   g.fillOval(5, 10, 42, 42); //Draw and fill oval
                 public String getColour()
                   return currentColour;
              public int playerOneMove()
                   return competitorOne;
              public int playerTwoMove()
                   return competitorTwo;
                 public void mousePressed(MouseEvent ev)
                   alternateColour(); //Use commands from this method
                   if (clicks == 0)
                        clicks = 1;
                        repaint(); //Paint oval red
                        number--; //Decrement number of counters left by 1
                         counterNo1.setText(number + " counters left.");
                         move++;
                         moveCount1.setText(move + " moves.");
                   else if (clicks > 0)
                        clicks = 0;
                        repaint(); //Paint oval yellow
                        number2--;
                         counterNo2.setText(number2 + " counters left.");
                        move2++;
                         moveCount2.setText(move2 + " moves.");
                 }I think that is all of the code which matters for this!
    I didn't choose to do this project and it is really stressing me out! If anybody could give me a nudge in the right direction (in really simple steps) that would be awesome. I appreciate you guys do this voluntarily (and for some even work) so I would be deeply grateful for any assistance in this matter.
    Thank you. :)
    - Jay
    Edited by: Aurora88 on Mar 5, 2008 7:18 AM

    public class CircleGrid extends JPanel implements MouseListener, MouseMotionListener
             int ifRed;
             int notIfRed;
                 boolean ifEmpty;
              String currentColour = "White";
              final int empty = 0;
              final int competitorOne = 1;
              final int competitorTwo = 2;
              static final int row = 6;
              static final int col = 7;
              Circle [][] cArray = new Circle[col][row]; //Declare array
              Circle circle = new Circle(0,0);
                 public CircleGrid()
                   ifRed = 1;
                   notIfRed = 0;
                   int redCircles = 0;
                   int yellowCircles = 0;
                   ifEmpty = true;
                   addMouseListener(this);
                 public void alternateColour()
                   ifEmpty = !ifEmpty;
                   repaint(); //Repaint upon changes
                 public void paintComponent(Graphics g)
                 if (ifEmpty)
                   g.setColor(Color.WHITE); //Set all of the ovals to white
             else if (ifRed == clicks)
                   position--;
                   addMouseListener(this);
                    g.setColor(Color.RED); //Paint red
                    currentColour = "Red";
                    System.out.println(getColour());
                    System.out.println(playerOneMove());
              else if (notIfRed == clicks)
                   addMouseListener(this);
                   g.setColor(Color.YELLOW); //Paint yellow
                   currentColour = "Yellow";
                   System.out.println(getColour());
                   System.out.println(playerTwoMove());
                   g.fillOval(5, 10, 42, 42); //Draw and fill oval
                 public String getColour()
                   return currentColour;
              public int playerOneMove()
                   return competitorOne;
              public int playerTwoMove()
                   return competitorTwo;
                 public void mousePressed(MouseEvent ev)
                   alternateColour(); //Use commands from this method
                   if (clicks == 0)
                        clicks = 1;
                        repaint(); //Paint oval red
                        number--; //Decrement number of counters left by 1
                         counterNo1.setText(number + " counters left.");
                         move++;
                         moveCount1.setText(move + " moves.");
                   else if (clicks > 0)
                        clicks = 0;
                        repaint(); //Paint oval yellow
                        number2--;
                         counterNo2.setText(number2 + " counters left.");
                        move2++;
                         moveCount2.setText(move2 + " moves.");
                   for (int i = 0; i < col; i++)
                        for (int h = 0; h < row; h++)
                             cArray[i][h] = new Circle();
                             gameCenter.add(cArray[i][h]);
                   System.out.println("LOCATION");
                   System.out.println("Row: " + circle.getRow());
                   System.out.println("Col: " + circle.getCol());
                 public void mouseClicked(MouseEvent ev)
                 public void mouseReleased(MouseEvent ev)
                   if (number < 0)
                        JOptionPane.showMessageDialog(game, "Error! You have no counters left.", "Error 001", JOptionPane.ERROR_MESSAGE);
                        System.out.println(countersGone()); //Display error when all counters are used
                        number = 22; move = 0; number2 = 22; move2 = 0;
                        counterNo1.setText(number + " counters left.");
                        moveCount1.setText(move + " moves.");
                        counterNo2.setText(number2 + " counters left.");
                        moveCount2.setText(move2 + " moves.");
                        clicks = 0;
                        game.dispose();
                 public void mouseEntered(MouseEvent ev)
                 public void mouseExited(MouseEvent ev)
                 public void mouseMoved(MouseEvent ev)
                 public void mouseDragged(MouseEvent ev)
                 public int getClickCount()
                   return clicks; //Record number of mouse clicks
                 public int getCounterNumber(int numberP1)
                      numberP1 = number; //Assigned number to numberP1
                      return number;
              public int getCounterNumber2(int numberP2)
                   numberP2 = number;
                   return number2;
              public int moveCounter1(int counterOne)
                   counterOne = move;
                   return move;
              public int moveCounter2(int counterTwo)
                   counterTwo = move2;
                   return move2;
                 public String countersGone()
                   return "You have used up all of your counters!";
         class Circle
             int rowNum, colNum;
             boolean occupied;
             String color;
        public Circle(int r, int c)
              rowNum = r;
              colNum = c;
              occupied = false;
        public int getRow()
              return rowNum;
        public int getCol()
              return colNum;
    }new Circle - cannot find symbol
    gameCenter.add - cannot find symbol
    Circle has been declared so I don't know why this is happening. :S

  • Converting bytes to character array problem

    I am trying to convert a byte array into a character array, however no matter which Character Set i choose i am always getting the '?' character for some of the bytes which means that it was unable to convert the byte to a character.
    What i want is very simple. i.e. map the byte array to its Extended ASCII format which actually is no change in the bit represtation of the actual byte. But i cannot seem to do this in java.
    Does anyone have any idea how to get around this problem?

    Thanks for responding.
    I have however arrived at a solution. A little un-elegant but it seems to do the job.
    I am converting each byte into char manually by this algorithm:
              for (int i=0;i<compressedDataLength;i++)
                   if (((int) output)<0)
                        k=(127-((int) output[i]));
                        outputChr[i]=((char) k);
                   else
                        k=((int) output[i]);
                        outputChr[i]=((char) k);
                   System.out.println(k);
    where output is the byte array and outputChr is the character array

  • Array problem (empty).

    Hi everybody,
    I'm using Crystal X and I have the following query
    IdField          Field1             Field2
    1                  CCC                8
    1                  GGG               3
    1                  DDD                2
    2                  AAA                7
    I want the following output
    IdField
    1               CCC GGG DDD    Field2 define different format to Field1 (different background color)
    2               AAA
    My report is grouped by IdField. As the output for Field1 has a different format depending on Field2. I want to write the Field1+Field2 values for each IdField in an Array, I have the following formulas, but the array looks empty, I have changed the array declaration as global and still is empty
    Section: ReportHeader
    Formula InitArray
                 shared stringvar Array DataArray;
                 redim DataArray[30];
    Section: Details (Suppresed)
    Formula AddDataToArray
                shared numbervar iCounter;
                shared stringvar Array DataArray;
                iCounter := iCounter + 1;
                DataArray[iCounter] := {Command.Field1} + "-" +  {Command.Field2};                                             
    Section: Footer Group1a
    Formulla FillTextFromArray
                shared numbervar sDataVal;
                shared stringvar Array DataArray;
                sDataVal := DataArray[1];  //DataArray[1] shoud be = "CCC-8"
                left(sDataVal, len(sDataVal)-2);
                {@DisplayData1}= DataArray[1]; //This is my problem the array is empty
    Section: Footer Group1b
    Display the following data
    IdField     @DisplayData1  @DisplayData2  @DisplayData3 ...
    I added 50 formulas to display each Field1 value with different formats. I know these columns are fixed, but I coudn't find any other way.
    I have 3 question:
    ??? What is wrong on my array than in formula "FillTextFromArray" is empty???
    ??? Is there another way to refence a formula or a text object different than FormulaName or TextObjectName???, like an object array or something, because I will be dealing with 50 formulas to write the value and to change the format
    ??? How to make reference to a text object, in case I would change the 50 formulas by 50 text objects
    Please help with any of the 3 questions or any ideas to make the report
    thanks
    cc

    You can try another way like
    create anew formula @Initialize
    whileprintingrecords;
    stringvar str:="";
    Now place this in group header of IDField
    Now Create another formula @Evaluate
    whileprintingrecords;
    stringvar str;
    str:=str" ";
    Place this in detail section
    Create another formula like @Display
    whileprintingrecords;
    stringvar str;
    place this in group footer of IDFIeld and right click on this formula and go to format field and check the option "can grow".
    Now you can suppress the sections group header and details section to show the values in a single line in each group footer.
    Hope this helps!
    Raghavendra

  • Mathscript Array -problem

    Dear Friends,
    I am reading the serial port data data , byte by byte..I used serial port vi and math-script in it ....
    And these  serial data are sent in a format like below........
    format:  HEADER ,  MSB  , DATA ,  CHECKSUM..
    I need to collect these bytes and plot it on the graph.. I have problem with saving these data in an array and processing it....
    below is the code,which i had written to do the process
     persistent  ubIndex = 0
     persistent  bHeader = 0
    ubTemp=input
     if bHeader ==0
                     if ubTemp == 89
                            ubIndex= 0
                            bHeader = 1                              
                       end
    else
                  ubIndex= ubIndex +1
                  ubReceivedata(ubIndex) = ubTemp      
                   if  ubIndex == 3
                           ubIndex = 0
                           bHeader = 0               
                     end
    end      
     ubChecksum = ubRecieveData(1) + ubRecieveData(2) + ubRecieveData(3)
    if   ubChecksum == 0
                   if ubRecieveData(1) == 76
                            duLen1 = ubRecieveData(2)
                                 elseif   ubRecieveData(1) == 69
                                        duLen2 = ubRecieveData(2)
                                 elseif   ubRecieveData(1) == 78
                                           duLen3 = ubRecieveData(2)
                                   elseif ubRecieveData(1) == 71
                                                duLen4 = ubRecieveData(2)
                                                duLength = duLen1 * 16777216 + duLen2 * 65536 + uwLen3 * 256 +  ubLen4 
                                  elseif   ubRecieveData(1) == 80
                                               uwTemp1 = ubRecieveData(2);
                                   elseif  ubRecieveData(1) == 66
                                                ubTemp2 = ubRecieveData(2);                 
                                                uwpackageSpeed = uwTemp1 * 256 + ubTemp2;
                                     elseif  ubRecieveData(1) == 68
                                              uwTemp1 = ubRecieveData(2);
                                     else  ubRecieveData(1) == 65
                                              ubTemp2 = ubRecieveData(2);                 
                                             uwDrumSpeed = uwTemp1 * 256 + ubTemp2;
                       end
    end
    In the above program,i collected 2nd, 3rd,4th byte in the ubRecieveData array  and i left the 1st byte(which is header)...
    and I find the checksum by adding the 2nd,3rd,4th byte to find whether it is zero or not,
    if it is zero ,then the received bytes are correct...and it will proceed to take only the data bytes...and i will plot it on the chart...
    I have a doubt in the ubrecievedata array..whether it is collecting the 3 bytes data or not......whether array  get's initliazed every time in the script..
    since it doesn't get in to the if-loop checksum and loop further.....
    I even removed the if-loop checksum ,to collect and process the data inside the loop below if-loop checksum..but it's not working ...
    will the above script are correct..... .....?suggest some solutions to get working
    i attached my  program vi..for u to get feel of my problem...
    regards
    rajasekar
    Attachments:
    vjnewsamp.vi ‏319 KB

    Hi Grant,
    I did as u told u,still unable to process the data and plot it on the chart.....
    I attached my program  testing20.vi ....for finding the problem..
    could u please see the vi..and suggest some solutions....
    As u said  the array should also be persistent.....and my doubt is the other variable like dulen1,dulen2,dulen3,dulen4,...should also be persistent...in order to calculate the parameter
    duLength,.......similarly the parameter uwpackagespeed and uwdrumspeed should be persistent.(in my point of view....)
    objective of the program is to read the serial port byte and byte ...and plotting it
    And the byte are sent in format like
    format: Header , MSB ,data,checksum..
                 Header, LSB ,data,checksum..
    so i need to recogize this format in my mathscript node ...the main thing is ,...... in 4 bytes the data is only of 1byte....
    In my program , i am plotting length(x-axis) versus packagespeed and drumspeed(y-axis)..
    here the length parameter itself 4 byte of data.....i have to collect it byte by byte of data ,...from the 4 byte format(math script gets called 16 times to collect these 4 data bytes
     from 4 byte format)...        and packagespeed and drumspeed is of 2 byte.......
    if u have any questions please ask me...
    Eagerly awaiting for ur reply....
    Regards
    rajasekar
    Attachments:
    testing21.vi ‏442 KB

  • Regex and implementing FilenameFilter problem

    Hello,
    So what I'm trying to do is to create a program that takes a certain set of files, pulls the first line of each file and uses it to name the file. Right now, I'm at the point of getting a listing of files based on a patterns. So when I run the program on the command line (of a windows machine), it spit out the files that I'm looking for. Something like:
    java FileRenamer *.txt
    Above should produce a listing of only files that have .txt on them (I want to have the capability to choose *.txt or whatever other combination of pattern match).
    To do the above, I want to use a FileNameFilter interface to figure out what files match. The problem that I'm running into is that when I run a unit test against the getFilesListBasedOnPattern method, I get:
    java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
    *.txt
    The problem is that the *.txt has a regex character (the *) and I'm not sure how make it behave like the wildcard in the dos command line where *.txt means everything that has .txt at the end.
    The code listing is below. Does anyone have any suggestions on how to best approach this?
    mapsmaps
    =======> Code below <=======
    // unit test snippet that causes blow out:
    FileRenamer fr = new FileRenamer();
    String [] strArrFilesBasePattern = fr.getFilesListBasedOnPattern(dirTestFiles,"*.txt");
    ====
    //main program
    package com.foo.filerenamer;
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Vector;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    * TODO Use regexp to filter out input to *.txt type of thing or nothing else
    public class FileRenamer
        // Vallid file patterns are *.*, ?
        public static final String strVALIDINPUTCHARS = "[_.a-zA-Z0-9\\s\\*\\?-]+";
        private static Pattern regexPattern = Pattern.compile(strVALIDINPUTCHARS);
        private static Matcher regexMatcher;
         * @param args
         * @throws InterruptedException
        public static void main(String[] args) throws InterruptedException
            int intMillis = 0;
            if (args.length > 0)
                try
                    intMillis = Integer.parseInt(args[0]);
                    System.out.println("Sleep set to " + intMillis + " seconds");
                catch (NumberFormatException e)
                    intMillis = 5000;
                    System.out.println("Sleep set to default of " + intMillis + " since first parameter was non-int");
                for (int i=0;i<args.length;i++)
                    System.out.println("hello there - args["+i+"] = "+ args);
    Thread.sleep(intMillis);
    // TODO Auto-generated method stub
    public boolean checkArgs(String [] p_strAr)
    boolean bRet = false;
    if (p_strAr.length != 1)
    return false;
    else
    regexMatcher = regexPattern.matcher(p_strAr[0]);
    bRet = regexMatcher.matches();
    return bRet;
    public String[] getFilesListBasedOnPattern(File p_dirFilesLoc, String p_strValidPattern)
    String[] strArrFilteredFileNames = p_dirFilesLoc.list(new RegExpFileFilter(p_strValidPattern));
    return strArrFilteredFileNames;
    class RegExpFileFilter implements FilenameFilter
    private String m_strPattern = null;
    private Pattern m_regexPattern;
    public RegExpFileFilter(String p_strPattern)
    m_strPattern = p_strPattern;
    m_regexPattern = Pattern.compile(m_strPattern);
    public boolean accept(File m_directory, String m_filename)
    if (m_regexPattern.matcher(m_filename).matches())
    return true;
    return false;

    I am doing something similar but have a problem with Java automatically converting wildcards in path-arguments to the first match (!).
    It seems the JVM is applying some intelligence here and checks if a path is passed to main() and if so, it automatically resolves wildcards (also quotes are escaped/resolved), which is pretty annoying and not what I want, since I do never see the original parameters this way:(
    Is there a way to get the original parameters without the JVM intervening / "helping"?
    Any help would be appreciated, as I want my utility to act just like any other shell-program...

Maybe you are looking for

  • IPod mounts on desktop but not in iTunes

    The problem started with a system extension error message (below). From an old posting elsewhere it is suggested that an errant DiskWarrior icons file gets inserted in the IOStorageFamily.ktext file, causing mount problems with USB devices. It happen

  • Cost in explain plan vs elapsed time

    hi gurus, i have two tables with identical data volume(same database/schema/tablespace) and the only difference between these two is, one partitioned on a date filed. statistics are up to date. same query is executed against both tables, no partition

  • ARA: Excluded Roles considered for Risk Analysis???

    Hi, There are certain role which are to be excluded from risk analysis or some business reasons. To achieve this, I have added entries for these roles in SPRO and saved them. Actually, these roles are available in all the systems. Therefore, under "S

  • Error Installing Premiere Elements 9 - Exit Code 7

    Hi, I'm trying to install Premiere Elements 9 on a Mac (running 10.6.4), but it always comes up with an error, and the program can't be installed. Last time I tried it got to about 95% but then gave me this error: Exit Code: 7 -----------------------

  • Photoshop CS6 Saving JPEGs as GIF's???

    I am doubble clicking my .jpg images from Bridge CS6 into Photoshop CS6 to downsize the image and after i change the image to move across to a forum elsewhere. The Save As" option gives me all the normal file. options, i click the drop down bar and s