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 495595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:36:30+00:00 2026-05-13T05:36:30+00:00

I am writing a program to calculate the shortest path between two nodes. In

  • 0

I am writing a program to calculate the shortest path between two nodes. In my program I have one custom class called NodeList, which contains an ArrayList of strings (representing nodes) along with a distance. I am using Dijkstra’s algorithm which involves opening up the shortest edge from each node. So, I use this loop to tabulate the possible routes from a given point:

for ( NodeList ed : edges )
    {
     if (ed.nodeList.get(0).equals(node1))
     {
      routes.add(ed);
     }
    }

This works fine, and appears to load the correct values into the variables (according to the debugger). However, when I try and set a variable to the distance of one of the nodes, I get a message “cannot find symbol variable distance”. Here is the code that causes the problem:

int minDistance = routes.get(0).distance;

Is this abnormal or is there something obvious I’m missing?

  • 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-13T05:36:30+00:00Added an answer on May 13, 2026 at 5:36 am

    get(0) apparently returned an object of class type which doesn’t have the particular field.

    There are several solutions depending on the root cause of the problem:

    • Parameterize the list if possible (e.g. NodeList<Route> instead of NodeList)
    • Cast it to the right type (e.g. int distance = ((Route) routes.get(0)).distance)
    • Make the field public (e.g. public int distance;)
    • Add a getter (e.g. public int getDistance() { return this.distance; }) and use it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program which has two panes (via CSplitter ), however I
I'm writing a program that contains a generational garbage collector. There are just two
I'm writing a program to calculate a value that is a measure of the
As an exercise I'm writing a program to calculate the odds of rolling 5
I'm writing a small program to calculate a physics problem but I'm having problems
I am writing a program in which I need to draw polygons of an
As a Christmas gift I have written a small program in Java to calculate
I'm writing program in C# for converting between model formats. The model format has
I'm writing a program that has two main functions. Each of the functions will
I'm writing a program that sends an email out at a client's specific local

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.