Word Cannot Be Resolved To A Variable Error
Jun 27, 2014
I am getting an error stating that 'word cannot be resolved to a variable' pointing to my return value. Why? Should I make a default String value for word before my while loop or something, like
String word = " ";
?
String getItRight(){//make sure the user enters the password correctly
Scanner input = new Scanner(System.in);
boolean repeating = true;
while(repeating){
[Code] ....
View Replies
ADVERTISEMENT
Jun 18, 2014
The error "cannot resolve to a variable". I get the error I just can't seem to fix the error.Presently I am working my way through the Oracle docs and that seems ok. Java for Dummies, Sams teach Yourself Java in 21 Days, plus my favorite Head First Java.
package tutorial;
import java.util.*;
public class HolidaySked {
BitSet sked;
public HolidaySked(){
sked = new BitSet (365);
int [] holiday = {1,15,50,148,185,246,281,
316,326,359};
for (int i = 0; i<holiday.length; i++){
addHoliday(holiday[i]);
[code]....
View Replies
View Related
Jan 18, 2015
Here is my current code. The CustomerName in the System.out.print statement doesn't compile - it says that CustomerName can not be resolved to a variable. But why is that true? it is declared and assigned a value in the for loop.
Query query = em.createQuery("select CustomerName from web_cost_file,customer " +
"where web_cost_file.customer=customer.id and web_cost_file.customer=" +
costsFileList[0]);
List<Object[]> listCustomerName = query.getResultList();
for (Object[] result : listCustomerName) {
String CustomerName = result[0].toString();
}
System.out.print(CustomerName);
View Replies
View Related
Feb 7, 2015
I've been using Eclipse and I realized that it compiles stuff into class files for you. So, I created a new project and each class is a separate .java file, with the .class files already there, but I cannot get rid of these errors. Or, say if I wrote them all into one file and then realized it needs to be 3 separate, or that all need to be in the same src file (oops)? Here are the errors:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
random cannot be resolved or is not a field
guessp1 cannot be resolved to a variable
guessp1 cannot be resolved to a variable
guessp2 cannot be resolved to a variable
guessp2 cannot be resolved to a variable
guessp3 cannot be resolved to a variable
guessp3 cannot be resolved to a variable
guessp1 cannot be resolved to a variable
guessp2 cannot be resolved to a variable
guessp3 cannot be resolved to a variable
[code]....
View Replies
View Related
Sep 11, 2014
What I'm trying to do here is to count the vowels in an arraylist of strings. What I did may not be right, but that's not my problem for now. My problem is that i cannot return the value (n) I want to return. I don't know why.
import java.util.*;
import java.util.Arrays;
public class One {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("aaa");
list.add("brr");
list.add("unn");
System.out.println(vowels(list));
[URL] ....
View Replies
View Related
Mar 9, 2014
I'm not sure why I'm getting these errors. They only begin to happen after the second if statement, and the subsequent if statements are formatted exactly the same.
The errors are marked by the comments in the code.
Java Code:
import java.util.*;
import java.io.*;
public class GazillionSongs {
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Welcome to Java Song Collection!");
System.out
.println("This program sorts and filters large databases of popular songs.");
[Code] .....
View Replies
View Related
May 5, 2014
I am getting the error message as Exception in thread "main" java.lang.Error: Unresolved compilation problems: NewExcel cannot be resolved to a type for the line NewExcel test = new NewExcel(); in the below code to read the columns from an excelsheet "test.xls". Why I am getting the error message :-
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadExcel
[Code] .....
View Replies
View Related
Jan 29, 2014
Below is my first ever code. I bolded where i am getting a syntax error. Why am i getting an error here if i assigned that word to a string?
public class BeerBottleTest {
public static void main(String[] args) {
int beerNum = 99;
String bottle = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
bottle = "bottle"; }
[Code] ....
View Replies
View Related
Feb 21, 2015
I know what the error means but I don't think initializing the variable will make my code work as intended so I'm having a little dilemna here... here's the code and I'll highlight the part that is said to be not initialized:
Java Code:
import java.util.Scanner;
public class ItemCost {
public static void main (String []args){
int i=1,item=1,e=1, f=1, g=1;
int items, d ;
double gst, qst, subt, Tot = 1, PriceItems ;
[Code] ....
So I'm supposed to get the following output :
Java Code:
Please input the amount of items bought 2
Please input the price of the item 1 1
Please input the price of the item 2 2
Please input the rate of GST in % 20
Please input the rate of QST in % 18 mh_sh_highlight_all('java');
HOWEVER my program doesn't seem to add input of item 1, and 2 if I initialize subt= 0 initially. It'll only take the last value inputted in the loop. By the way, the increments are counters to count the amount of errors the user might input by accident ( or whatever). Some people have been pointing it out as useless but that's the only way I found it to work.
View Replies
View Related
Oct 12, 2014
I don't understand that the error occurs when I don't initialize the variable myPoint. Whereas, I initialize the variable myPoint after variable declaration and before place of error.
package enumeration;
import java.util.Random;
public class Craps {
[Code]....
When I initialize the variable myPoint to zero in its decleration, the error disappear. But why? I have already initialized the variable myPoint in default case before the line of error occured..
View Replies
View Related
Mar 31, 2014
Consider the following simple code:
public class Test {
private final int arg;
private final Runnable runnable1 = new Runnable() {
@Override
public void run() {
// No errors here, exactly as expected
System.out.println("ARG: " + arg);
[Code] ....
The java compiler (version 1.8.0-b132) produces the following error when compiling this code:
"Error:(14, 46) java: variable arg might not have been initialized"
Actually, I do not expect the error here.
Both declarations 'runnable1' and 'runnable2' are essentially the same: these are just Runnable objects accessing value of the 'arg' field (which is initialized in the constructor).
The only difference between the declarations is that 'runnable1' - is an old-fashion instantiation of Runnable, whereas 'runnable2' - is an instantiation of Runnable via a lambda expression.
View Replies
View Related
Mar 23, 2015
I'm getting this error, I definitely know that is my error trying to pass method/variable because when I commented received part of my code it ran and worked.
I get this error
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Here are my 2 classes
Java Code:
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
[Code] .....
View Replies
View Related
Feb 28, 2015
I want to use a try catch block, but I am not sure how to fix this problem:
int a;
try{
a = Integer.parseInt(A.getText());
}
catch (Exception e){
Output1.setText("Error");
}
//do someting with a here
The purpose of the try-catch is to catch blank input.The problem with this is that underneath the try - catch I get an error saying that the variable might not have been initialized. I know why this happens. I know I could initialize the varaible before the try - catch, but there is no default or null I can set an int as. If I initialized it as 0, the blank input will no longer be catched.how to make this problem disappear?
View Replies
View Related
Sep 14, 2014
I am trying to create this program I am pretty sure it is easy but I am making it difficult lol, it keeps giving me a error, it is saying cannot find symbol - variable keyboard, I don't think I have keyboard as a variable but I may be wrong.
double distancel = keyboard.nextdouble(); that is the specific line ....
import javax.swing.JOptionPane;
import java.io.File;
import java.util.Scanner;
//import java.util.totalInches;
//instance variables
public class Map{
public static void main(String[] args){
[Code] ....
View Replies
View Related
Dec 14, 2014
My dynamic web project has a java class that captures a session variable with the following code.
HttpSession LoginSession = request.getSession();
String VAR = LoginSession.getAttribute("myVar").toString(); //This is the row 127
If i test the app in local (Mac + Java 1.8 + Tomcat 8) all works. In my remote cloud server (Ubuntu 14.10 + Java 1.8 + Tomcat 8) all works, except this class, that has this code. I copy the complete error here. Note that the row 127 of the error message is the second row of the previous code; and, if i comment this row with // and assign a fix variable all works. So, the problem is that 127^ row.
14-Dec-2014 08:15:23.923 SEVERE [http-nio-8080-exec-14] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [srvNavigation.SrvPT] in context with path [/myapp] threw exception
java.lang.NullPointerException
at srvNavigation.SrvPT.doGet(SrvPT.java:127)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
[Code] ....
How can i solve the problem?
View Replies
View Related
Apr 27, 2015
I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.
As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?
public void findUnique() {
System.out.println("There are " + findUniqueWords(root, 0) + " unique words.");
}
private int findUniqueWords(Node subTree, int uniqueCount) {
// Base Case: At the end of the branch
if(subTree == null){
return uniqueCount;
[Code] ....
View Replies
View Related
Jun 25, 2014
I am new to Java and trying to learn it.I wrote the following program but while creating the method nav i am getting errors.
Error:- void is an invalid type for the variable nav
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.*;
public class YahooHomepage {
private static WebDriver driver;
[Code] .....
View Replies
View Related
Jul 31, 2014
I am trying to use a JFrame to open up extra windows that will prompt the user the Log In or Out, but I am getting an error with one of my variables that writes to Excel. There is something wrong with the variable "sheet" contained in the "while(i <= 4)"
private void createLabel(WritableSheet sheet) throws WriteException
{
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
times = new WritableCellFormat(times10pt);
times.setWrap(true);
WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);
[Code] .....
View Replies
View Related
Mar 13, 2015
The intentions of this program is to prompt a user to enter a file name, and then reads the file. The program will prompt the user to enter a word that needs to be corrected. So lets say I have a text file containing "My name is OP and I Like goind to the Park!" I want to change "goind" to "going",
Now, my second method "isSimilar" executes a similar word with more than one same letter and same length, but I dont know how to execute that whole thing in my third method "correctThisLine" . How I can call that isSimilar method and read in that text file and change that word into that?
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class WahidMuhammadA3Q2{
String fileName = "AutoCorrectMe.txt";
public static void main (String [] args){
[Code] ....
View Replies
View Related
Aug 19, 2014
I am looking for java codes to generate a word document based on a word template, basically, I have a word template created and in my local path, the template has a proper format with some fields which will be filled in after java codes ran. The java codes will fetch one record from a table, and open the word template and then fill the fields in the word template, and created a new word document and save it in another folder.
I found this example: [URL] which is similar except it uses xml template instead of word template, how to make it work to change the template from xml to word (docx) template?
View Replies
View Related
Jun 5, 2012
Im running into some problems with the Java compiler. This is my code:
public class DoublyLinkedList<T> implements SimpleList<T> {
protected Node dummy;
protected int n;
public DoublyLinkedList(){
dummy = new Node();
dummy.next = dummy;
dummy.pre = dummy;
n = 0;
[Code] ....
I want to use a dummy node in my implementation of the Doubly Linked List, so it will be easier to code all the methods I need to write. I keep on getting a problem with line 14 and 15:
dummy.next = dummy;
dummy.pre = dummy;
// cannot find symbol variable next (compiler error)
// cannot find symbol variable pre
View Replies
View Related
Jul 1, 2014
Here's My Code.
package bin;
import java.util.Scanner;
public class AppletMain{
public static void main(String[] args){
Scanner oneinput = new Scanner(System.in);
String one;
[Code] ....
I am trying to get it to compare the word I type in to the set word in the object 'secretword'. I have tried everything from equal to == to compareTo, I even created a two hundred line program to do this SIMPLE problem.
View Replies
View Related
Apr 21, 2014
import java.io.*;
import java.util.Random;
import java.util.Scanner;
public class WordGame
{
public static void main(String[] args) throws IOException
{
final int RANDOM_LETTERS_COUNT = 10;
final int TRIALS = 10;
int score = 0;
[Code] ....
View Replies
View Related
Aug 27, 2014
I Can't run this simple program
import java.util.Scanner;
import javax.swing.JOptionpane;
public class Project {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
[code]...
This is the Error that i get in console!"Exception in thread "main" java.lang.Error: Unresolved compilation problem: JOptionPane cannot be resolved at Project.main(Project.java:10)"
View Replies
View Related
Jun 2, 2014
I am trying to read a file that will be contained within the Jar. I have created a source folder in eclipse and put the file in there. The examples I can find online to do this are not working out for me. I am getting an error that getClass cannot be resolved.
Java Code:
private static void help() {
version();
try {
InputStreamReader is = getClass.getClassLoader().getResourceAsStream("data/cmdhelp");
int c;
do {
c = is.read();
System.out.print((char) c);
} while (c > -1);
System.out.println();
} catch (IOException e) {
System.out.println("JAR file has not been packaged correctly.");
}
} mh_sh_highlight_all('java');
The error from eclipse:
getClass cannot be resolvedCommand.java/accface/src/frontendline 29Java Problem
View Replies
View Related
Mar 2, 2012
I found some code online to draw a pink heart.. sort of a valentine's day heart.. I would like to add to it and customize it some... But I can't get it to work as-is.. I get a compile error that "StdDraw Cannot be resolved" ...
Here is the code..
import java.awt.color.*;
import java.awt.Graphics;
import javax.swing.JPanel;
public class Heart {
public static void main(String[] args) {
StdDraw.setXscale(-1.5, +1.5);
[Code] .....
View Replies
View Related