Это мой enum pojo класс для значения c.
package net.transitdata.gtfsRTNYCT;
/**
* Helper for translating feeds to their integer ID
feed_id=1
1-6, S Lines
feed_id=16
N Q R W Lines (Beta Version)
feed_id=21
B D Lines (Beta Version)
feed_id=2
L Line
feed_id=11
Staten Island Railway
*/
public enum FeedId {
A_DIVISION (1),
NQRW (16),
BD (21),
L (2),
SIR (11);
private final int value;
FeedId(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
, затем я создал URLHelper, я перезапустил свой ключ API в исходном коде, который я не могу показать здесь ...
package net.transitdata.gtfsRTNYCT;
import java.net.MalformedURLException;
import java.net.URL;
public class UrlHelper {
// set MTA Datamine key as an environment variable or replace this with a string
private static String baseUrlWithoutFeed = "http://datamine.mta.info/mta_esi.php?key=<MY_MTA_API_KEY>&feed_id=1";
public static URL getFeedUrlFromFeedId(FeedId id) {
String urlString =baseUrlWithoutFeed + id.getValue();
URL url = null;
try {
url = new URL(urlString);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return url;
}
}
и main. java program
package net.transitdata.gtfsRTNYCT;
import com.google.transit.realtime.GtfsRealtime;
import com.google.transit.realtime.GtfsRealtimeNYCT;
import com.google.protobuf.ExtensionRegistry;
import java.io.IOException;
import java.net.URL;
public class Main {
public static void main (String[] args) {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
registry.add(GtfsRealtimeNYCT.nyctFeedHeader);
registry.add(GtfsRealtimeNYCT.nyctStopTimeUpdate);
registry.add(GtfsRealtimeNYCT.nyctTripDescriptor);
URL url = UrlHelper.getFeedUrlFromFeedId(FeedId.BD);
System.out.println("getting feed from " + url.toString());
GtfsRealtime.FeedMessage feed = null;
try {
feed = GtfsRealtime.FeedMessage.parseFrom(url.openStream(), registry);
} catch (IOException e) {
e.printStackTrace();
}
if (feed != null) {
//noinspection CodeBlock2Expr
feed.getEntityList()
.stream()
.filter(GtfsRealtime.FeedEntity::hasTripUpdate)
.forEach(entity -> {
System.out.println(entity.getTripUpdate().toString());
});
}
}
}
Когда я пытался запустить мой код Main. java как Java Приложение в Ecilipse ... это показывает ошибку me как показано ниже ...
getting feed from http://datamine.mta.info/mta_esi.php?key=<MY_MTA_API_KEY>&feed_id=1
com.google.protobuf.InvalidProtocolBufferException: Protocol message tag had invalid wire type.
at com.google.protobuf.InvalidProtocolBufferException.invalidWireType(InvalidProtocolBufferException.java:78)
at com.google.protobuf.UnknownFieldSet$Builder.mergeFieldFrom(UnknownFieldSet.java:498)
at com.google.protobuf.GeneratedMessage$Builder.parseUnknownField(GeneratedMessage.java:438)
at com.google.transit.realtime.GtfsRealtime$FeedMessage$Builder.mergeFrom(GtfsRealtime.java:449)
at com.google.transit.realtime.GtfsRealtime$FeedMessage$Builder.mergeFrom(GtfsRealtime.java:266)
at com.google.protobuf.AbstractMessageLite$Builder.mergeFrom(AbstractMessageLite.java:212)
at com.google.protobuf.AbstractMessage$Builder.mergeFrom(AbstractMessage.java:746)
at com.google.transit.realtime.GtfsRealtime$FeedMessage.parseFrom(GtfsRealtime.java:217)
at net.transitdata.gtfsRTNYCT.Main.main(Main.java:23)
Что я должен изменить, чтобы удалить эту ошибку