为什么我的视图没有加载
Why isn't my view loading
我正在制作一个学校项目,但无法加载。
除了我打印到日志中的内容之外,绝对 NO 错误日志,但我确实得到了一些关于 Connector Trackers
的信息
以下是部分截图
![]
(http://pierlot.com.au:8888/repository/images/Screenshot.png)
![]
(http://pierlot.com.au:8888/repository/images/Screenshot2.png)
note the top bar is flashing
这是我的代码
class information extends CustomComponent{
/**
*
*/
private static final long serialVersionUID = 1L;
public information(String... filenames){
VerticalLayout information = new VerticalLayout();
Label text = new Label();
text.setContentMode(ContentMode.HTML);
HashMap<Integer,Integer> pageno = new HashMap<Integer,Integer>();
pageno.put(0,0);
Button nextb = new Button(FontAwesome.ARROW_CIRCLE_O_RIGHT);
Button previousb = new Button(FontAwesome.ARROW_CIRCLE_O_LEFT);
nextb.addClickListener(event -> {
if(pageno.get(0)==filenames.length){
}else{
pageno.put(0,pageno.get(0)+1);
}
});
previousb.addClickListener(event -> {
// TODO Auto-generated method stub
if(pageno.get(0)==0){
}else{
pageno.put(0,pageno.get(0)-1);
}
});
String f = File.separator;
String baseadress=new String("C:"+File.separator+"Users"+File.separator+"Countrywide Austral"+File.separator+"OneDrive"+File.separator+f+"ERPs"+f+"Term 4"+f);
setCompositionRoot(information);
information.addComponent(text);
information.addComponent(new HorizontalLayout(nextb,previousb));
while(true){
try {
TextFileProperty stri=new TextFileProperty(new File(baseadress+filenames[pageno.get(0)]+".txt"));
text.setPropertyDataSource(stri);
} catch (ReadOnlyException | ConversionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public class SetiView extends CustomComponent implements View {
private static final long serialVersionUID = 1L;
/**
* Submit Button
*
*/
Button submit = new Button("Submit");
@Override
public void enter(ViewChangeEvent event) {
getUI().getNavigator().addViewChangeListener(new ViewChangeListener() {
/**
*
*/
private static final long serialVersionUID = 120255140723534027L;
@Override
public boolean beforeViewChange(ViewChangeEvent event) {
// TODO Auto-generated method stub
return false;
}
@Override
public void afterViewChange(ViewChangeEvent event) {
// TODO Auto-generated method stub
}
});
getUI().getConnectorTracker().unregisterConnector(this);
getUI();
UI.getCurrent().getPage();
Label scorel = new Label();
//submit.addClickShort
//int score=0;
// TODO Auto-generated method stub
HashMap<Integer,Component> questions = new HashMap<Integer,Component>();
HashMap<Integer,Object> interfacetransfer = new HashMap<Integer, Object>();
interfacetransfer.put(0, 0);
//Layouts/Tabs
//
/**
* Information Layout
*
*
*/
/**
* Bibliography Layout
*
*
*/
VerticalLayout bibliographyl= new VerticalLayout();
FreeformQuery fq = new FreeformQuery("SELECT * FROM vwBibliographies", ((JDBCConnectionPool)getSession().getAttribute("pool")));
Table bibliography = new Table();
try {
SQLContainer container = new SQLContainer(fq);
bibliography.setContainerDataSource(container);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Scanner scan= new Scanner(System.in);
//scan.findInLine("");
// Notification.show(new Scanner(System.in).nextLine());
bibliographyl.addComponent(bibliography);
/**
* Quiz Layout
*
*
*/
VerticalLayout popupquiz = new VerticalLayout();
Window quizwindows = new Window();
quizwindows.setContent(popupquiz);
popupquiz.addComponent(scorel);
/**
* Glossary Layout
*
*
*/
VerticalLayout glossary = new VerticalLayout();
String query="Select * FROM vwGlossary";
getSession();
FreeformQuery glossaryquery=new FreeformQuery(query, ((JDBCConnectionPool)VaadinSession.getCurrent().getAttribute("pool")));
Table glossarytable = new Table();
glossarytable.setSizeFull();
glossary.addComponent(glossarytable);
try {
glossarytable.setContainerDataSource(new SQLContainer(glossaryquery));
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//questions.put(1, new QuizQuestion(""))
questions.put(0,new VerticalLayout(new Label("What state in America is SETI based in?")));
((AbstractComponentContainer) questions.get(0)).addComponent(new OptionGroup(""));
((OptionGroup)((AbstractOrderedLayout) questions.get(0)).getComponent(1)).addItems("Colorado","California","Massachusets");
submit.addClickListener(event1 -> {
// TODO Auto-generated method stub
if(submit.getCaption().equals("Submit")&&popupquiz.getComponent(0).equals(questions.get(0))){
if(((OptionGroup)((VerticalLayout)questions.get(0)).getComponent(0)).getValue().equals("California")){
Notification.show("Correct",Type.ASSISTIVE_NOTIFICATION);
submit.setCaption("Next");
interfacetransfer.put(0, 1);
}else{
Notification.show("Incorrect",Type.ERROR_MESSAGE);
submit.setCaption("Next");
}}
});
questions.put(1,new VerticalLayout());
((AbstractComponentContainer) questions.get(1)).addComponent(new Label("Am I smart?"));
((AbstractComponentContainer) questions.get(1)).addComponent(new CheckBox());
submit.addClickListener(event1 -> {
// TODO Auto-generated method stub
if(submit.getCaption().equals("Submit")&&popupquiz.getComponent(0).equals(questions.get(1))){
if(((CheckBox)((AbstractOrderedLayout) questions.get(1)).getComponent(1)).getValue().equals(true)){
Notification.show("Correct");
submit.setCaption("Next");
interfacetransfer.put(0,((Integer)interfacetransfer.get(0))+1);
}else{
Notification.show("Incorrect");
submit.setCaption("Next");
}
}});
for(int i=0;questions.size()-1>i;i++){
int e=i;
submit.addClickListener(event1 -> {
// TODO Auto-generated method stub
if(submit.getCaption().equals("Next")&&popupquiz.getComponent(e).equals(questions.get(e))){
popupquiz.removeAllComponents();
if(e!=questions.size()-1){
popupquiz.addComponent(questions.get(e+1));
submit.setCaption("Submit");
popupquiz.addComponent(submit);
scorel.setCaption(Integer.toString((int) interfacetransfer.get(0)));
popupquiz.addComponent(scorel);
}
}
});
}
VerticalLayout mainlayout = new VerticalLayout(MainView.nav);
TabSheet tab = new TabSheet();
mainlayout.addComponent(tab);
AbstractLayout quizl = new VerticalLayout();
tab.addTab(new information("Page 1","Page 2"),"Information");
tab.addTab(quizl,"Quiz" );
setCompositionRoot(mainlayout);
tab.addTab(bibliographyl,"Bibliography");
tab.addTab(glossary,"Glossary");
Window quiz = new Window("Quiz");
quiz.center();
tab.addSelectedTabChangeListener(event1 -> {
// TODO Auto-generated method stub
if(event1.getTabSheet().equals(tab.getTab(quizl))){
quiz.isVisible();
}else{
quiz.setVisible(false);
}
});
quiz.setContent(popupquiz);
popupquiz.addComponent(questions.get(0));
popupquiz.addComponent(submit);
getUI().addWindow(quiz);
getSession();
//getting current date and time using Date class
mainlayout.addComponent(new Label((String) VaadinSession.getCurrent().getAttribute("sessionupdate")));
}
}
您的代码中存在无限循环。确保添加 break;
或更新 while 条件,使其不会永远循环。
while(true){
try {
TextFileProperty stri=new TextFileProperty(new File(baseadress+filenames[pageno.get(0)]+".txt"));
text.setPropertyDataSource(stri);
} catch (ReadOnlyException | ConversionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
ConnectorTracker
用于保持 UI 活动。可能他需要清理他的代码(在 Eclipse 菜单 Project->Clean 上),并在编译代码不正确的情况下重建。你也可以提醒他,所有 class 的名字都应该是驼峰式的(比如 ConnectorTracker
)。
我正在制作一个学校项目,但无法加载。
除了我打印到日志中的内容之外,绝对 NO 错误日志,但我确实得到了一些关于 Connector Trackers
以下是部分截图
![]
(http://pierlot.com.au:8888/repository/images/Screenshot.png)
![]
(http://pierlot.com.au:8888/repository/images/Screenshot2.png)
note the top bar is flashing
这是我的代码
class information extends CustomComponent{
/**
*
*/
private static final long serialVersionUID = 1L;
public information(String... filenames){
VerticalLayout information = new VerticalLayout();
Label text = new Label();
text.setContentMode(ContentMode.HTML);
HashMap<Integer,Integer> pageno = new HashMap<Integer,Integer>();
pageno.put(0,0);
Button nextb = new Button(FontAwesome.ARROW_CIRCLE_O_RIGHT);
Button previousb = new Button(FontAwesome.ARROW_CIRCLE_O_LEFT);
nextb.addClickListener(event -> {
if(pageno.get(0)==filenames.length){
}else{
pageno.put(0,pageno.get(0)+1);
}
});
previousb.addClickListener(event -> {
// TODO Auto-generated method stub
if(pageno.get(0)==0){
}else{
pageno.put(0,pageno.get(0)-1);
}
});
String f = File.separator;
String baseadress=new String("C:"+File.separator+"Users"+File.separator+"Countrywide Austral"+File.separator+"OneDrive"+File.separator+f+"ERPs"+f+"Term 4"+f);
setCompositionRoot(information);
information.addComponent(text);
information.addComponent(new HorizontalLayout(nextb,previousb));
while(true){
try {
TextFileProperty stri=new TextFileProperty(new File(baseadress+filenames[pageno.get(0)]+".txt"));
text.setPropertyDataSource(stri);
} catch (ReadOnlyException | ConversionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public class SetiView extends CustomComponent implements View {
private static final long serialVersionUID = 1L;
/**
* Submit Button
*
*/
Button submit = new Button("Submit");
@Override
public void enter(ViewChangeEvent event) {
getUI().getNavigator().addViewChangeListener(new ViewChangeListener() {
/**
*
*/
private static final long serialVersionUID = 120255140723534027L;
@Override
public boolean beforeViewChange(ViewChangeEvent event) {
// TODO Auto-generated method stub
return false;
}
@Override
public void afterViewChange(ViewChangeEvent event) {
// TODO Auto-generated method stub
}
});
getUI().getConnectorTracker().unregisterConnector(this);
getUI();
UI.getCurrent().getPage();
Label scorel = new Label();
//submit.addClickShort
//int score=0;
// TODO Auto-generated method stub
HashMap<Integer,Component> questions = new HashMap<Integer,Component>();
HashMap<Integer,Object> interfacetransfer = new HashMap<Integer, Object>();
interfacetransfer.put(0, 0);
//Layouts/Tabs
//
/**
* Information Layout
*
*
*/
/**
* Bibliography Layout
*
*
*/
VerticalLayout bibliographyl= new VerticalLayout();
FreeformQuery fq = new FreeformQuery("SELECT * FROM vwBibliographies", ((JDBCConnectionPool)getSession().getAttribute("pool")));
Table bibliography = new Table();
try {
SQLContainer container = new SQLContainer(fq);
bibliography.setContainerDataSource(container);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Scanner scan= new Scanner(System.in);
//scan.findInLine("");
// Notification.show(new Scanner(System.in).nextLine());
bibliographyl.addComponent(bibliography);
/**
* Quiz Layout
*
*
*/
VerticalLayout popupquiz = new VerticalLayout();
Window quizwindows = new Window();
quizwindows.setContent(popupquiz);
popupquiz.addComponent(scorel);
/**
* Glossary Layout
*
*
*/
VerticalLayout glossary = new VerticalLayout();
String query="Select * FROM vwGlossary";
getSession();
FreeformQuery glossaryquery=new FreeformQuery(query, ((JDBCConnectionPool)VaadinSession.getCurrent().getAttribute("pool")));
Table glossarytable = new Table();
glossarytable.setSizeFull();
glossary.addComponent(glossarytable);
try {
glossarytable.setContainerDataSource(new SQLContainer(glossaryquery));
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//questions.put(1, new QuizQuestion(""))
questions.put(0,new VerticalLayout(new Label("What state in America is SETI based in?")));
((AbstractComponentContainer) questions.get(0)).addComponent(new OptionGroup(""));
((OptionGroup)((AbstractOrderedLayout) questions.get(0)).getComponent(1)).addItems("Colorado","California","Massachusets");
submit.addClickListener(event1 -> {
// TODO Auto-generated method stub
if(submit.getCaption().equals("Submit")&&popupquiz.getComponent(0).equals(questions.get(0))){
if(((OptionGroup)((VerticalLayout)questions.get(0)).getComponent(0)).getValue().equals("California")){
Notification.show("Correct",Type.ASSISTIVE_NOTIFICATION);
submit.setCaption("Next");
interfacetransfer.put(0, 1);
}else{
Notification.show("Incorrect",Type.ERROR_MESSAGE);
submit.setCaption("Next");
}}
});
questions.put(1,new VerticalLayout());
((AbstractComponentContainer) questions.get(1)).addComponent(new Label("Am I smart?"));
((AbstractComponentContainer) questions.get(1)).addComponent(new CheckBox());
submit.addClickListener(event1 -> {
// TODO Auto-generated method stub
if(submit.getCaption().equals("Submit")&&popupquiz.getComponent(0).equals(questions.get(1))){
if(((CheckBox)((AbstractOrderedLayout) questions.get(1)).getComponent(1)).getValue().equals(true)){
Notification.show("Correct");
submit.setCaption("Next");
interfacetransfer.put(0,((Integer)interfacetransfer.get(0))+1);
}else{
Notification.show("Incorrect");
submit.setCaption("Next");
}
}});
for(int i=0;questions.size()-1>i;i++){
int e=i;
submit.addClickListener(event1 -> {
// TODO Auto-generated method stub
if(submit.getCaption().equals("Next")&&popupquiz.getComponent(e).equals(questions.get(e))){
popupquiz.removeAllComponents();
if(e!=questions.size()-1){
popupquiz.addComponent(questions.get(e+1));
submit.setCaption("Submit");
popupquiz.addComponent(submit);
scorel.setCaption(Integer.toString((int) interfacetransfer.get(0)));
popupquiz.addComponent(scorel);
}
}
});
}
VerticalLayout mainlayout = new VerticalLayout(MainView.nav);
TabSheet tab = new TabSheet();
mainlayout.addComponent(tab);
AbstractLayout quizl = new VerticalLayout();
tab.addTab(new information("Page 1","Page 2"),"Information");
tab.addTab(quizl,"Quiz" );
setCompositionRoot(mainlayout);
tab.addTab(bibliographyl,"Bibliography");
tab.addTab(glossary,"Glossary");
Window quiz = new Window("Quiz");
quiz.center();
tab.addSelectedTabChangeListener(event1 -> {
// TODO Auto-generated method stub
if(event1.getTabSheet().equals(tab.getTab(quizl))){
quiz.isVisible();
}else{
quiz.setVisible(false);
}
});
quiz.setContent(popupquiz);
popupquiz.addComponent(questions.get(0));
popupquiz.addComponent(submit);
getUI().addWindow(quiz);
getSession();
//getting current date and time using Date class
mainlayout.addComponent(new Label((String) VaadinSession.getCurrent().getAttribute("sessionupdate")));
}
}
您的代码中存在无限循环。确保添加 break;
或更新 while 条件,使其不会永远循环。
while(true){
try {
TextFileProperty stri=new TextFileProperty(new File(baseadress+filenames[pageno.get(0)]+".txt"));
text.setPropertyDataSource(stri);
} catch (ReadOnlyException | ConversionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
ConnectorTracker
用于保持 UI 活动。可能他需要清理他的代码(在 Eclipse 菜单 Project->Clean 上),并在编译代码不正确的情况下重建。你也可以提醒他,所有 class 的名字都应该是驼峰式的(比如 ConnectorTracker
)。