ramarar Posted September 19, 2014 Share Posted September 19, 2014 I have been trying to run some string classes in java through bluej but keep encountering this error Error: cannot find symbol class lang during runtime. I have tried reinstalling java and bluej but it didn't work. Any solutions for this? Link to comment https://gtaforums.com/topic/738325-bluej-error/ Share on other sites More sharing options...
trip Posted September 20, 2014 Share Posted September 20, 2014 Never heard of bluej. (after a 1 minute briefing on bluej)Make sure you have a constructor and it is the same name as the class. It sounds like bluej gives you a base framework when you start a project. I'm willing to bet that it is something silly that you will want to kick yourself for not seeing once you get it working. If you want to post your code here(use tags) we can help debug. Maybe switch to eclipse as your java IDE. Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066210839 Share on other sites More sharing options...
ramarar Posted September 21, 2014 Author Share Posted September 21, 2014 public class initials{ public initials(String x) {int n=x.length();char []a=x.toCharArray();System.out.print(x.charAt(0)+".");for(int i=1;i<=n;i++){if(a[i]==' ') { System.out.println(a[i+1]+"."); }}}} Well I ran this same code at school and it worked fine which makes me rule out any error in the code but I might be missing something too. Bluej is described to us at school for our computer syllabus which is why I am preferring it to eclipse. Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066214622 Share on other sites More sharing options...
Furry_Monkey Posted September 21, 2014 Share Posted September 21, 2014 It's fairly straight-forward code so I'm not sure what's causing the error. Maybe check your Java SDK installation. But, I'd recommend using split, rather than parsing an array of characters. If you use x.split(" ") then it will return an array containing all the words in the string. It will be easier to work with, as well as having much better performance. Okay, that's not really an issue with such a simple function, but it makes sense to get used to always looking for the best performance, as long as it doesn't make the code unreadable. Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066218198 Share on other sites More sharing options...
ramarar Posted September 22, 2014 Author Share Posted September 22, 2014 Re installed the Sdk .Didn't work.Any other solutions? Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066220077 Share on other sites More sharing options...
reiniat Posted September 24, 2014 Share Posted September 24, 2014 (edited) That code throws an IndexOutOfBoundsException everytime you run it: This line: for(int i=1;i<=n;i++) should be like this: for(int i=1;i<n;i++) Youre using an array, the last index is n-1, not n. Edited September 24, 2014 by reiniat Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066228100 Share on other sites More sharing options...
ramarar Posted September 24, 2014 Author Share Posted September 24, 2014 I must have made an error in typing over there but other than this what can I do to solve the error. Could the problem be in the jar or bin files? Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066229135 Share on other sites More sharing options...
reiniat Posted September 24, 2014 Share Posted September 24, 2014 (edited) I can only think on the basic stuff. Did you set the PATH variable? Also you should have reinstalled BlueJ after reinstalling the Java SDK, and thinking about it, is this the last version of BlueJ too? Also you could import the toCharArray() method with: import java.io.*; Above the public class declaration....Although that not supposed to be required in standard BlueJ environment, it should work. And try import java.lang.*; and tell me what happens, did you chose the correct Java SDK when installed BlueJ? (install BlueJ again) Edited September 24, 2014 by reiniat Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066231051 Share on other sites More sharing options...
ramarar Posted September 25, 2014 Author Share Posted September 25, 2014 I already tried importing both io and lang package but it didn't work. By PATH variable do you mean the one used to access javac in command prompt. I am using the latest version of bluej and java and I have tried reinstalling too in the same way as you suggested. Java SDK is also the right one and I even downloaded it again. My thoughts dart to runtime because this appears during runtime. Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066232254 Share on other sites More sharing options...
ramarar Posted September 27, 2014 Author Share Posted September 27, 2014 Still trying to solve the problem. I noticed something strange when I decided to use a string within the program instead as a parameters. This program is supposed to print initials of names but when I ran it using a string "Nico Belic" it gave output 124112 instead of N.B. and If I use any other name then also numbers are given out but when I ran a program to print vowels in the string then the output came right. The lang error occurs only when I try to use String as parameters even when executing the simplest of the program with a string which is to display the entered string itself. Could this be a problem with the lang package or it goes deeper? Here is the code for vowels program public class pro { void disp() { String x="Nico Bellic"; int l=x.length(); char t; int c=0; for(int I=0;i<l;i++) { t=x.charAt(i); if(t=='a' || t=='e' || t=='i' || t=='o' || t=='u') { c++; } } System.out.println©; } } Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066241693 Share on other sites More sharing options...
K^2 Posted September 29, 2014 Share Posted September 29, 2014 Could you post your entire code? Not just the class/function you are running? Not sure that it will make a difference, but I don't see anything wrong in that segment, so maybe there is some weird memory thing going on with the rest of it. I've seen weirder string output bugs result from a memory leak. Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066249080 Share on other sites More sharing options...
ramarar Posted September 29, 2014 Author Share Posted September 29, 2014 My f"""""""""""""""""""ing fault for putting single quotes instead of double in the print statement due to which it becomes a character which results in those numbers. So this weird output was my fault and it may be excluded from the problem. K^2,What do you suggest about the lang error ?Could it be a problem with bluej or java or my system? Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066249153 Share on other sites More sharing options...
xtal256 Posted December 5, 2014 Share Posted December 5, 2014 I don't see a main method in the code you posted above. As K^2 said, can you please post your entire code here (or upload to PasteBin if it's large). Also post the command line you used to compile it (e.g. javac initials.java). If you are compiling directly through BlueJ, try and find out what command line it's generating. Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066605620 Share on other sites More sharing options...
Whiskey Posted December 10, 2014 Share Posted December 10, 2014 (edited) Have you tried running the code on a different IDE? Try running it on Eclipse or a different IDE. Could be a possible error with the compiler. You could also try compiling your code online here. http://ideone.com/ Edited December 10, 2014 by Whiskey Link to comment https://gtaforums.com/topic/738325-bluej-error/?do=findComment&comment=1066629679 Share on other sites More sharing options...
Recommended Posts