gpt4 book ai didi

java - 3 x "Syntax error on token(s)"- 基本 Java 声明

转载 作者:行者123 更新时间:2023-12-01 15:12:16 26 4
gpt4 key购买 nike

我正在开发一个 Java RESTful Web 服务,由于某种奇怪的原因,我得到了 3 个我完全不确定的 Java 标记。

这是我的代码:

package au.com.rest; //self made package
import javax.ws.rs.*; //JaxRS
import javax.ws.rs.core.*;
import au.edu.uts.it.wsd.*; //Package containing the relevant classes

@Path("/feedlist")
public class RESTFeedService {

String name, uri, action, feedFile;
String textReply = "Feed ";
String xmlReply = "<?xml version=\"1.0\"?> \n<feeds> \n";

feedFile = "/tmp/feeds.txt";
action = request.getParameter("action");
name = request.getParameter("feedName");
uri = request.getParameter("uri");

Feed feed = new Feed(name, uri);
FeedList feedList = new FeedListImpl();

feedList.load(feedFile);

@GET
@Produces(MediaType.TEXT_PLAIN)
public String showTextFeeds()
{
for (Feed f:feedList.list()){
textReply += "[Feed Name: " + f.getName() + ", ";
textReply += "[Feed URI: " + f.getURI() + "]"; }
return textReply;
}



我收到的错误如下:

String xmlReply = "<?xml version=\"1.0\"?> \n<feeds> \n";

标记“;”存在语法错误,{应在此标记之后

feedFile = "/tmp/feeds.txt";

标记“String”存在语法错误,@预期

public String showTextFeeds()

token 语法错误、结构错误

请指出我做错了什么的正确方向。谢谢!

最佳答案

String name, uri, action, feedFile;

feedFile = "/tmp/feeds.txt";
action = request.getParameter("action");
name = request.getParameter("feedName");
uri = request.getParameter("uri");

应该是

String name = request.getParameter("feedName");
String uri = request.getParameter("uri");
String feedFile = "/tmp/feeds.txt";
String action = request.getParameter("action");

关于java - 3 x "Syntax error on token(s)"- 基本 Java 声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12176416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com