Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:47:22+00:00 2026-05-27T04:47:22+00:00

So I’m using Processing to draw a map from a data file. I want

  • 0

So I’m using Processing to draw a map from a data file. I want to stock some information of the first line inside a class. In processing this class is an inner class of PApplet, so it has to be a static class (Otherwise i get an error: static fieldscan only be declared in static or top level type).

public static class PlacesInfo{
    static final int totalCount;
    static final float xMin;
    static final float yMin;
    static final float xMax;
    static final float yMax;
    static final int populationMax;
    static final int densityMax;


    //Set all static variables once
    static{
      String[] lines =  loadStrings("population.tsv");
      String info = lines[0].substring(2); //to delete some useless char
      String[] infoInit = split(info, ','); //to parse the data of the first line

      totalCount = int(infoInit[0]);
      xMin = float(infoInit[1]);
      xMax = float(infoInit[2]);
      yMin = float(infoInit[3]);
      yMax = float(infoInit[4]);
      populationMax = int(infoInit[6]);
      densityMax = int(infoInit[8]); 
    }
}

When I run this code, I get an error, because I can’t use the loadStrings() function (which is non-static).

So what I want is to have static final variables that I can initialize from the “population.tsv” file. What are your ideas/advices?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:47:23+00:00Added an answer on May 27, 2026 at 4:47 am

    1) Make the method static, and you will be fine — static code must be in order must be compiled in order. Put the loadStrings function before the static code block.

    Please note : However – you might be better off simply creating a single, static , “init” method, which is called in your static code block . This will be nameable and unit-testable, unlike your current implementation.

    2) By the way : your float syntax is off, and must to be casted properly.

      int i = (int) 1.4f; 
    

    3) To initialize the static variables you can do the following :

    • Declare a static init() method, which reads the file and initializes the static variables.
    • Create a separate FileReader object in a separate class, or a static inner class, which can be invoked to read in variables , and invoke it FROM your static code block.
    • (bad idea) Put the file reading logic inside of your big static code block . this will be very ugly however.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.