• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • paul wheaton
  • Paul Clapham
Saloon Keepers:
  • Piet Souris
Bartenders:

Help generated Java-file Protoc

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this file suggested by ChatGPT.

I get all sorts for errors . Some I kind of understand, others not.

So if I generated a Java-file with protoc, should I run the Java-file from where I run Protoc?

 
Master Rancher
Posts: 5152
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I get all sorts for errors .

Can you copy the full text of the error messages and paste them here?
 
Marshal
Posts: 4935
624
VSCode Eclipse IDE Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
protoc  is a compiler for .proto IDL files, which can be used to generate source for a variety of programming languages including Java, Kotlin, C++, Python, etc.

My choice for using a .proto file in a Java project would be to use Maven, and have it call protoc at build time.  

You would need to download the .proto file from https://gtfs.org/documentation/realtime/proto/ (or some other source), and then place it in the src/main/proto/ directory in your project.

When you build (mvn clean compile), the Java file(s) will be generated and placed under the project's target/generated-sources/protobuf/java directory.

Here's an example pom.xml


If you don't want to work with the .proto files, then you could add the dependency referenced here: https://mvnrepository.com/artifact/com.google.transit/gtfs-realtime-bindings to your project.

Here's an example pom.xml using the dependency:


And if you don't want to use Maven at all, then you could just download the  jar file from here: https://repo1.maven.org/maven2/com/google/transit/gtfs-realtime-bindings/0.0.4/gtfs-realtime-bindings-0.0.4.jar and use it directly in your project.
 
Lars Persson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:

I get all sorts for errors .

Can you copy the full text of the error messages and paste them here?




Not sure how to copy alot of errors but I took a screenschot.
Ska-rmavbild-2025-11-20-kl.-13.49.00.png
[Thumbnail for Ska-rmavbild-2025-11-20-kl.-13.49.00.png]
 
Ron McLeod
Marshal
Posts: 4935
624
VSCode Eclipse IDE Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lars Persson wrote:Cannot resolve symbol 'google' :4
Cannot resolve symbol 'google' :5
Cannot resolve symbol 'FeedMessage' :18
Cannot resolve symbol 'FeedMessage' :22
Cannot resolve symbol 'FeedMessage' :26
Cannot resolve symbol 'FeedMessage' :35
Cannot resolve symbol 'FeedMessage' :41
Cannot resolve symbol 'FeedEntity' :42
Cannot resolve method 'getEntityList()' :42
Cannot resolve method 'hasTripUpdate()' :43
Cannot resolve symbol 'TripUpdate' :44
Cannot resolve method 'getTripUpdate()' :44
Cannot resolve method 'getTrip()' :45
Cannot resolve method 'getTrip()' :46
Cannot resolve method 'getStopTimeUpdateCount()' :47
Cannot resolve symbol 'FeedMessage' :53
Cannot resolve symbol 'FeedEntity' :54
Cannot resolve method 'getEntityList()' :54
Cannot resolve method 'hasAlert()' :55
Cannot resolve method 'getId()' :56
Cannot resolve method 'getAlert()' :57
'URL(java.lang.String)' is deprecated since version 20 :27
Typo: In word 'skane' :15
Typo: In word 'skane' :16


It looks like the classes/package are not visible to the compiler/IDE.  he required imports might be missing/errored or a library/dependency is not present.

Can you post the source code associated with the errors?
 
Ron McLeod
Marshal
Posts: 4935
624
VSCode Eclipse IDE Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A fix for the URL warning would be to replace this:with this:or just:
 
Lars Persson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

Lars Persson wrote:Cannot resolve symbol 'google' :4
Cannot resolve symbol 'google' :5
Cannot resolve symbol 'FeedMessage' :18
Cannot resolve symbol 'FeedMessage' :22
Cannot resolve symbol 'FeedMessage' :26
Cannot resolve symbol 'FeedMessage' :35
Cannot resolve symbol 'FeedMessage' :41
Cannot resolve symbol 'FeedEntity' :42
Cannot resolve method 'getEntityList()' :42
Cannot resolve method 'hasTripUpdate()' :43
Cannot resolve symbol 'TripUpdate' :44
Cannot resolve method 'getTripUpdate()' :44
Cannot resolve method 'getTrip()' :45
Cannot resolve method 'getTrip()' :46
Cannot resolve method 'getStopTimeUpdateCount()' :47
Cannot resolve symbol 'FeedMessage' :53
Cannot resolve symbol 'FeedEntity' :54
Cannot resolve method 'getEntityList()' :54
Cannot resolve method 'hasAlert()' :55
Cannot resolve method 'getId()' :56
Cannot resolve method 'getAlert()' :57
'URL(java.lang.String)' is deprecated since version 20 :27
Typo: In word 'skane' :15
Typo: In word 'skane' :16


It looks like the classes/package are not visible to the compiler/IDE.  he required imports might be missing/errored or a library/dependency is not present.

Can you post the source code associated with the errors?



Thanks!
 
Lars Persson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:A fix for the URL warning would be to replace this:with this:or just:



Thanks! I have tried alot of versions and will test again and probably come back.
 
Lars Persson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. I do feel stupid and lost.

How do I use the jar-file? Can I just copy the pom.xml if I start using Maven. (I have tried it a bit).

Here is what I did:

I fixed the protoc and the proto file.

Then ran this:

protoc --java_out = java2 gtfs-realtime.proto

This resulted in the path that Ron showed to GtfsRealtime.java.

As I understand (and I could be wrong) you shouldn't change this java-file. Instead you should use it's classes and functions in another file.

Here is where I go wrong. I tried to create a java-project using the help of chatGPT (or CoPilot which I think uses ChatGPT).

I pasted the code suggested by CoPilot but keep getting errors. That made me doubt that I had the project in the right place.

I am not an expert programmer but I do get that FeedMessage and FeedEntity (in the error-list) seems to be functions from GtfsRealtime.java.

Among other things this has confused me:

package com.google.transit.realtime;

I get an error but package is kind of namespace as I get it.

Also thinking I have the project in the wrong place since it's an path to GtfsRealtime.java.

I kind of feel like I came a long way and it shouldn't be to hard to solve. Still I'm stuck.

I have understood (I think) that you should'nt download the .pb-file but instead read the stream.

This is where I got the API from:

https://www.trafiklab.se/sv/api/gtfs-datasets/gtfs-sweden/realtime-specification/

Any more help would be greatly appreciated.
 
Ron McLeod
Marshal
Posts: 4935
624
VSCode Eclipse IDE Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be helpful to understand what your development environment looks like.

From the image that you posted earlier, it looks like you are using the IntelliJ IDE - it that correct?
 
Lars Persson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:It would be helpful to understand what your development environment looks like.

From the image that you posted earlier, it looks like you are using the IntelliJ IDE - it that correct?



Yes, I use IntelliJ.
 
reply
    Bookmark Topic Watch Topic
  • New Topic