Please, help .. return not working. string can not be resolved to a variabl
Greetings..
I am writing a Java code that encrypt a String using DES. After encryption, I want to return the String, but I get error that says: variable can not be resolved. Please, help me to find out what is the problem ?? Thanks in advance.
Here is the code:
import javax.crypto.*;
import java.security.*;
public class Client {
public String DESEncrypt(String cardnum)
try{
//create cipher object for DES
Cipher c=Cipher.getInstance("DES");
// craete the symmetric key for DES
KeyGenerator kg=KeyGenerator.getInstance("DES");
Key key=kg.generateKey();
// DO the ecryption steps then display the result
c.init(Cipher.ENCRYPT_MODE, key);
//Dofinal accepts byts only. Thats why we use getbytes method.
byte[] cardNoBytes=cardnum.getBytes("UTF8");
//get the encrypted bytes
byte[] encryptedCardNoBytes=c.doFinal(cardNoBytes);
//convert bytes to string
String cardNoString=new String(encryptedCardNoBytes);
} catch(Exception e){ System.out.print("Error");
return cardNoString;
} //end the DESEncrypt method
public static void main (String[] args) {
try{
Client cl=new Client();
String x2=cl.DESEncrypt("123");
System.out.println("The Encrypted text using DES is: " + x2+'\n');
} catch(Exception e){ System.out.print("Error");
}//end main
}
Next time, paste in the exact, complete error message and indicate clearly exactly which line is causing it.
Your problem is that you declare cardNoString inside the try block, but you try to return it outside. Local variables only exist in the narrowest block in which they're declared. Once you exit try, that variable does not exist.
You also have a logical problem. If an error occurs, you're just printing out :"Error", but you're not actually handling it. You're going on as if everything is fine. Catching an exception doesn't fix the error. If you can't fix it, don't catch it.
What do you think your method will return if an exception occurs before you set cardNoString? What do you think it will do to the caller to have some arbitrary, meaningless value returned when he thinks everything went fine and he got a valid result?
Similar Messages
-
My iPad display become white rather than keys are not working, i can not turn off .
My iPad display become white rather than keys are not working, i can not turn off .
version number iSO 8Your statement makes no sense at all. Please clarify.
-
my device was not registered as part of the Developers Program and now my devices are not working, i can not restore nor update my devices... any suggestions? i was running my devices on iOS 7 Beta that i downloaded back in August
If you're not a registered developer, it means you've stolen Apple's software. Now you come to an Apple forum and ask for help? You're lucky you're not being prosecuted!
You can receive no help for stolen software here. Enjoy your iBrick. -
I have macbook without a firewire port, I have usb 2.0 port, now my os is not working I can not get through apple logo loading , I can not enter safe mode, I can only enter one user mode, how can I backup my data, I have very important data in my hdd
Here is what worked for me:
My usb hub, being usb2, was too fast. I moved the wire to a usb port directory on my pc. That is a usb1 port which is slow enough to run your snyc. -
Adobe pdf plug in does not work, when I tried to update following message appeared, "Adobe Reader 9.5.1 and lower has been blocked for your protection", how to solve this problem?
Could you review/adjust your preference for which program opens PDFs? I'm not sure how that drop-list behaves when there are multiple Adobe plugins. You might need to physically remove an old plugin file or two to make sure Firefox is not trying to use the old one.
* [[Use the Adobe Reader plugin to view or download PDF files]] <br>
''Edit: actually this article describe how to use the Options dialog Applications section to review/change the setting: [[How to disable the built-in PDF viewer and use another viewer]]''.
* C:\Program Files (x86)\Mozilla Firefox\Plugins (only one want nppdf32.dll here)
* In regedit.exe, check the following key for the source of obsolete plugins: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MozillaPlugins
Both the file that stores download handling preferences, and the file which registers plugins, can be renamed and Firefox will regenerate them, so those remains options for further actions as well. -
The story is:
I have alot java class files under directory: c:\myproj\com\pin\sa
in each of the file, the package signature is: package com.pin.sa
Then I set the JavaVMInitArgs fVM_args; by setting the classpath to:c:\myproj
then I use: cls = (*fEnv).FindClass("com/pin/sa/frameWork") to find a class file called frameWork, but failed.
then i build a test file called test.class (it is just a simple file pls see below for the code)and put package com.pin.sa in it and put it in directory : c:\myproj\com\pin\sa, this means the test.class is under the same directory as the frameWork.class,
then I use cls = (*fEnv).FindClass("com/pin/sa/test"), and it SUCCEEDED!!!
I really don't understand why like this, they have same package signature and under same directory why different results.
In frameWork file, there are some imported packages, does this matter? And there is a static main() in it.
if you can give an example of how to set the classpath in JavaVMInitArgs fVM_args, and how to deal with the package signature, I will appreciate it very much
==test.java==
package com.pin.sa;
public class test
public void printHello()
System.out.println("Hello World from Java!");
cls = (*fEnv).FindClass("com/pin/sa/test");
cls = (*fEnv).FindClass("com/pin/sa/test");
C:\\myProj\\resiprocate\\myAnalysis\\sipphone\\sipXphone\\main\\softphone\\lib");Hi Hufuman,
What are the packages that you are using in frameWork Class. Add the class path to those classes also. Also check the name of the .class file is exactly the same as frameWork and not FrameWork or framework etc.
Check whether you have correctly given the package declaration in the frameWork class.
If you dont have any problem, post the frameWork class definition also here or atleast the packages imported and the classpath set for those referred packages.
Dhamo. -
Please answer as soon as possible.
Have you tried a rest or hard reset?
Hold your power button and your home button for about 15 seconds until you see the apple logo.
Ignore the power slider when you see it. -
Please can somone help my in built cameral on my MacBook Pro is not working, the green light does not show again and the camera is not working . what can i do to active it back.
SemakoYuu can try to reactivate your iSight camera by opening up iMessage.. navigate to Preferences/Audio Video,and then click on Camera. IT shoudl be grayed-out if you only have one camera hooked up to your machine. If you have an external camera, then disconnect it from your machine.
-
I am running Office 2013. Trying to sync my reminders with my iPhone 5c version 7.1.2 using icloud for windows, but it is not working. Can anyone please help?
-
My mobile is getting hang since last 1 hour, torch of mobile is still on and the touchscreen is not working, I can't unlock my mobile.
Can anyone help me to fix it?Please press the power- and the homebutton simultaneously until the apple logo will appear ( 10 sec.). That´s it.
-
Help needed I updated my ipad2 with iOS5 but few of my dashbaords (HTML5) are not working now ,can any one let me know how to downgrade the OS as we have a meeting coming up .. its urgent
Downgrading the iOS is not supported. If you are using Safari this try clearing its cache via Settings > Safari.
If that doesn't work then try closing Safari completely and then re-open it : from the home screen (i.e. not with Safari 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Safari app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
A third option is a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot. -
Please help me my apple id its not working what do i do?
please help me my apple id is not working what do i do
If you desire speedy resolution it helps to be more specific with error messages etc. when asking a question here.
iTunes Customer Service Contact - http://www.apple.com/support/itunes/contact.html > Get iTunes support via Express Lane > iTunes > iTunes Store -
I cannot get my messages/text messages to work om my Hi. I am sending this thru my iPad. Respond and let me know you got it. Fun fun fun. . I did go and try to another Apple ID different from my iPhone but it still will not work. Can anyone help me?
chicx wrote:
This is the third time of writing this on your Apple Support Communities!
Not with your current user id.
Far too much uneccesary information in your post, which only confuses things, a vast amount!
Let's start with iTunes.
Have you updated iTunes to 11.1.5, because the previous version did appear to have an issue about seeing iPods?
With iTunes 11.1.5 installed, look in Edit/Preferences/Devices, (or use the ALT key, followed by the E key and then the F key) and make sure that the box named Prevent iPods, iPhones and iPads from syncing automatically does not have a tick in the box.
Once you have doen those two things, check to see if the iPod is seen by iTunes.
chicx wrote:
By the way, what does IOS mean? (I thought IO stood for operating system, but am flummoxed by the S on the end.
Really?
OS stands for Operating System. (In computer speak, IO means Input/Output.)
iOS originally stood for iPhone Operating System, but it now refers to the iPod Touch and iPhone. The iPod Classic, which you have listed in your profile as your iPod, does not use iOS.
I assume that you have been listening to the Podcast in your iTunes on the computer as you cannot transfer it to your iPod. It's what I'd do. -
On my macbook pro I have a message on my homepage telling me that certain items want to use my keychain. I've pressed cancel the message will not go. The mac is now running very slow and iphoto and safari are not working. Can anyone help?
What version of Mac OS X?
What home page?
What browser? -
hi, recently i bought macbook pro with retina display and installed windows 8 professional original software also. but in windows 8 track pad/ TOUCHPAD is not working properly. can you help me with providing drivers for trackpad to work on windows 8 professional .
Did you download and install the Windows Support software? If you did, did you use the Boot Camp Control icon to set up the trackpad how you want it?
http://www.apple.com/support/bootcamp/
https://discussions.apple.com/community/windows_software/boot_camp
Maybe you are looking for
-
I get a blank white screen when I try to play games on Club Pogo
as stated earlier, when I go to club pogo, all I get is a blank white screen, firefox will go to site but will not load the games,
-
Satellite P200D - Value Added Package error on Windows 7 64bit
Satellite P200D-12F (PSPBQE) and Windows 7 64bit TVAP ERROR! I cant find any solution to this problem on the whole internet. can someone please contact Toshiba providers about this because this is really silly? Noone wanna answer me! PLZ! help
-
I create files using PS. Sometimes, these files will fail to open in PS at a later date. The error msg is that the file is corrupted. I can open them in Illustrator to view them. But they are lost to opening in PS. Why? And what can I do to corr
-
Custom Step Type: Sequence Call
OK, I'm primarily a LabVIEW programmer, but in TestStand I understand how to: * Create a Custom Step Type * Link a LabVIEW Module for execution, post substep, edit substep, etc. * Prevent the user from selecting a different module for an instance of
-
What does hardware model iPad 3,3 mean?
My iPad is a 3rd generation GSM model. But the diagnostic data sent by my iPad to the apple server(it's a built in feature) states that my hardware model Is iPad 3,3. So far I know for CDMA model they use 3,3 but for GSM it should be 3,2. Am I wrong?