对于作业,我必须制作一个Android tv-guid应用程序。 作业说明指出:
我认为我在前两步做了锻炼,但我无法完成最后一步。有谁知道我做错了什么。我附上了所有代码。
ChannelInterface.java
public interface ChannelInterface {
/**
* Method that returns the name of this channel, e.g. "Nederland 1".
* @return String channel name.
*/
public String getName();
/**
* Method that returns the list of programs scheduled on this channel.
* @return ArrayList of Programs.
*/
public ArrayList<Program> getPrograms();
/**
* Method to add a program to the list of programs.
* @param program The program that is to be added to the list.
*/
public void addProgram(Program program);
ChannelParserInterface.java
public interface ChannelParserInterface {
/**
* Method invoked by the app to create the list of channels. This method should:
* - read the program details from file (txt/xml)
* - create the <code>ArrayList<Program></code> for each channel
* - create the Channel object for each channel (setting their name and program list)
* - return the list of create Channel objects.
* Before returning the list of Channels, make sure that no gaps exist in the Program Lists of each channels (fill the gaps!).
* @return The ArrayList of Channels.
*/
public ArrayList<Channel> createChannels();
}
ChannelParser.java
public class ChannelParser implements ChannelParserInterface {
/**
* Hulp methode om het bestand van internet in te lezen en als Stream aan te bieden.
* @param type "xml" of "txt" om aan te duiden welk bestand je wilt gebruiken
* @return De InputStream die gelezen kan worden.
*/
private InputStream openStream(String type) {
try {
URL url;
if(type.equals("xml"))
url = new URL("http://ict1.tbm.tudelft.nl/epg.xml");
else
url = new URL("http://ict1.tbm.tudelft.nl/epg.txt");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
return con.getInputStream();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public ArrayList<Channel> createChannels() {
ArrayList<Channel> result = new ArrayList<Channel>();
Scanner input = new Scanner(openStream("txt"));
ArrayList<Program> programlist = new ArrayList<Program>();
Channel nederland1 = new Channel();
Channel nederland2 = new Channel();
Channel nederland3 = new Channel();
Channel rtl4 = new Channel();
Channel rtl5 = new Channel();
Channel sbs6 = new Channel();
Channel rtl7 = new Channel();
Channel net5 = new Channel();
Channel veronica = new Channel();
Channel discovery = new Channel();
result.add(new Channel());
return result;
}
Program.java
public class Program implements ProgramInterface {
public String title, subtitle, description, category, startTime, endTime;
public Program(String title, String subtitle, String description, String category, String startTime, String endTime) {
this.title = title;
this.subtitle = subtitle;
this.description = description;
this.category = category;
this.startTime = startTime;
this.endTime = endTime;
}
public String getTitle() {
return title;
}
public String getSubtitle() {
return subtitle;
}
public String getDescription() {
return description;
}
public String getCategory() {
return category;
}
public String getStartTime() {
return startTime;
}
public String getEndTime() {
return endTime;
}
Channel.java
public class Channel implements ChannelInterface {
private String name;
private ArrayList<Program> programs;
public String getName() {
return name; //vergeet het return type niet
}
public ArrayList<Program> getPrograms() {
return programs;
}
public void addProgram(Program program) {
this.programs.add(program);
}
我在ChannelParser.java中收到错误,因为Arraylist不起作用,但我不知道如何解决它。