Use of functions in static block

Hello,
I have this app containing a static {} block. The reason it's there is to 1) provide a splash screen 2) have input dialog to process input string and check if it's valid in order to load app or not.
In pseudocode it's like this:
1 - get input string with showInputDialog()
2 - check for the input string validity (a valid string is with prefix A-, C- or S-)
3 - if string is valid, load the app
4 - if string is not valid, proceed to step 1.
As you may already see, there is going to be a lot of code (with if-else statements) to check for A-, C- and S- prefixed because I am using indexOf() function which takes only one parameter.
I am considering a way to somehow check recursively, but for this I think I'll need a function to call indexOf() with A-, C-, S- and assess validity for each case.
My question is, is there a way in the static block to have a function? Or can somebody please recommend an efficient approach to checking a string validity with different possibilities inside a static block as in my case, to avoid lots of if-else statements?
P.S. My apologies for initially posting this thread in wrong section.
Thank you!
Victor.

DrClap wrote:
What's a function? And why are you particularly concerned about doing those things in a static initializer as opposed to in some other place?Hi,
Sorry, I'm still thinking c++. I meant method. Something like of the form:
static
boolean valid = false;
while string is not valid
stringfrominput = showInputDialog();   
//determine if string is valid
valid = checkvalid(stringfrominput)
//if possible to have
boolean checkvalid(stringfrominput)
recursively process stringfrom input based on A-, S-, or C- prefixes
return boolean value
}I have a jar app. It is Windows-based and runs as a TrayIcon application. If I include this process when class is loaded, this means that the app will be loaded with all its features. But I need to make sure that the app's features will be loaded only if certain conditions are met.
I am not sure how else to approach this requirement without using static {} block.
Thank you,
Victor.

Similar Messages

  • Using a function from static context..

    Well I have a command line app; and it has a public static void main. Now, I made a function that writes to a file, and tried calling it from the main section, and it got mad saying I can't call it from static context. Anyway to allow it to be called from both static and non static contexts?

    otherwise create object of the class, from that object you can call a method

  • Can I use Count, Max function in PLSQL BLOCK.

    Can U help me to use count, max function in PLSQL BLOCK.
    Because it is giving me error "It is a SQL function"

    SELECT COUNT(*)
    INTO l_variable
    FROM dual;
    Will work inside PL/SQL

  • Why do we use static block ????

    my question is that why do we use static block for certain statements and declarations ?? what advantage do they hold???
    Please help me........

    Here is an example:
    If you use a JDBC-driver, it's enough to write:
       String driverName = "package.MyDriver";
       Class.forName(driverName);In the class "MyDriver" there is a static block:
    public class MyDriver implements java.sql.Driver {
       static {
          MyDriver driver = new MyDriver();
          java.sql.DriverManager.registerDriver(driver);
    }

  • How can I execute program after using F4_Filename function?

    Hi all,
    I'm a new user on the forum. I've been working with ABAP and SAP for a few weeks. I wrote a program for importing data from excel file to SAP using BDC. During searching this forum I found information about F4_Filename function which allows users to browse the disc for a file. I'd like to add this function to my program. I have a parameter for a file name but this is an ordinary static string field. When I added the code which I found in the message on this forum the rest of program doesn't execute.
    This is simple program for example:
    REPORT  Z_TEST8_AB.
    DATA f_name TYPE STRING.
    PARAMETERS p_file like rlgrap-filename DEFAULT 'c:\test.xls'.
    f_name = p_file.
    write:/ f_name.
    This program works correctly. There is a field for parameter. I can change the default name for a file.
    After all, I can run the program (F8) and rest of the code is executed. The field for parameter dissapears from the screen and the file name is displayed. ( command write)
    Now I added a function F4_Filename
    REPORT  Z_TEST8_AB.
    DATA f_name TYPE STRING.
    PARAMETERS p_file like rlgrap-filename DEFAULT 'c:\test.xls'.
    at selection-screen on value-request for p_file.
      call function 'F4_FILENAME'
           exporting
                program_name  = syst-repid
                dynpro_number = syst-dynnr
                field_name    = 'p_file'
           importing
                file_name     = p_file.
    f_name = p_file.
    write:/ f_name.
    I can browse a computer for a file now but after selecting the file I can't run the rest of the code. When I click on the icon or press key F8 the field for parameter doesn't dissapier and the command write is not executed.
    What do I do wrong?
    Could anyone suggest me a solution? How can I executed the code after using this function?
    Thanks in advance.
    Regards,
    Arek.

    Hi arkadiusz,
    1. simple
    2.
    <b>start-of-selection.</b>
    f_name = p_file.
    write:/ f_name.
    regards,
    amit m.

  • Error when using VML functions of Intel MKL v9.0 with LabVIEW 8.2.1

    Hi,
    I have created a DLL in Visual Studio 2005 which uses functions from the Intel Math Kernel Library (MKL) v9.0. The DLL works perfectly when I run it in VS 2005, but when I use it in the LabVIEW environment, I receive the error 1097 [An exception occurred within the external code called by a Call Library Function Node.].
    It seems that the VML function vdPowX(), which raises each element of a vector
    to the constant power, creates an access violation reading at location 0x00000000.
    Unhandled exception at 0x0652d545 (OptimisationDLL_Intel.dll) in LabVIEW.exe: 0xC0000005: Access violation reading location 0x00000000.
    When I trace it with VS2005, it seems to read at 0x00 when they check for the mode of the function (HA or LA) to see if the function will uses High Accuracy or Low Accuracy. You can reproduce the bug by simply trying to read the Mode with the Intel Function vmlGetMode().
    I'm not sure why I only get the crash in LabVIEW and not in VS2005. The other function from the MKL that I use, daSum(), works correctly in VS2005 and LabVIEW. It doesn't have an accuracy mode since it's not in the VML family, that's probably why.
    I've included the source code in C that causes the crash when the DLL is used in LabVIEW (Corellation_Intel.c).
    When you attach the LabVIEW process to Visual Studio Debug mode, the execution stops at eax,dword ptr [edx+ecx*4]:
    _mkl_vml_core_w7_vml_GetMode:
    023D528C  mov         ecx,dword ptr [__tls_index (240EA0Ch)]
    023D5292  mov         edx,dword ptr fs:[2Ch]
    023D5299  mov         eax,dword ptr [edx+ecx*4]
    Anyone had this kind of error or have any idea what I might have done wrong? I uses mkl_c.lib and libguide.lib libraries in the i32 of Intel MKL.
    Thanks a lot for your help and feel free to contact me if you need more information.
    Regards,
    Mat
    Attachments:
    Corellation_Intel.c ‏2 KB

    Dear Mat,
    While more details are desirable to give precise answer I guess that I know the origins of the problem. VML functions are thread-safe. VML engineers use Mircosoft TLS mechanism to maintain thread safety of VML global variables. The TLS use is different for static and dynamic case. This implies that it is impossible to use MKL static library which contains TLS stuff to build dynamic library. Indeed, your DllMain function must have VML TLS initialization/processing/finalization stuff (for details see http://msdn2.microsoft.com/en-us/library/ms686997.​aspx). In case VML TLS stuff is absent in your DllMain routine you will see Access Violation on any attempt to access VML global variables.
    VML engeneers are seeking for possible solutions/workarounds. Thus far they don't see any elegant way of solving this with existing technologies. Specifically, _mkl_vml_core_w7_vml_GetMode routine does access one of VML global variables.
    There is a possibility to build custom VML DLL from static MKL library using MKL Builder Tool. The limitation is that the built DLL cannot contain non-MKL stuff (recalling DllMain issue, MKL Builder Tool cannot put into DllMain routine user's stuff).
    Feel free to go to Intel MKL web forum or contact Intel Tech Support in case you have additional questions.
    I will keep you informed.
    Regards,
    Sergey Maidanov
    Intel Corporation

  • Can i play music and use mirroring function at same time from ipad2 to apple tv

    can i play music and use mirroring function at same time from ipad2 to apple tv

    Yes, any audio during the "mirroring" funtion will forward to the appletv. This includes all system audio, games, apps, ect. If you slide the mute botton the side of your ipad to mute then you can block app audio and just get Music audio or Pandora if you are using pandora.

  • Using EveryNCallback function with a C++ class (not VB)

    Hello all,
    I am trying to incorporate one of the ANSI C examples into my code which contains C++ classes. I receive errors because of having to declare the EveryNCallback and DoneCallback functions as static to keep their C function signature. This of course is not allowable when using these functions as members of a class. Could anyone help please?
    Best,
    Paolo

    Firstly, thank you for the help. I have attempted to code the advice you gave but it still does not seem to compile properly. Can you suggest what is wrong with my code please?
    Here is the code I am trying to configure:
    forceDriver.h
    static int32 CVICALLBACK static_callback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void* callbackData);
    int32 EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples);
    int32 DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
    forceDriver.cpp
    DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,2500,0,&forceDriver::static_callback,panel));
    **START TASK**
    int32 forceDriver::EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples)
           panel->(member_function);
    int32 CVICALLBACK forceDriver::static_callback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void* callbackData)
    forceDriver* static_object = static_cast<forceDriver*>(callbackData);
    return static_object->EveryNCallback(taskHandle, everyNsamplesEventType, nSamples);
    where panel is the object I have created. 

  • SQL LOADER: how to load CLOB column using stored function

    Hi,
    I am a newbie of sql loader. Everything seems to be fine until I hit a
    road block - the CLOB column type. I want to load data into the clob
    column using a stored function. I need to do some manipulation on the
    data before it gets saved to that column. But I got this error when I
    run the sql loader.
    SQL*Loader-309: No SQL string allowed as part of "DATA" field
    specification
    DATA is my CLOB type column.
    here is the content of the control file:
    LOAD DATA
    INFILE 'test.csv'
    BADFILE 'test.bad'
    DISCARDFILE 'test.dsc'
    REPLACE
    INTO TABLE test_table
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    codeid          BOUNDFILLER,
    reason          BOUNDFILLER,
    Checkstamp     "to_date(:CHECKSTAMP, 'mm/dd/yyyy')",
    "DATA"          "GetContent(:codeid, :reason)"
    All references are suggesting to use a file to load data on
    CLOB column but I want to use a function in which it generates
    the content to be saved into the column.
    Any help is greatly appreciated.
    Thanks,
    Baldwin
    MISICompany

    *** Duplicate Post ... Please Ignore ***

  • How to use Analytic functions in Forms10g

    Hi,
    Can we use Analytic function in forms10g like Lead & Lag.
    Thanks & Regards,

    Use a db view as a data source of your form block ....
    Greetings...
    Sim

  • Help required in understanding of static blocks in java

    Hi ,
    Can some one help me in understanding the difference between static blocks in java....also what is the difference in declaring some static variables in a class and and declaring some variables in a static block? From an architecture viewpoint when should one use static blocks in Java?

    Static blocks are piece of code that can beexecuted
    before creating an instance of a class.static blocks are executed once, when the class
    itself is loaded by the JVM. They are not executed
    before creating each instance of a class.
    For example whatever you include in the mainn method will be
    executed without you having to create the instanceof
    the class using the new operator. So you can saythe
    main method is a static block.main is not a static initialisation block but a
    static method. a special case static method at that -
    it is only executed when the containing class is
    specified as a parameter to the JVM. (unless you
    specifcally call it elsewhere in code - but that
    would be bad form).
    in answer to the original post, static variables
    belong to the class. each instance of the class share
    the same static variables. Public static vars can be
    accessed by prefixing them with the class name. A
    static initialisation block can be used to
    initialise static variables. Variables declared
    within the static initialisation block exist only
    within the scope of the block.
    e.g.
    public class Foo {
    static Bar bar;        // static member variable
    // static initialisation block
    static {
    // variable declared in static block...
    String barInfo =
    arInfo = System.getParameter("barInfo");
    // ... used to initialise the static var
    bar = new Bar(barInfo);
    So is the only purpose of static initialization blocks is to initialize static variables? Does the initialization of static variables inside a static block make any difference in performance? If yes , then how ?

  • Can we have try/catch in a static block in a class?

    hi All
    i have a question about put a try/catch block in a static block in a class to catch exceptions that maybe thrown from using System.xxxx(). in my custom class, i have a static block to initialize some variables using System.xxx(). in case of any error/exception, i need to be able to catch it and let the caller know about it. i tried to put a try/catch block in the static block, and tried to rethrow the exception. but it is not allowed, how would i handle situation like this? thanks for your help and advise in advance.

    You could just swallow the exception inside try/catch
    block, and instead of throwing it out, just set a
    static variable to allow checking from outside
    whether the initialization succeeded, or check within
    the constructor / methods of this class for
    successful initialization, and throw the exception
    then. You could even save that exception in a static
    variable for later.Ouch, ouch, you're hurting my brain. This would allow someone to ignore a (presumably) fatal error. Throw a RuntimeException as indicated. You can wrap a checked exception in an unchecked one if need be.

  • Error while using Ago function

    hi all,
    OBI 11.1.1.7.1
    I am unable to view data on result tab. No value returned in Calcutated Attribute. Please Help
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 22040] To use Ago function, the storage level of the query ('[Time Dim.PAY_DT]') must be a static level.Please have your System Administrator look at the log for more details on this error. (HY000)
    Regards,
    Nivedita

    Substr("Fin Account".ASSET_NUM, 1, instr(Fin Account".ASSET_NUM, ':')+1)
    or
    Substr("Fin Account".ASSET_NUM, instr(Fin Account".ASSET_NUM, ':')+1,50)
    i think you should use 3 parameters, did you try that if it would work?
    additionally check what is the default format of your data: go to column properties -> data format; if its text then ok; otherwise you will have to cast the number to char; in such a case the above could be:
    Substr(cast("Fin Account".ASSET_NUM as char(20)), 1, instr(cast(Fin Account".ASSET_NUM as char(20)), ':')+1)
    or
    Substr(cast("Fin Account".ASSET_NUM as char(20)), instr(cast(Fin Account".ASSET_NUM as char(20)), ':')+1,50)
    Edited by: UserMB on Jun 25, 2009 6:17 AM

  • Foreach loop in static block won't compile

    When I try to compile this:public class TestEnum
      private static String[] numerals =
          {"einz", "zwei", "drei", "vier"};
      static
        for (String n : numerals)
          // doesn't matter what's in here
      public static void main(String[] args)
    }I get this exception:An exception has occurred in the compiler (1.4.2-beta).
    java.lang.NullPointerException
        at com.sun.tools.javac.comp.Lower.visitArrayForeachLoop(Lower.java:2269)
        at com.sun.tools.javac.comp.Lower.visitForeachLoop(Lower.java:2242)
        at com.sun.tools.javac.tree.Tree$ForeachLoop.accept(Tree.java:559)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1580)
        at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:51)
        at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:131)
        at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:497)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1580)
        at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:1645)
        at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:409)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1580)
        at com.sun.tools.javac.comp.Lower.translate(Lower.java:1594)
        at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:2438)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:408)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.Main.compile(Main.java:41)
        at com.sun.tools.javac.Main.main(Main.java:32)The same thing happens if I use foreach with a Collection instead an array. If I use an old-style for loop or Iterator in the static block, it compiles fine. I can also put the foreach loop in the main method, and it works. Is this a known bug?

    You guys rock. Thanks for finding this problem. I'll get it fixed.

  • Authentication syntax for HTTP GET method using TCP functions in Labview on linux

    Hi,
    Currently, I am trying to communicate to web server. I have Labview installed on a Linux machine. The HTTP function blocks and other labview functions do not work. Hence, I am building a HTTP code string using TCP functions (port 80) to talk to the web server. I am successfully able to fetch a response from web sites (example www.ni.com) from my vi. However, when I try to communicate to my web server, it does not work. It requires an authentication. I am able to open http://ipaddress in my browser from my machine using username and password. Can someone help with Authentication string requirement for GET method?
    so far the string is:
    GET /index/ HTTP/1.1
    Host: http://xx.xx.xx.xx

    An easy option would be to try http://userassword@server syntax for the URL.
    Else I posted a Twitter fetcher once (won't work anymore since Twitter moved to Oauth authentication) at LAVA. Based on code from @cloew.
    The code is part of this LLB.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

Maybe you are looking for

  • FAQ: What are the known issues so far in Photoshop CS6 Beta

    APPLICATION  COEXISTENCE Lightroom 4 Beta + Photoshop CS6 beta -- Editing the same video file simultanously in both applications may result in an error, crash, or blank (transparent) frames. You might see this Photoshop error: "Could not complete the

  • Standard SAP Planning reports

    Hi all I have a requirement for some planning reports and I am hoping to find them in standard ECC. Can anyone let me know if they are aware of what is available to meet the following; Coverage reports or shorage reports at the component level Waterf

  • Urgent Help--Mass Migration of Reports to 10g

    Hi All, We have about 350 reports that we want to migrate to 10g. Is there a way to migrate them all using a batch program or some tool instead of opening them one by one in the reports developer? PLEASE HELP URGENT. Thank a lot in advance.

  • KM DMS connector: Configuration issue

    Hi experts, I follow this thread to configure my DMS connector: https://forums.sdn.sap.com/thread.jspa?threadID=1411690&messageID=7884645 After that, i've moved to KM contents -> dms folder. Unfortunately, i've got the following error: Exception Clas

  • PSE 8 - Photomerge Panorama not working?

    Trial version (is Panorama disabled in trial?), XP, default preferences File->New->Photomerge Panorama and select either 2 open files or 2 files off disk.    Tried Auto reposition, manual , and in both cases, the program thinks for a couple seconds a