Netbeans - Method Cannot Be Applied To Given Types
Sep 23, 2014
Here is my code:
import java.util.*;public class DebugSix {
public static void main(String[] args) {
ArrayList<String>products = new ArrayList();
products.add("shampoo");
products.add("moisturizer");
products.add("conditioner");
Collections.sort(products);
[Code] ....
I am using netbeans and getting errors for display(); and size(); it is telling me the errors are :
for the display error, "method display in class DebugSix cannot be applied to given types;
display();" and for the size() is : "cannot find symbol System.out.println("
The size of the list is " + size());"
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
public class Circle { private double PI = 3.14159; private double radius; public Circle() { radius = 0.0;
[Code] ....
This is the error i am receiving:
Circle.java:78: error: method getRadius in class Circle cannot be applied to given types; System.out.println("A circle with a radius of " + circle.getRadius() + " will have an area of " + circle.getArea() + " , a diameter of " + circle.getDiameter() + " and a circumference of " + circle.getCircumference()); ^ required: double found: no arguments reason: actual and formal argument lists differ in length 1 error
I'm new to programming and I have an assignment due in java class. Here is the error code:
TestCircle.java:10: error: method setradius in class Circle cannot be applied to given types; circle1 = inputCircle.setradius(); ^ required: double found: no arguments reason: actual and formal argument lists differ in length
And here is my code:
import java.util.Scanner; public class TestCircle { public static void main(String[] args) { double circle1; double circle2; double circle3; Circle inputCircle = new Circle();
I'm getting an error on line 51 and don't know what it means?
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package million; import java.util.Scanner; import java.util.ArrayList;
I'm doing an exercise we're you're supposed to sort strings in alphabetical order, without importing anything , not using the Arrays.sort() method.
I think I got the method down partially right, or it is on the right track, but it is completely not being applied to my answer. All it prints out in the console is the actual String array twice, without sorting anything.
public class arrayofstrings { public static void sort(String[] a) { String temp= ""; int min; int i= 0; for (int j=0; j<a.length-1; j++) {
I am having trouble with methods. What I want to do is be able to create 4 types of strings under the same method, but only draw one of them at a time.
Trying to find a way to use primitive data types to overload sound()method. I can't seem to warp my head around using an int or a double to overload the method. And if I did, how do you call them in the main afterwards?
I am trying to remove the duplicate elements from ArrayList using .contains() if elements are primitive datatype it works but user-defined datatype does not work.
public class UserBean { String name; String address; public String getName() { return name;
I need to debug the equals method implementation of a class I've made, but I cannot for the life of me get Netbeans' debugger to step into it. I can step into other methods from the class (most of which implement the methods in an interface) that are called in the main method (just like the equals method). I've tried...
-Disabling all the step filters -Clearing the Netbeans cache -Moving the call to the equals method out of the if statement it's in and just calling it as its own statement -placing breakpoints within the equals method as well as on the call to the method -placing a method breakpoint on the overridden equals method in addition to the other locations -Using the shift-F7 version of the step into command
I'm using Netbeans 8.0.1 (I don't know if this is the latest version, but the last time I tried to update everything died and I had to completely remove NB and reinstall it) and JDK 8u05 (I think).
I am writing a program in the GUI Builder and found that when I add code to print user input from text fields to a text file, the main method is no longer recognized. It throws all kinds of errors.
I have been able to get the code to work separately in a project file. Also, have been able to print to the console.
I have noticed a strange behavior of Combobox element. The number of visible rows is not the same established by setVisibleRowCount() method. It happens when changing the items list dynamically. The following example reproduces it. I think it is Javafx 8 bug. I have tried unsuccessfully to trigger some event indirectly to refresh the combobox drop down.
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class TestComboBox extends Application { private int count;
I can understand result 3 is because of an upcast from short to int, since FunWithOverloading will not have a overloaded method with short now. However, what is happening with result 4? Shouldn't it call methodA of the subclass with the argument type short? If its because I have declared the reference variable, derived, of the type FunWithOverloading, then how come the first result correctly picks the overloaded method of the sub class?
class FunWithOverloading{ void methodA(int x){System.out.println("Integer method " + x);} void methodA(short x){System.out.println("Short method " + x);} //line 3 } class OverloadedSubClass extends FunWithOverloading{ void methodA(short x){System.out.println("Sub class short method " + x);}
how objects relate to classes and how you can create and re-use object types.on that point, but this has me baffled. I most certainly do not have a firm grasp yet on passing things to and from methods that just makes my head hurt. SO anyway I tried out one of the code examples:
/* ElectricGuitar.java */ class ElectricGuitar { String brand; int numOfPickups; boolean rockStarUsesIt;
[code]...
But I just realized this thing has no main method and only one class defined.....so I guess I just tried to compile.
I am trying to understand the concept of Generics in java. In the introduction to Generic Types, this example is given:
Java Code: public class Box { private Object object; public void set(Object object) { this.object = object; } public Object get() { return object; } } mh_sh_highlight_all('java'); "Since
Since its methods accept or return an Object, you are free to pass in whatever you want, provided that it is not one of the primitive types." - I understand this.But then it has been changed to a generic class:
Java Code: /** * Generic version of the Box class. * @param <T> the type of the value being boxed */ public class Box<T> { // T stands for "Type" private T t;
public void set(T t) { this.t = t; } public T get() { return t; } } mh_sh_highlight_all('java'); "
As you can see, all occurrences of Object are replaced by T. A type variable can be any non-primitive type you specify: any class type, any interface type, any array type, or even another type variable."We can use any type in place of an Object, because Object is a superclass of all classes. But T (or any other class) is not a superclass of all classes. So how do we justify any class being used in place of a random T or any other class?
public class AutoBoxingExample { public void add(Integer intVal){ System.out.println("Wrapper"); } public void add(int value){ System.out.println("Primitive"); } public static void main(String[] args) { AutoBoxingExample auto = new AutoBoxingExample(); auto.add(12); } }
The output is "Wrapper". What would be the reason behind it?
GoodEmployee is defined who has ALL the following properties:
He should be married. He should have 2 or less than 2 children. His middle name should start with "k" but not end with "e" The last name should have more than 4 characters The character "a" should appear in the last name at least two times. The name of one of his children should be "Raja"
isMarried true if the employee is married. noOfChild the number of children of the employee. middleName the middle name of the employee lastName the last name of the employee. childNames the array of the names of the children of the employee