I'm new to java and following a book called "Learn java in 21 days". while Following it i was writing a piece of code similar to the one written in book but it gave an error of "non-static variable this cannot be referenced from a static context" while in the book the author is getting proper output and he didn't mention about the error. Can any one please tell me what is this error? i have tried checking this problem but i'm unable to understand as in book there is no error but in my code its shown as error. I'm using NetBeans.
i tried replacing float's F or decimal points etc
package com.java21days;
import java.util.*;
public class ComicBooks{
public ComicBooks() {
}
public static void main(String[] args) {
HashMap quality = new HashMap();
// Setting of hash
float price1 = 3.00F;
quality.put("mint", price1);
float price2 = 2.00F;
quality.put("Near mint", price2);
float price3 = 1.50F;
quality.put("Very Fine", price3);
float price4 = 1.00F;
quality.put("Fine", price4);
float price5 = 0.50F;
quality.put("Good", price5);
float price6 = 0.25F;
quality.put("poor", price6);
// Getting Values
Comic[] comix = new Comic[3]; // array of Commic objects
comix[0] = new Comic("Amazing Spider-Man", "1A", "very fine",12_000.00F);
comix[0].setPrice( (Float) quality.get(comix[0].condition) );
}
class Comic{
String title;
String issueNumber;
String condition;
float price;
float basePrice;
public Comic(String inTitle, String inIssueNumber, String inCondition, float inBasePrice){
title = inTitle;
issueNumber = inIssueNumber;
condition = inCondition;
basePrice = inBasePrice;
}
void setPrice(float factor){
price = basePrice * factor;
}
}
}
Those who have access to the book can see output on the page 235