Results 1 to 9 of 9
  1. #1
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    282
    Rep Power
    3

    Exclamation How to use class in if condition

    Hi
    i need help!
    in my project i use packages(core [sub-package] & data [sub-sub-package])
    inside the sub-sub-package i have two classes CryptoFileData & PlainFileData
    and
    i wants to use above classes in another sub-package called gui
    i import the classes too..,

    but it showing error in the fallowing code (core/data/CryptoFileData)



    Java Code:
    if(currentData.getClass() == core/data/CryptoFileData)
            {
                CryptoFileData data = (CryptoFileData)currentData;
                File outPath = new File(tf_rOutput.getText());
                data.setOutputFile(outPath);
                data.SetPassword(PwdDialog.getPasswordFromUser());
            }

    if i use (core.data.CryptoFileData) formate also showig error

    can anyone give the solution please..,

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,920
    Rep Power
    19

    Default Re: How to use class in if condition

    You need to show us the errors.
    Anyway, in this case it's <class name>.class to get the Class instance.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    282
    Rep Power
    3

    Default Re: How to use class in if condition

    Thank you Mr.Tolls..,
    I try for as your idea..,
    Thank you Sir..,

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: How to use class in if condition

    The instanceof keyword is there for a purpose. Even if, sadly, its use exposes a faulty or weak design. As does testing the class of a parameter in any other way.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    282
    Rep Power
    3

    Default Re: How to use class in if condition

    i am very happy with your help sir,
    i will try to make better design sir..,
    thank you..,

  6. #6
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    282
    Rep Power
    3

    Thumbs up Re: How to use class in if condition

    Thanks to Jesus!

    Thank you sir!
    I have been trouble with my coding.
    Now!
    After your idea, i got my output..,
    I lot of thank to you...,
    thousands of thanks to you my helper...,

    But!
    i am using Netbeans IDE & created my project in (e://raj/sec)

    if i create a jre,
    i can only execute in side the Netbeans Or on the folder (wher i keep my project path (dist folder)) Or create shortcut from their

    but!
    if i copy the jar to desktop it show an error (Java Exception has occurred)

    what i have to do sir..,

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,923
    Rep Power
    8

    Default Re: How to use class in if condition

    Again, you have to show us the error. But it sounds like it could be a problem with your classpath or a relative path.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    282
    Rep Power
    3

    Default Re: How to use class in if condition

    jest in my if statement to use the class like

    Java Code:
    if(currentData.getClass() == core.data.CryptoFileData.class)
            {
                CryptoFileData data = (CryptoFileData)currentData;
                File outPath = new File(tf_rOutput.getText());
                data.setOutputFile(outPath);
                data.SetPassword(PwdDialog.getPasswordFromUser());
            }
    is this the problem sir?..,

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,920
    Rep Power
    19

    Default Re: How to use class in if condition

    What exception?
    Come on, help us to help you.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Accessing specific class if condition is true
    By Hash in forum New To Java
    Replies: 1
    Last Post: 02-24-2012, 03:43 AM
  2. Condition ignored.
    By Pojahn_M in forum New To Java
    Replies: 8
    Last Post: 12-09-2011, 02:21 AM
  3. Waiting on a condition
    By nephos in forum New To Java
    Replies: 9
    Last Post: 04-22-2011, 10:05 AM
  4. While loop condition
    By counterfox in forum New To Java
    Replies: 3
    Last Post: 10-10-2010, 01:14 AM
  5. IF-Condition in a String
    By lenaz in forum Advanced Java
    Replies: 1
    Last Post: 07-18-2009, 12:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •