Can Class.forName("SomeClassName").newInstance() work in all classes?

I saw some classes don't have a method called "newInstance()".
but I have seen some advices say that is better using "Class.forName().newInstance()" than using "Class.forName()".

I saw some classes don't have a method called
"newInstance()".If you have class Foo, and you do Class.forName("Foo").newInstance();you're not calling Foo's newInstance method. You're calling java.lang.Class' newInstance method. You have a Class object that represents the Foo class. You tell that Class object newInstance() which invokes the public no-arg constructor of class Foo (as if you had done new Foo()). If Foo doesn't have a public no-arg constructor, you'll get an exception.
but I have seen some advices say that is better using
"Class.forName().newInstance()" than using
"Class.forName()".They do two completely different things, and Class.forName().newInstance() first does Class.forName() and then class newInstance() on what that returns.
Class.forName("Foo") returns the Class object that is associated with class Foo. It also loads the class if it hasn't already been loaded. It returns an instance of java.lang.class
newInstance() calls the public, no-arg ctor of that class, if that ctor exists. Otherwise it throws an exeption. If it succeeds, it returns an instance of Foo.

Similar Messages

  • I'm can't get iMessage to work with all my Apple devices.

    So i cant seem to get iMessage to work across all my Apple devices. My wife and I use the same Apple ID but have different phone numbers. Is there a way to get all our messages on our shared devices and our personal messages on our phones? (iPad, iMac, MacBook Pro: Shared)

    Hi,
    I have this set up with one Mac and two iPhones  (Not Multiple Macs)
    I added the Apple ID to the Mac for iMessages.
    I then added the Apple ID to the first iPhone.
    I accepted the pop ups on the Mac so that the iPhone was Listed in Receive At (you might have to Restart the App on the Mac to trigger this).
    I then added the Apple ID to the Second iPhone and again accepted the pop ups in the Mac.
    IF this is what you think you did but it is not working remove the Apple ID from both iPhones
    Place the iPhones in Airplane mode fro a few minutes to Break with the server.
    when back in normal mode and in Settings > Messages check the iPhone number is ticked and active.
    (Send a Test message to the Apple ID (Mac) to check)
    Add back the Apple ID if the test works.
    Restart the Mac version to trigger the pop ups and Accept.
    Repeat the set up with tests for send iPhone.
    I have never set this up with one ID on two or more computers but it should work.
    9:01 PM      Wednesday; June 4, 2014
     iMac (Mavericks 10.9.x)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.8)
     Mac OS X (10.6.8),

  • Can't get setMask to work at all

    I am using Flash CS3 with ActionScript 2.0
    I am trying to load a jpg in and display it in an existing movieClip.
    I have created a movieClip on the stage with an instance name of maskMovieClip. I then create a new/empty clip within maskMovieClip, and then load the new clip with the jpg and then try to use the setMask to switch them. I did read that it won't work if jpg's have not finished loading, so I put a for/next loop in my example just to make sure the clips are loaded. Here is my test code:
    //HOW TO RE-PRODUCE PROBLEM...
    //Create one movie clip on the stage with an instance name of maskMovieClip.
    //Create two small jpg pics called pic1.jpg and pic2.jpg.
    //This correctly loads and displays a jpg into maskMovieClip
    maskMovieClip.loadMovie("pic1.jpg", 1);
    //This supposedly creates a new movie clip called newMC within the maskMovieClip
    maskMovieClip.createEmptyMovieClip("newMC", maskMovieClip.getNextHighestDepth());
    //This loads a different jpg into newMC. And just to make sure it worked,
    //I manually tried creating a movie clip on the stage with the instance
    //name of newMC, and it correctly loaded and displayed it.
    newMC.loadMovie("pic2.jpg", 1);
    //This is just to kill some time to make sure both jpg's are loaded
    for (i=0; i<=100000; i++) {
        trace(i);
    //This is supposed to switch from one to the other, but doesn't
    maskMovieClip.setMask(newMC);
    //I even tried this to make sure I didn't have it backwards
    //newMC.setMask(maskMovieClip);
    Any assistance would be greatly appreciated!!!
    Thanks

    I gave up on using setMask... I could not get it to work even with MovieClipLoader class, so I took a different approach...
    I load all the jpegs in like this into their own instance and assign them an increasing depth starting at 0. To display any particular jpeg just change it's _alpha back to 100:
    for (j=0; j<total; j++) { //Pre-load all the images. total is the number of pics in the external XML file
      picLoad = "newMC" + j; //Assign each image a unique name (newMC0, newMC1, etc)
      this.createEmptyMovieClip(picLoad, j); //Set their depth equal to j (newMC0 is depth 0, newMC1 is depth 1, etc)
      this[picLoad]._alpha = 0; //Set their alpha=0 so you can't see them
      this[picLoad].loadMovie(image[j],1); //image[] is an array that contains the location & name of each pic (image[0] = "slideshow/pic1.jpg")
    I then used swapDepths() to move the buttons from their original depth assigned by Flash (which is around -16000) to a higher depth starting at 50000, which is well above the depth of the jpegs I loaded in, so unless somebody wanted to load in more than 50000 images, it should not be a problem. There is actually 2 buttons, a text field and a movieClip (as a background for the buttons and text). I initially could not get swapDepths to work with the buttons and text field... it was only working with movie clips, but then I found out that swapDepths is not available to buttons and text fields by default, but needs to be included. All this was done like this:
    Button.prototype.swapDepths = MovieClip.prototype.swapDepths; //Make swapDepths available for buttons
    TextField.prototype.swapDepths = MovieClip.prototype.swapDepths; //Make swapDepths available for text fields
    button_bg.swapDepths(50000);
    picNum_txt.swapDepths(50001);
    prev_btn.swapDepths(50002);
    next_btn.swapDepths(50003);
    Another possible alternative would have been to use swapDepths to swap each pic back and forth between a manually created movieClip on the stage, but it seemed easier to just write the code to swap my buttons once instead of code for swapping pics everytime!
    Thanks

  • HT201471 I have an iPad 3 model A1416 16GB.  It is about 1 1/2 years old. When I opened it today the pad for my password came up and then before I could put in my password the screen went black and now I can not get it to work at all.  What should I do?

    I have an iPad 3 model A1416 16GB.  It is about 1 1/2 years old.  When I opened it today the screen for my password came up and then before I could enter it the screen went blank. I can not get it to do anything now. It had about 24% of charge left. I plugged it into the charger and still nothing. What do I do?  How do I get it to work?

    Try the following:
    1. Reset
    Hold the Sleep and Home button down until you see the Apple logo
    2. Restore:
    http://support.apple.com/kb/HT1414
    3. Recovery:
    http://support.apple.com/kb/HT1808

  • [SOLVED] Can't get any sound working at all

    I've just installed Arch again on my MacBook 5,2 and I can't get any sound (speakers or earphones) to work. I've tried the ALSA wiki page for troubleshooting, but none of that has worked. Does anyone have any ideas where to start with this?
    Last edited by dave1022 (2011-05-07 15:04:31)

    When you try something and it doesn't work, post the commands and the errors you get here, so that someone can actually help you with your problem.
    Please help us help you.

  • I can't get flashplayer to work on all sites

    I am having a problem with viewing a website that uses a
    flashplayer. I can go to youtube and see the videos fine, but the
    site that I need to go to, I get a white page, and nothing on it. I
    have to get into this site for my job and do training at home. The
    helpdesk at my company is not any help. I have downloaded, and
    unistalled, and done just about everything everyone has suggested
    in the other threads. Why is it that I can view some websites but
    this one, that I need, I can't view. The web address ends in a .swf
    . Please, please, please help me.

    You really need to provide more info, like what you've tried to do and what the result was (error messages..).
    First step is to go to Settings>icloud and sign into your icloud account.

  • How can i make the valueChangeListener works for all item under foreach?

    Hi,
    My jspx file have the following content:
    <af:forEach items="#{pageFlowScope.directiveStep.paraItems}"
                                                       var="item">
                                              <af:panelLabelAndMessage label="#{item.name}"
                                                                       id="plam2"
                                                                       for="soc1">
                                                 <af:panelGroupLayout id="pgl2"
                                                                      layout="horizontal">
                                                    <af:selectOneChoice id="soc1"
                                                                        value="#{item.howValue}"
                                                                        required="true"
                                                                        valueChangeListener="#{pageFlowScope.directiveStep.howToSetDirectivePropValueChange}"
                                                                        autoSubmit="true">
                                                       <f:selectItem value="Set Value}"
                                                                      id="si1"/>
                                                      <f:selectItem value="Choose a Value"
                                                                      id="si1"/>
                                                    </af:selectOneChoice>
                                                    <af:switcher facetName="#{item.selectWay}"
                                                                 id="switch1">
                                                       <f:facet name="true">
                                                          <af:selectOneChoice id="soc2"
                                                                              required="true"
                                                                              value="#{item.value}">
                                                             <f:selectItems value="#{pageFlowScope.directiveStep.procVarItems}"
                                                                            id="si2"/>
                                                          </af:selectOneChoice>
                                                       </f:facet>
                                                       <f:facet name="false">
                                                          <af:inputText id="it1"
                                                                        required="true"
                                                                        value="#{item.value}"/>
                                                       </f:facet>
                                                    </af:switcher>
                                                 </af:panelGroupLayout>
                                              </af:panelLabelAndMessage>
                                           </af:forEach>
    The ui is like:
    label name     |    selectOneChoice : 'Set Value' or 'Choose a Value'   |        inputText (if it is 'Set Value') / selectOneChoice (if it is 'Choose a Value')
    The weird thing is when i click the selectOneChoice of the two or later row, the ValueChangeListener will be invoked, it indeed change the value  of 'selectWay' correctly. But the UI will not update. If later i do the same thing to the first row, all other rows in UI will update corrently.
    Any suggestions? Very appreciated for any repiles.
    Thanks.

    Hi,
    on problem I spot is that all your components created by the forEach loop have the same ID value. I suggest you change the ID to e.g. id="soc_#{item.index}" for zhe select one choices. In addition, I don't see where you refresh components after the change
    Frank

  • I cannot get Address book to work at all. I keep saving addresses under the "Message" menu but they don't appear.

    I can't get "AddressBook" to work at all. I opens and shows the same three addresses saved ages ago. I click on the "Messages" menu drop down and try to save the current address of an e-mail but nothing happens. Very frustrating. Any tips?? Thanks, Peter

    Try reseting (not just turning off) your phone: hold down the Home button and the Power button on the top until the Silver Apple appears (ignore the red slider if it appears). See if the reset clears things up!
    Cheers,
    GB

  • Can't get iphoto to work after tampering with library in Finder

    I think I made a big mistake when I tampered with the iphoto library in Pictures in Finder.
    Now I can't get iphoto to work. All the pictures are gone in iphoto, the spaces are there but they are blank.
    When I open iphoto it goes into the mode (little spinning wheel appears) where I have to "force quit".
    Any supggestions on what I can do? Thanks.

    The list that shows is just data files and such.
    You can burn the entire iPhoto Library folder.
    You can burn each Year folder or any other variation.
    This is my workflow. The reason I do it the way I describe is because I want a backup of just the photos and video clips I take so I can copy them to a partition of my external drive and burn them to disc. On the other partition I backup my entire users folder
    When iPhoto 5 first came out I really think it was programmed to import the smaller 30 sec video clips that cameras were taking at the time. Since then, digital cameras, at least my Canon S2 can take clips as large as your memory card can hold. The first time I tried to download my images and movie clips with my new camera, iPhoto stalled at the movie clips. I wasn't going to take any chances messing up my iPhoto Library so I started using Image Capture to download all my images and Movie clips. I actually like doing it this way a lot better. My movie clips are downloaded into my Movies folder where I then put them in a dated folder.
    My photos are downloaded into my Pictures folder, where I then put them in a dated folder. I import the dated folder into iPhoto. I also keep all dated folders from photo downloads in the Pictures folder till I get enough Movie folders and Photo folders to fill a DVD. I burn them and then delete them from the hard drive.
    This way I have the photos in iPhoto and I also have just the photos backed up to DVD.
    The Movies I keep on the hard drive in their dated folders until I use all the clips for my iMovie projects for the Year. I then make sure they are all burned to DVD, then I delete those from my hard drive.
    Using Image Capture to download images and video clips:
    Open up Image Capture which is found in the Applications folder.
    When it is opened, go to Image Capture/Preferences
    Under the General button choose
    Camera: When a camera is connected, open Image Capture.
    The next time you connect your camera Image Capture will open.
    In the window that opens you will see an Options button. Click on that button to set your options.
    To find out more about Image Capture (it can do a lot more) Click on Help in the menu bar when Image Capture is open.
    iPhoto: How to Change the "Open Automatically" Preference
    If you find you can't change any of Image Captures preferences or can't access any drop down menus or they are greyed out, check to make sure Image Capture is loose in the Applications folder and not within a sub folder.
    Here is info on backing up your photos:
    Backing up your iPhoto Library
    1. Burn the iPhoto Library folder in the Finder to a CD or DVD
    This method will give you a burned iPhoto Library folder that can be copied back to your computer to replace a damaged library. You can also use this method to backup an old library when you want to create a new Library to use as your current library.
    insert a blank CD into your internal or external CD-RW drive and copy the iPhoto library to the CD icon on your desktop. When you drag the CD icon to the Trash/Eject button in the Dock, you are given the option to burn the CD. Click Burn and the CD is created. To burn a DVD backup of your digital images, use a DVD and a SuperDrive-equipped Mac
    The easiest way to burn an iPhoto Library folder in the Finder that is larger than 4.7 gig to fit on one DVD is to burn sections of the folder.
    Drag the iPhoto Library folder to the desktop
    Double click the folder to open it.
    Drag each Year folder to the desktop.
    You should be left with the iPhoto Library folder containing all the data files, and the Year folders.
    Combine whatever year folders that amount closest to a DVD burn size on one DVD. Make sure that you have burned all the Year folders, then the iPhoto Library folder with all the data files.
    If you ever need to use this backup, insert the DVDs into your computer and copy the folders to the desktop. Put all the Year folders back into the iPhoto Library folder. Then put the iPhoto Library folder back into the Pictures folder.
    You can also check out applications for disc spanning:
    Disc-spanning software
    DropDMG
    Toast
    Dragon Burn 4
    BackityMac
    Retrospect Express-comes with some external drives
    Retrospect for Macintosh Desktop Edition
    2. Copy the ENTIRE iPhoto Library to an external drive formated for a Mac. Do not use this as your only back up as the external can also go bad.
    3. Copy the ENTIRE iPhoto Library to your iPod in disk mode
    4.Creating your own CDs and DVDs for viewing in iPhoto
    This method is a great way to back up Albums of older photos or even your entire library if it is small enough to fit on a DVD. This method will give you a library that will mount within iPhoto in the source column to be viewed. To import any images from this library they need to be dragged into your library in the source column.
    If you just want to backup the images in your library:
    1) Within iPhoto select the images, albums or rolls you want to backup. Go to Share>Export and export them to a newly created folder on the desktop. Follow the directions in the next link.
    Creating a CD or DVD to be viewed in Windows or by a photo processing company
    1.. If you backed up the entire iPhoto Library by burning within iPhoto or burning the folder in the Finder, make sure the burned copy is a good working copy before you delete the iPhoto Library folder in the Finder. You delete the iPhoto Library in the finder by dragging it to the trash when iPhoto is closed. When you next launch iPhoto it will create a new empty library for you to start anew.
    2. If you burned just the images, be aware that that is all you are archiving. No metadata will travel with the images such as comments, keywords, etc.
    You can then delete those images within iPhoto by highlighting them and hitting the delete key, then empty iPhoto's trash. Do this often and in groups so iPhoto will not choke on too many images.

  • My iphone is locked and I cant make it work at all.

    Hi, my iphone is locked and I can't get it to work at all. do you have any suggestions>?

    Hi irishdave75,
    I apologize, I'm a bit unclear on the exact nature of the issue you are describing. If you mean that it is locked with a passcode and you are unable to access it, you may find the troubleshooting steps outlined in the following article helpful:
    Forgot passcode for your iPhone, iPad, or iPod touch, or your device is disabled - Apple Support
    If, on the other hand, you mean that your iPhone is locked up or otherwise not responding, then this article may be of more use:
    iOS: Not responding or does not turn on - Apple Support
    Regards,
    - Brenden

  • HT201210 i updated my 4s yesterday, but my phone will not work at all now, and will not turn off. It has a itunes image on the screen with an arrow undernieth and what looks like the charger lead. i've had it on charge! is there anything else i can do?

    i updated my 4s yesterday, but my phone will not work at all now, and will not turn off. It has a itunes image on the screen with an arrow underneath and what looks like the charger lead. i've had it on charge! is there anything else i can do?

    Cconnect it to your computer with the latest version of iTunes installed.

  • My itunes will not work at all. i have deleted and reinstalled in over ten times, i have ended the process, i have reinstalled quicktime i few times, i have deleted many folders. What else can i do? Please help:(

    My itunes will not work at all. i have deleted and reinstalled in over ten times, i have ended the process, i have reinstalled quicktime i few times, i have deleted many folders such as TEMP, itunes helper et What else can i do? Please help:(

    Now it sometimes keeps coming up and working but once i plug an ipod in it freezes my whole computer up and no i dont get any response from itunes at all

  • I bought new Macbook Pro 13" around two months before .My Apple ID is working on all other things except app store . It is buffering for a lot of time and lastly coming on screen " can not connect to app store " Please help me

    I bought new Macbook Pro 13" around two months before .My Apple ID is working on all other things except app store . It is buffering for a lot of time and lastly coming on screen " can not connect to app store " Please help me

    Have you tried repairing disk permissions : iTunes download error -45054

  • I can't make my new wrt160nv2 work at all

    I have a linksys cablemodem and router befsr41v4.3. I've been running a vista machine and xp machine with no problems for the last 2 years. Just got a Toshiba laptap that we want to connect to the internet also but use around the house so bought a WRT160Nv2. Followed the install disk for installation, named a SSID, unplugged and plugged in and finally got a done message saying everything was installed and done.
    Plugged in the two desktop computers and went to IE7 and got a cannot connect to the internet. Network diagnostics came up with everything working fine in the computer.
    Played with the Toshiba and it says it found the network I had named but can't connect to the internet.
    Ran the disk set up because there was no documentation in the box and while I was at it printed the pdf manual. After the disk set up ran again got a message that the eternet cable was not connected and for me to plug it in.
    But the cable was plugged in.
    When I return to the old set up (the befsr41 wired router) then the desk tops and the Toshiba can all surf the internet (I plugged in a cat5 cable into the Toshiba).
    How do I tell if the wrt160 itself is broken (just bought it 3 days ago!)? It seems odd that both the Toshiba wireless portion and the desktop wired portion both can't get onto the internet and I get a message that the ethernet cable is not connected.
    Not knowing very much about the wireless portion (worked with wired only and talked to the best buy guy about how easy it is to replace the befsr41 with the wrt160n) but after the install disk is done installing the program, is the Toshiba automatically supposed to find the router and connect? When I search the Toshiba and go to network properties it says it's connected "a" network called the same thing that I called the wrt160n during the setup and that I get 4 or 5 green bars showing the connection between the Toshiba and the wrt160n. But there is a big red X between the router and the internet.
    I was expecting something a lot easier than this to be able to use the internet on the desktops through the wired ports and the Toshiba throughout the house through the wireless portion.
    It seems odd that BOTH the wired and the wireless don't work at all. I could understand I don't know how to get the Toshiba to connect wirelessly and I need to play with it but when I can't connect at all makes me think the problem is in the wrt160n.
    Any thoughts before I take this thing back to best buy?

    If you are trying to configure your Router with the Setup disk, you can exit from the Setup and configure your Router Manually.
    If your Internet Service Providor is Cable follow this link ----- Once you are able to go online from the Wired computer, Below are the Wireless Settings which you can set on your Router and this will make your Laptop go Online Wirelessly.
    Open an Internet Explorer browser page on your wired computer(desktop).In the address bar type - 192.168.1.1 and press Enter...Leave username blank & in password use admin in lower case...
    For Wireless Settings, please do the following : -
    Click on the Wireless tab
    -Here select manual configuration...Wireless Network mode should be mixed...
    -Provide a unique name in the Wireless Network Name (SSID) box in order to differentiate your network from your neighbours network...
    - Set the Radio Band to Standard-20MHz and change the Standard channel to 11-2.462GHz...Wireless SSID broadcast should be Enabled and then click on Save Settings...
    Please make a note of Wireless Network Name (SSID) as this is the Network Identifier...
    For Wireless Security : -
    Click on the Sub tab under Wireless > Wireless Security...
    Change the Wireless security mode to WEP, Encryption should be 64 bit.Leave the passphrase blank, don't type in anything...Under WEP Key 1 type in any 10 numbers please(numbers only and no letters eg: your 10 digit phone number) and click on save settings...
    Please make a note of WEP Key 1 as this is the Security Key for the Wireless Network...
    Click on Advanced Wireless Settings
    Change the Beacon Interval to 75 >>Change the Fragmentation Threshold to 2304, Change the RTS Threshold to 2304 >>Click on "Save Settings"...
    Now see if you can locate your Wireless Network and attempt to connect...

  • Since I have upgraded to Firefox 4.0.1, it has been constantly freezing up. Now it does not work at all and I am unable to remove my profile. How can I remove my profile if Firefox does not work?

    I finally got so tired of Firefox freezing my computer that I tried to uninstall and reinstall. Upon reinstall, it will not work at all and I am unable to delete my old user profile. Is there any way to get rid of this profile so I can give one last attempt to get Firefox to work before switching permanently to Google Chrome? I really liked Firefox for years until they screwed it up with the recent changes.

    Try running Firefox in [[Safe Mode]]. If it functions properly in that configuration, then one of your add-ons is the culprit.

Maybe you are looking for