Use String Variable in New Object Creation

Thanks to those who review and respond. I am new to Java, so please be patient with my terminoloy mistakes and fumblings. I am reading in a file and I want to create a new object based on specific field (car for example). As you will notice I grab field 8 here label sIID.
String sIID = dts.group(8);
BTW this regex grouping works fine. The problem is seen when I try to use the sIID variable in my new object creation process.
DateParse sIID = new DateParse();
My IDE is reporting "Variable sIID is already defined in the scope"
Is this possible? The assumption is that the sIID will have different value during the processing of the file. For example, car could mean truck, sedan, etc with operators like color, number of doors, mileage, top speed, etc.

Thanks for the reply. I have include similar and much shorter code for the sake of brevity.
My problems are centered around the x variable/object below. Ideally this would translate to three objects PersonA, PersonB, etc that I could reference later in the code as PersonA.newname if I wanted to. Hopefully this makes sense.
public class TestingObjects {
  public static void main(String[] argv) {
       String [] names;
       names = new String[3];
       names[0] = "PersonA";
       names[1] = "PersonB";
       names[2] = "PersonC";
       for (String x:names) {
         PN x = new PN();  // <- Problem
         x.name = x;
         x.SayName();
        System.out.println(x.newname);
public class PN {
       String name;
       String newname;
  public String SayName() {
       newname = "Name = " + name;
       System.out.println(name);
      return newname;
}

Similar Messages

  • Aborting new object creation

    I want to test the input parameters to a constructor and determine if an invalid parameter has been supplied.
    If I use:
    Thingy myThingy = new Thingy("invalid value");
    is it up to the programmer of the above to catch the error, either through exception handling or some other form of error checking, and perform
    myThingy = null;
    to render the partially initialized object ready for garbage collection?
    Is there a way in the constructor itself to indicate that the object shouldn't be created and null should be returned as the result of the "new" operation?
    Thanks,
    John

    But I'd say Clem1986 still has a point. Even in the constructor
      Foo() throws Exception {
        throw new Exception("Bollocks");
      }there's the implicit call to super() and instance initializers before you arrive at throw. From JVM spec: The new instruction does not completely create a new instance; instance creation is not completed until an instance initialization method has been invoked on the uninitialized instance. Which is done above. Whether this qualifies in OP's context as completing instance creation or instantiating an object I don't know. But you could work with it in the constructor, and once you get to throw, memory has been allocated, all superclasses have been initialized (which might involve heavy allocation/computation), default values were assigned to fields and instance initializers have executed. Only now can you decide to "abort new object creation" by completing abruptly and not "returning" the reference to the newly-(partially-)created object to the caller.

  • Set "url" in HTTPService using String variable

    Hi,
    How can I set "url" in HTTPService using String variable (see below). I've tried different formats of string & variable concatenations.
    privtate var myurl:String = "http://localhost/";
        <mx:HTTPService id="post_submit_service"
            url="{myurl+'test.php'}"
            method="POST"
            resultFormat="text"
          result="result_handler(event)"
          fault="fault_handler(event)">
            <mx:request xmlns="">
          </mx:request>
        </mx:HTTPService>
    Thanks,
    ASM

    try following:
    url="{myurl}test.php"

  • How to use string variable onside quotes

    Hi,
    i would like to know how to use string variable onside quotes. what i mean is if i have a LOV variable P_STATUS as character string.
    and in my PL/SQL function i give a query as
    Q AS VARCHAR2(1000) := 'SELECT * FROM EMP
    WHERE STATUS = :P_STATUS';
    Is this correct. I Know that the above statement works when the LOV is an integer, but when i use a character LOV return value the above statement does not work. how can i get in the character LOV value.
    Can someone help me please.
    Thanks,
    Philip.

    916753 wrote:
    Yes I tried binding all the values separately. It is working, but, I am trying to pass all values by variableBut you can't. The variable is holding a single string value.... that is just 1 value. Your binding are expecting multiple values. You can't bind 1 string value and expect Oracle to magically know how to break your string up into seperate values for the bind variables. What if one of your bind variables actually needed e.g. a comma seperated string as it's value? How would Oracle know that?
    You must bind each thing seperately. That's the way cursors work.
    , because i have more than 150 tables in which data will be load. that's why i m trying to create a unique procedure to load data one by one table. Otherwise I have to write individual procedures for per procedures.It's a hard life being a software programmer, but somebody's got to do it. Unfortunately there are too many people who try and write "generic" procedures and expect them to just work. I mean why don't Oracle just implement some SQL command so you can do...
    execute immediate 'load all my tables';save us all the hassle eh!? ;)
    when i write all the columns like
    execute immediate (insert_string) using rc1.TOLL_ID, rc1.LANE_ID, rc1.RECEIVED_DATETIME, rc1.LANE_QUERY, c1.EXECUTED_DATETIME
    but it is not possible to generate runtime variable thats why I m trying to assign all values to a single variable and use it like
    execute immediate (insert_string) using (v_string)
    how can I separate the values and ho to use it .Don't use execute immediate. Use the DBMS_SQL package instead and bind your values dynamically with loops to cover all the columns you need etc.

  • Dynamic Variables and New-Object - in a GUI

    so, i have not found anything that i can parlay into a solution for what i am attempting to do.  
    Basically i am using powershell to build a GUI to manage websites on various servers.  
    in a nutshell:
    - i have an array with the servers i want to query
    - a foreach loop gets me the site names for each server (number of sites can vary on a server).
    - need put checkboxes on a GUI for every site to do something (25-30 sites across 8 servers).
    currently i am passing the $dir.name variable to a function that will create the new variable using this command:
    $pName = $dir.name New-variable -name $pName -value (New-Object System.Windows.Forms.CheckBox)
    $pName.Location -value (New-Object System.Drawing.Size(10,$i))
    $pName.Size -value (New-Object System.Drawing.Size(100,20))
    $Pname.Text -value $dir.name
    $groupBox.Controls.Add($pName) 
    Problem is i am not able to do anything with my newly created variable.  I am trying to use the following code to position the new checkbox but i get nothing (same for text, size, etc.)  I am not seeing any errors, so i don't know what i have going
    wrong.  
    is this even possible?
    I am able to create static checkboxes, and i can create dynamic variables.  But i can't mix the two...

    Here is how we normally use listboxes to handle form situations like this one.  The listboxes can automatically select subgroups.
    The hash of arrays can be loaded very easily with a script or the results of the first list can be used to lookup and set the contents of the second.
    Notice how little code is actually used.  This is all of the setup code needed aside from the from definition:
    $FormEvent_Load={
    $global:serversToSites=@{
    Server1=@('S1_SITE1','S1_SITE2','S1_SITE3')
    Server2=@('S2_SITE1','S2_SITE2','S2_SITE3')
    Server3=@('S3_SITE1','S3_SITE2','S3_SITE3')
    $listbox1.Items.AddRange($serversToSites.Keys)
    $listbox1_SelectedIndexChanged={
    $listbox2.Items.Clear()
    $listbox2.Items.AddRange($global:serversToSites[$listbox1.SelectedItem])
    $listbox2_SelectedIndexChanged={
    [void][System.Windows.Forms.MessageBox]::Show($listbox2.SelectedItem,'You Selected Site')
    Here is the complete demo form:
    [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
    [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
    [System.Windows.Forms.Application]::EnableVisualStyles()
    $form1 = New-Object 'System.Windows.Forms.Form'
    $listbox2 = New-Object 'System.Windows.Forms.ListBox'
    $listbox1 = New-Object 'System.Windows.Forms.ListBox'
    $buttonOK = New-Object 'System.Windows.Forms.Button'
    $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    $FormEvent_Load={
    $global:serversToSites=@{
    Server1=@('S1_SITE1','S1_SITE2','S1_SITE3')
    Server2=@('S2_SITE1','S2_SITE2','S2_SITE3')
    Server3=@('S3_SITE1','S3_SITE2','S3_SITE3')
    $listbox1.Items.AddRange($serversToSites.Keys)
    $listbox1_SelectedIndexChanged={
    $listbox2.Items.Clear()
    $listbox2.Items.AddRange($global:serversToSites[$listbox1.SelectedItem])
    $listbox2_SelectedIndexChanged={
    [void][System.Windows.Forms.MessageBox]::Show($listbox2.SelectedItem,'You Selected Site')
    $Form_StateCorrection_Load=
    #Correct the initial state of the form to prevent the .Net maximized form issue
    $form1.WindowState = $InitialFormWindowState
    $form1.Controls.Add($listbox2)
    $form1.Controls.Add($listbox1)
    $form1.Controls.Add($buttonOK)
    $form1.AcceptButton = $buttonOK
    $form1.ClientSize = '439, 262'
    $form1.FormBorderStyle = 'FixedDialog'
    $form1.MaximizeBox = $False
    $form1.MinimizeBox = $False
    $form1.Name = "form1"
    $form1.StartPosition = 'CenterScreen'
    $form1.Text = "Form"
    $form1.add_Load($FormEvent_Load)
    # listbox2
    $listbox2.FormattingEnabled = $True
    $listbox2.Location = '237, 26'
    $listbox2.Name = "listbox2"
    $listbox2.Size = '120, 134'
    $listbox2.TabIndex = 2
    $listbox2.add_SelectedIndexChanged($listbox2_SelectedIndexChanged)
    # listbox1
    $listbox1.FormattingEnabled = $True
    $listbox1.Location = '13, 26'
    $listbox1.Name = "listbox1"
    $listbox1.Size = '120, 134'
    $listbox1.TabIndex = 1
    $listbox1.Sorted = $true
    $listbox1.add_SelectedIndexChanged($listbox1_SelectedIndexChanged)
    # buttonOK
    $buttonOK.Anchor = 'Bottom, Right'
    $buttonOK.DialogResult = 'OK'
    $buttonOK.Location = '352, 227'
    $buttonOK.Name = "buttonOK"
    $buttonOK.Size = '75, 23'
    $buttonOK.TabIndex = 0
    $buttonOK.Text = "OK"
    $buttonOK.UseVisualStyleBackColor = $True
    #Save the initial state of the form
    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load($Form_StateCorrection_Load)
    #Clean up the control events
    $form1.add_FormClosed($Form_Cleanup_FormClosed)
    #Show the Form
    $form1.ShowDialog()
    You can easily substitute  CheckedListbox if you like checkboxes.
    ¯\_(ツ)_/¯

  • How to use string Variables for data provider names

    Really what I need to be able to do is insert the variable
    name in this:
    dataProvider="{chartXML2.lastResult.month.day}"
    I need to replace the "month" with a string variable name
    (i.e public var monthName = "January";)
    I also need to do the same for the categoryfield as it will
    not let me do categoryfield=$String.
    In PHP this is incredibly easy to do. You just say
    blah=$string . In fact, in PHP you can embed variable names
    everywhere. Its very powerful. For instance, in php, for the
    dataprovider issue above, i'd just do
    dataProvider="{chartXML2.lastResult.$StringName.day}"
    and it'd work just fine. Whats the syntax for doing this in
    Flex?

    You can use bracket notation. But don't. Use a reuslt handler
    to wrap the xmllist in an XMLListCollection instance variable and
    bind to that.
    Tracy

  • New Object Creation vs. Field Setters

    I know this is massively context dependent, but is there some rule of thumb to follow when it comes to deciding between
    i) Making an class's fields final and creating a new object with new field values when needed, and
    ii) Leaving a class's fields mutable and using setter methods to alter the field.
    I tend toward option one, because not only do I tend to shy away from setters, but also because it helps prevent me from accidentally maintaining an old reference. However, purely from a performance standpoint, which option should you assume is better? How many object's of X size do I have to be making per unit of time before the performance benefits of "final" are lost?
    Thanks!

    I've been wishing for a while that Java would add a language level concept of immutability. Either an immutable keyword or an annotation. The compiler would bitch if you declared a class immutable and each of its fields was not final and either a primitive or a reference to an immutable class. Or perhaps it could simply check that there was no assignment to any field.
    It would be handy for me as a user of a class to know that it's immutable, for things like copying and thread-safety. It might or might not allow for runtime optimizations too.
    As for whether to make a given class immutable, like others say--it depends on the semantics of the class. If it's intended to represent something dynamic--e.g. a clock, or a piece on a board whose position changes with time, or the state of a network interface including packet sent and received--then it will make your code clunky and nonintuitive if you have to create a new object everytime the state of the thing you're modeling changes. But if it's something that changes less frequently, or that represents a fairly static entity or "value", then make it immutable.
    I do agree with duffymo: Better that an object comes out of construction in a valid and useful state. So even if the object is mutable, pass field values to the c'tor or set them to reasonable defaults inside the c'tor (e.g., "now", etc.)

  • String contains class name: how to use it for creating new objects

    Hi All
    I've seen things like this in scripting languages, so I was wondering if things like this are possible in java. Here is an not working example:
    String s = "MyClass" ;
    MyClass mc = new s() ; // or: s mc = new s() ;
    if ( mc instanceof s ) { ..... }
    Is something like this possible ?
    Thnx in advance
    LuCa

    jeanluca wrote:
    I've seen things like this in scripting languages, so I was wondering if things like this are possible in java. Here is an not working example:
    Is something like this possible ?AFAIK, it is only possible in a very limited way as noted above and is nearly always not recommended and definitely not necessary. The variable name has little importance, but OTOH the object reference has great importance. Instead learn about arrays, Lists, and Maps.

  • Using a variable in an object name.

    Hi,
    I have 15 text fields each with 6 check boxes.
    I would like to copy the text fields to new fields depending on which checkbox's are checked.
    This also needs to be in a loop.
    I need to know how to add a variable into a textfield name?
    My code is basically like this:
    var x = 1;
    while (x<15)
         {if (Page1.CheckP// insert the value of x //S1.rawValue==1)
                        {Pax// insert the vaule of x //Sect1.rawValue=PaxName1
                   x=x+1};
    I am using Adobe Designer.
    Thank you in advance.
    Damo.

    Hi Bruce,
    I am running this code in a 'on click' event on a button.
    Basically, I have 5 passenger names each with 6 CheckBox's for 6 sectors.
    If Checkbox1 (Sector 1) is checked, I want to put the passenger name in a textfield. Then look for the next passenger on sector 1 and put them in the next textfield.
    This needs to be done for each sector.
    So this is what I have:
    var PaxName1=Page1.PaxName1.rawValue;  // and all other passenger names.
    // Sector 1
    var x = 1;
    while (x<5)
         var vCheck=Page1["CheckS1P"+x];
         if (vCheck.rawValue==1)
              {[TextField"+X].rawValue = PaxName''+X;
                x=x+1};
    Hope this explains what I am trying to do.

  • Question on how to use a variable in report object's horizontal formula to shift back and forth at refresh interval.

    Hello All;
    I have an SSRS Report that displays some slider objects. The report auto-refreshes every 5 minutes.
    This report is displayed on a big screen TV and I want to shift the images back and forth every time it refreshes to prevent possible burn-in on the screen.
    I see you can use a formula on the Horizontal position of objects, and I think a variable that gets added 10 and then subtracted by 10 every refresh could be used to display the objects in different positions each iteration, but I don't know how to do that
    in SSRS. I have read up on variables, and I think I need a global variable, but not sure how to update it on each refresh iteration.
    I read the links on using Silverlight to shift things, but that adds a whole other level of complexity.
    I could even do something in the DB and then pull that into the formula field if needed.
    Thanks in advance.
    George Hicks

    Hello All;
    I have an SSRS Report that displays some slider objects. The report auto-refreshes every 5 minutes.
    This report is displayed on a big screen TV and I want to shift the images back and forth every time it refreshes to prevent possible burn-in on the screen.
    I see you can use a formula on the Horizontal position of objects, and I think a variable that gets added 10 and then subtracted by 10 every refresh could be used to display the objects in different positions each iteration, but I don't know how to do that
    in SSRS. I have read up on variables, and I think I need a global variable, but not sure how to update it on each refresh iteration.
    I read the links on using Silverlight to shift things, but that adds a whole other level of complexity.
    I could even do something in the DB and then pull that into the formula field if needed.
    Thanks in advance.
    George Hicks

  • Greater Than or Less Than using String Variables

    I seem to have a problem when trying to sort an ALPHABETIC LIST, seeing if one text field is greater tan or less than another.
    i.e. Lets say my variables are called FirstLetter and SecondLetter.
    FirstLetter="A", SecondLetter="B"
    So as an example and a test....Can I ask ...
    IF SecondLetter>FirstLetter Then
            Textwindow.WriteLine(SecondLetter + "  >" + FirstLetter)
    Else
            Textwindow.WriteLine(FirstLetter + " >= " + SecondLetter)
    Endif
    I seem to be fine and program working well with numeric values in variables but the '> & <' feature does not seem to work with Text ?
    Any help really appreciated
    Thanks
    Dave

    We gotta get their ASCII/UNICODE value before comparing them:
    firstLetter = "A"
    secondLetter = "B"
    If Text.GetCharacterCode(firstLetter) > Text.GetCharacterCode(secondLetter) Then
    Textwindow.WriteLine(FirstLetter + " > " + SecondLetter)
    ElseIf Text.GetCharacterCode(firstLetter) < Text.GetCharacterCode(secondLetter) Then
    Textwindow.WriteLine(SecondLetter + " > " + FirstLetter)
    Else
    Textwindow.WriteLine("They're the same " + FirstLetter + " letter!")
    EndIf
    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

  • How to use reflection package for dynamic object creation

    I want to convert a "DataObject (SDO) " into "Pure java object".
    For this i want to create a java object with the fields in Dataobject, and this should be in generic way.

    Use Java reflection if you have the java class already created.
    Otherwise use Java IO API for creating the .java file and compile it dynamically by calling javac exe from java code and executing using reflection

  • Necessary variables in new group creation

    I am working on a script to create a new user and matching group using the niutil command. When I create my group in the script, I assign a gid and name. Thus, in netinfo manager, the "name" and "gid" properties are listed for the group. However, when I create the same user/group through "accounts" in the System Preferences, both "passwd" and "generateduid" properties are also generated and listed in the NetInfo Manager.
    1. What properties are necessary for a group in OSX 10.4 (Tiger) to function properly?
    2. If the "passwd" and "generateduid" properties are necessary for the group to function properly, then how do I create these properties via a script or the command line?
    Thanks!
    Mac OS X (10.4.10)

    man, when am i going to stop feeling like a dope with some of this stuff?
    fist image is showing what i am looking at when i can't find a way to add a group without using the pulldown.
    second images is showing a "sub-group" that i think was created by selecting all the contacts in a group and dragging them to another group. this one does not seem to delete.
    jon

  • How use integer variable as object in query

    sir how use integer variable as object in query
    see my code
    Integer currentssgg = new Integer(tt.getValue().toString()); no error
    //yy.setValue(currentss); no error
    //yy.setValue(new Integer(tt.getValue().toString())); no eror
    getSessionBean1().getTripRowSet().setObject(1,currentssgg); giv error
    tripDataProvider.refresh();
    and how use string variable same as method
    please give me idea how use integer variable as object in query
    thank's
    aamir

    >> var mnu = 'menu1';
    this[mnu].onRollOver = function(){
    <<
    Close, but it needs to be like this:
    var mnu = 1;
    this["menu" + mnu].onRollOver = function(){
    Dave -
    www.offroadfire.com
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Difference between "clone" and creating a new object

    Hi experts,
    What on earth is the difference between:
    1)creating a new object by using the "clone()" method and
    2) just creating a new object?
    Let me be a bit more specific:
    if there's a class called "Book" and suppose we've already created an object called "japaneseBook", any difference between "Book spanishBook = new Book();" and "Book spanishbook = japaneseBook.clone()"?
    Thank you.
    Eileen

    The purpose is very obvious. At anytime in the running application, when Objects have been changed, and you desire to make another one of the same kind, you can't use new. You would use clone. The newer Object would have the same values in the variables. Now i got a question.. an important issue.
    public class XYZ{   
      public static int t = 10;
    } // default constructor is present by default.
                     //In another portion i have the following..
    private XYZ x = new XYZ( );  // private Object!!
         // Now what about this one????
    public XYZ x1 = x.clone( );  // public !!, well
    What impact of this code can be there to break the rules of good OOP design??? Is it that a clone Object would have the same access of itself (not of its variables) or different one?????????

Maybe you are looking for