I've encountered this problem while trying to use cellData -> cellData.getValue() to add an attribute from an object, the attribute is a StringProperty and i have a method to return it, and i'm using it in the cellData -> cellData.getValue().methodtoreturnproperty, but it's still giving me java.lang.reflect.InvocationTargetException, does anyone know what i'm doing wrong?
Here's the code:
package projeto.resources;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import projeto.Filmes;
import projeto.MainApp;
import projeto.Sala;
public class FilmeOverviewController {
#FXML
private TableView<Filmes> filmeTable;
#FXML
private TableColumn<Filmes, String> nomeColumn;
#FXML
private TableColumn<Filmes, String> categoriaColumn;
#FXML
private TableColumn<Filmes, String> salaColumn;
#FXML
private Label nomeLabel;
#FXML
private Label salaLabel;
#FXML
private Label categoriaLabel;
#FXML
private Label diretorLabel;
#FXML
private Label duracaoLabel;
#FXML
private Label protagonistaLabel;
#FXML
private Label classificacaoLabel;
// Reference to the main application.
private MainApp mainApp;
public FilmeOverviewController() {
}
#FXML
private void initialize() {
//Inicia a tableview com tres colunas.
nomeColumn.setCellValueFactory(cellData -> cellData.getValue().nomeProperty());
categoriaColumn.setCellValueFactory(cellData -> cellData.getValue().categoriaProperty());
salaColumn.setCellValueFactory(cellData -> cellData.getValue().numeroProperty());
// limpando os detalhes
showFilmeDetails(null);
// adicionando funcao
filmeTable.getSelectionModel().selectedItemProperty()
.addListener((observable, oldValue, newValue) -> showFilmeDetails(newValue));
}
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
//adiciona uma observable list
filmeTable.setItems(mainApp.getfilmeDados());
}
private void showFilmeDetails(Filmes filme) {
if (filme != null) {
nomeLabel.setText(filme.getNome());
categoriaLabel.setText(filme.getCategoria());
duracaoLabel.setText(filme.getDuracao());
protagonistaLabel.setText(filme.getProtagonista());
classificacaoLabel.setText(filme.getClassificacao());
diretorLabel.setText(filme.getDiretor());
salaLabel.setText(filme.getSalaN());
} else {
nomeLabel.setText("");
categoriaLabel.setText("");
duracaoLabel.setText("");
protagonistaLabel.setText("");
classificacaoLabel.setText("");
diretorLabel.setText("");
salaLabel.setText("");
}
}
#FXML
private void handleDeletarFilme() {
int selectedIndex = filmeTable.getSelectionModel().getSelectedIndex();
if (selectedIndex >= 0) {
filmeTable.getItems().remove(selectedIndex);
} else {
Alert alerta = new Alert(AlertType.WARNING);
alerta.setTitle("Nenhum filme selecionado");
alerta.setHeaderText("Nenhuma Selecao");
alerta.setContentText("Por favor selecione um filme para deletar");
alerta.showAndWait();
}
}
#FXML
private void handleNovoFilme() {
Filmes tempFilme = new Filmes("Nome","Categoria");
boolean clicado = mainApp.showEditarFilmeDialog(tempFilme);
if (clicado) {
mainApp.getfilmeDados().add(tempFilme);
}
}
#FXML
private void handleEditarFilme() {
Filmes filmeSelecionado = filmeTable.getSelectionModel().getSelectedItem();
if(filmeSelecionado != null) {
boolean clicado = mainApp.showEditarFilmeDialog(filmeSelecionado);
if(clicado) {
showFilmeDetails(filmeSelecionado);
}
}else {
//se nada for selecionado
Alert alerta = new Alert(AlertType.WARNING);
alerta.initOwner(mainApp.getPrimaryStage());
alerta.setTitle("Nenhuma selecao");
alerta.setHeaderText("Nenhum filme selecionado");
alerta.setContentText("Por favor selecione algum filme.");
alerta.showAndWait();
}
}
}
There's a class called Sala, that's being imported into this controller, i could make it work with another class called Filmes, i don't know exactly why it's not working with the class Sala, here's the code in the class:
package projeto;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Sala {
private boolean e3d;
private int assentosMax;
private int assentosDisp;
private final StringProperty numeroProperty = new SimpleStringProperty();
public Sala(boolean e3d, int assentosMax, int assentosDisp, String numero) {
setNumero(numero);
e3d = this.e3d;
assentosMax = this.assentosMax;
assentosDisp = this.assentosDisp;
}
public boolean isE3d() {
return e3d;
}
public void setE3d(boolean e3d) {
this.e3d = e3d;
}
public int getAssentosMax() {
return assentosMax;
}
public void setAssentosMax(int assentosMax) {
this.assentosMax = assentosMax;
}
public int getAssentosDisp() {
return assentosDisp;
}
public void setAssentosDisp(int assentosDisp) {
this.assentosDisp = assentosDisp;
}
public StringProperty numeroProperty() {
return numeroProperty;
}
public final String getNumero() {
return numeroProperty.get();
}
public final void setNumero(String numero) {
numeroProperty().set(numero);
}
}
Edit: Here's the error:
jun 07, 2018 3:18:37 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX runtime of version 8.0.171
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.Error: Unresolved compilation problem:
The method numeroProperty() is undefined for the type Filmes
at projeto.resources.FilmeOverviewController.<init>(FilmeOverviewController.java:50)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at projeto.MainApp.showFilmeOverview(MainApp.java:59)
at projeto.MainApp.start(MainApp.java:50)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application projeto.MainApp
Thanks in advance!
This looks like you are expecting one type of object in the table but providing another.
You define your table like this:
#FXML
private TableColumn<Filmes, String> salaColumn;
Your cell value factory is trying to get the following:
salaColumn.setCellValueFactory(cellData -> cellData.getValue().numeroProperty());
The numeroProperty is on the Sala object, not the Filmes Object.
Try the following (Though I am not 100% sure, since your definition of Filmes is not in the question):
salaColumn.setCellValueFactory(cellData -> cellData.getValue().getSala().numeroProperty());
Also - if there is a chance that the Sala object could be null, you'll want to check for that before trying to access the numeroProperty().
Related
I am trying to get hold of XML editor for my RCP application. My simple aim is to show SCXML files with source and design. I tried few ways and nothing seems working.
Right now I am trying to run below approach
https://github.com/Pontesegger/codeandme/blob/master/Code%20%26%20Me%20Blog/form_editor_with_xml_source_view.zip
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.IFormPage;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
public class SampleEditor extends FormEditor {
private StructuredTextEditor fSourceEditor;
private int fSourceEditorIndex;
/** Keeps track of dirty code from source editor. */
private boolean fSourceDirty = false;
#Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
super.init(site, input);
// TODO: load your model here
}
#Override
protected void addPages() {
fSourceEditor = new StructuredTextEditor();
fSourceEditor.setEditorPart(this);
try {
// add form pages
addPage(new FirstForm(this, "firstID", "First Page"));
// add source page
fSourceEditorIndex = addPage(fSourceEditor, getEditorInput());
setPageText(fSourceEditorIndex, "Source");
} catch (final PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// add listener for changes of the document source
getDocument().addDocumentListener(new IDocumentListener() {
#Override
public void documentAboutToBeChanged(final DocumentEvent event) {
// nothing to do
}
#Override
public void documentChanged(final DocumentEvent event) {
fSourceDirty = true;
}
});
}
#Override
public void doSaveAs() {
// not allowed
}
#Override
public boolean isSaveAsAllowed() {
return false;
}
#Override
public void doSave(final IProgressMonitor monitor) {
if (getActivePage() != fSourceEditorIndex)
updateSourceFromModel();
fSourceEditor.doSave(monitor);
}
#Override
protected void pageChange(final int newPageIndex) {
// check for update from the source code
if ((getActivePage() == fSourceEditorIndex) && (fSourceDirty))
updateModelFromSource();
// check for updates to be propagated to the source code
if (newPageIndex == fSourceEditorIndex)
updateSourceFromModel();
// switch page
super.pageChange(newPageIndex);
// update page if needed
final IFormPage page = getActivePageInstance();
if (page != null) {
// TODO update form page with new model data
page.setFocus();
}
}
private void updateModelFromSource() {
// TODO update source code for source viewer using new model data
fSourceDirty = false;
}
private void updateSourceFromModel() {
// TODO update source page from model
// getDocument().set("new source code");
fSourceDirty = false;
}
private IDocument getDocument() {
final IDocumentProvider provider = fSourceEditor.getDocumentProvider();
return provider.getDocument(getEditorInput());
}
private IFile getFile() {
final IEditorInput input = getEditorInput();
if (input instanceof FileEditorInput)
return ((FileEditorInput) input).getFile();
return null;
}
private String getContent() {
return getDocument().get();
}
}
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
public class FirstForm extends FormPage {
/**
* Create the form page.
*
* #param id
* #param title
*/
public FirstForm(final String id, final String title) {
super(id, title);
}
/**
* Create the form page.
*
* #param editor
* #param id
* #param title
* #wbp.parser.constructor
* #wbp.eval.method.parameter id "Some id"
* #wbp.eval.method.parameter title "Some title"
*/
public FirstForm(final FormEditor editor, final String id, final String title) {
super(editor, id, title);
}
/**
* Create contents of the form.
*
* #param managedForm
*/
#Override
protected void createFormContent(final IManagedForm managedForm) {
final FormToolkit toolkit = managedForm.getToolkit();
final ScrolledForm form = managedForm.getForm();
form.setText("First Editor Page");
final Composite body = form.getBody();
toolkit.decorateFormHeading(form.getForm());
toolkit.paintBordersFor(body);
}
}
Plugin.xml
<editor
class="generic.layer.editor.v2.SampleEditor"
default="false"
id="generic.layer.editor.v2.editor1"
name="name">
<contentTypeBinding
contentTypeId="generic.layer.editor.v2.content-type1">
</contentTypeBinding>
</editor>
</extension>
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.xml"
file-extensions="scxml"
id="generic.layer.editor.v2.content-type1"
name="name"
priority="normal">
</content-type>
And call to the editor from my view
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IStorage storage = new StringStorage((String)o);
IStorageEditorInput input = new StringInput(storage);
try {
page.openEditor(input, "generic.layer.editor.v2.editor1");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
This is the error I am getting right now
!ENTRY org.eclipse.e4.ui.workbench 4 0 2019-09-27 15:56:32.129
!MESSAGE
!STACK 0
java.lang.NullPointerException
at org.eclipse.wst.sse.ui.StructuredTextEditor.createCombinedPreferenceStore(StructuredTextEditor.java:1521)
at org.eclipse.wst.sse.ui.StructuredTextEditor.initializeEditor(StructuredTextEditor.java:2768)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.<init>(AbstractDecoratedTextEditor.java:344)
at org.eclipse.ui.editors.text.TextEditor.<init>(TextEditor.java:59)
at org.eclipse.wst.sse.ui.StructuredTextEditor.<init>(StructuredTextEditor.java:1151)
at generic.layer.editor.v2.SampleEditor.addPages(SampleEditor.java:34)
at org.eclipse.ui.forms.editor.FormEditor.createPages(FormEditor.java:140)
at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:348)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:151)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:99)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:355)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:990)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:955)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:124)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:399)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:318)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:992)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:661)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1293)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.lambda$0(LazyStackRenderer.java:68)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:144)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4889)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:52)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:173)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:620)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:584)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:769)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:401)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1188)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3261)
at org.eclipse.ui.internal.WorkbenchPage.access$25(WorkbenchPage.java:3176)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3158)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3153)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3117)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3098)
at generic.layer.editor.v2.SCXMLView$1$1.run(SCXMLView.java:118)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:37)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:182)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4213)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3820)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at generic.layer.editor.v2.Application.start(Application.java:21)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
at org.eclipse.equinox.launcher.Main.main(Main.java:1472)
Sep 27, 2019 3:56:32 PM generic.layer.editor.v2.PropertyView$2$1 run
INFO: Receiving event for transformation propoerties:
I am trying to make a Search bar using JFXTextField in Javafx8. But when I add FilteredList and SortedList in my Code, The Application no longer run and Output shows the following Exception:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: file:/C:/Users/Zed%20and%20White/Documents/NetBeansProjects/Project_EMS/dist/run1317715357/Project_EMS.jar!/project_ems/FrontEnd.fxml:22
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at project_ems.Project_EMS.start(Project_EMS.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Caused by: java.lang.NullPointerException
at javafx.collections.transformation.TransformationList.<init>(TransformationList.java:65)
at javafx.collections.transformation.FilteredList.<init>(FilteredList.java:66)
at javafx.collections.transformation.FilteredList.<init>(FilteredList.java:87)
at project_ems.FrontEndController.<init>(FrontEndController.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 17 more
Exception running application project_ems.Project_EMS
I have followed this method Create Search TextField to Search in a Javafx table
Here's my Code:
ObservableList:
private ObservableList<DataHandler_ExamsListing> EListingData;
Block of Code that Uses the Above Observable List:
private void LoadEListingData(){
try {
DBE.resultSet = DBE.statement.executeQuery("SELECT * FROM Exam");
EListingData = FXCollections.observableArrayList();
while (DBE.resultSet.next()) {
EListingData.add(new DataHandler_ExamsListing(DBE.resultSet.getInt("ExamID"),DBE.resultSet.getString("ExamName"),DBE.resultSet.getString("ExamDate"),DBE.resultSet.getString("ExamComment")));
}
EListingTable.setItems(EListingData);
} catch (SQLException e) {
}
}
FilteredList and SortedList (Both are Global):
private final FilteredList<DataHandler_ExamsListing> FilteredData = new FilteredList<>(EListingData);
private final SortedList<DataHandler_ExamsListing> sortedData = new SortedList<>(FilteredData);
SearchBar FXML:
#FXML // fx:id="SearchExam_Elisting"
private JFXTextField SearchExam_Elisting; // Value injected by FXMLLoader
ActionEvent on SearchBar:
#FXML
private void SearchExamList(ActionEvent event) {
SearchExam_Elisting.textProperty().addListener((observable, oldValue, newValue) -> {
FilteredData.setPredicate(DataHandler_ExamsListing -> {
if (newValue == null || newValue.isEmpty()) {
return true;
}
String lowerCaseFilter = newValue.toLowerCase();
if (DataHandler_ExamsListing.getExamName().toLowerCase().contains(lowerCaseFilter)) {
return true;
}
return false;
});
});
sortedData.comparatorProperty().bind(EListingTable.comparatorProperty());
EListingTable.setItems(sortedData);
System.out.println("DOne");
}
if I comment out FilteredList and SortedList and the ActionEvent, The App runs smoothly.
Please help me resolve this Issue. Thanks!
I don't know what you mean by "Both are global". The closest thing to a global scope would be static fields and none of the fields is declared as static.
But as for the issue in the question:
You're initializing the FilteredData field when declaring it which results in the assignment being executed even before a constructor would be executed. This means there is no way the LoadEListingData is executed before the assignment
FilteredData = new FilteredList<>(EListingData);
for this reason EListingData is still null at that time. This is not allowed though.
You need change the time this field is initialized, e.g. to after loading the data using the LoadEListingData.
Alternatively you could initialize the field with a empty ObservableList and fill this list later when the LoadEListingData method is called:
private final ObservableList<DataHandler_ExamsListing> EListingData = FXCollections.observableArrayList();
private final FilteredList<DataHandler_ExamsListing> FilteredData = new FilteredList<>(EListingData);
private final SortedList<DataHandler_ExamsListing> sortedData = new SortedList<>(FilteredData);
#FXML
private void initialize() {
EListingTable.setItems(sortedData);
}
private void LoadEListingData(){
List<DataHandler_ExamsListing> data = new ArrayList<>();
try {
// prepare data for insert using single update
DBE.resultSet = DBE.statement.executeQuery("SELECT * FROM Exam"); // directly accessing static fields of a different class is a terrible idea since it violates the information hiding principle
while (DBE.resultSet.next()) {
data.add(new DataHandler_ExamsListing(DBE.resultSet.getInt("ExamID"),DBE.resultSet.getString("ExamName"),DBE.resultSet.getString("ExamDate"),DBE.resultSet.getString("ExamComment")));
}
} catch (SQLException e) {
e.printStackTrace(); // Never just ignore an exception unless it's expected
return;
}
// update data
EListingData.setAll(data);
}
I am using ASM 5.0.3 with Websphere 8.5.x and IDM JDK 1.7 to profiling method execution time using org.objectweb.asm.commons.AdviceAdapter
Oracle JDBC driver ojdbc7.jar is used for creating JDBC. My Application is working fine without adding -javaagent arguments.
When bytecode is modified (via -javaagent), Websphere starts fine but when accessing application it throws java.lang.NoClassDefFoundError: oracle/security/pki/OraclePKIProvider .
I found a link which explains about the issue in detail & shows NoClassDefFoundError happens for certain JVM/driver version combinations
https://plumbr.eu/blog/java/troubleshooting-verifiers-the-rabbit-hole-goes-deep
An exception occurred while invoking method setDataSourceProperties on com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl used by resource jdbc/appDatasource : java.lang.NoClassDefFoundError: oracle/security/pki/OraclePKIProvider
at oracle.jdbc.pool.OracleDataSource.<clinit>(OracleDataSource.java:103)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:383)
at com.ibm.ws.rsadapter.DSConfigHelper.createDataSource(DSConfigHelper.java:747)
at com.ibm.ws.rsadapter.spi.WSRdbDataSource.createNewDataSource(WSRdbDataSource.java:3029)
at com.ibm.ws.rsadapter.spi.WSRdbDataSource.<init>(WSRdbDataSource.java:1358)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.setDataSourceProperties(WSManagedConnectionFactoryImpl.java:2653)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
......
Suggested solution from the link is
Make sure that if the label visit was originally followed by a frame visit, we would insert our instructions after the frame visit, not between the frame and the label.
Can some one explain "How to achieve this using ASM bytecode?"
Update1 - Attached AdviceAdapter Code
package com.abc.agent.adapter;
import com.abc.jm.TMConstants;
import com.abc.jm.TMLog;
import com.abc.org.objectweb.asm.Label;
import com.abc.org.objectweb.asm.MethodVisitor;
import com.abc.org.objectweb.asm.Opcodes;
import com.abc.org.objectweb.asm.Type;
import com.abc.org.objectweb.asm.commons.AdviceAdapter;
public class DriverMethodAdviceAdapter extends AdviceAdapter {
private String methodName;
private String className;
private String description;
private boolean isConnectMethod;
private static final String INTERFACE_DRIVER_CONNECT_METHOD_DESC = "(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;";
private int okFlag = newLocal(Type.BOOLEAN_TYPE);
Label startFinally = new Label();
public DriverMethodAdviceAdapter(int access , MethodVisitor mv , String methodName, String description, String className, int classFileVersion){
super(Opcodes.ASM5, mv, access, methodName, description);
this.className = className;
this.methodName = methodName;
this.description = description;
this.isConnectMethod = false;
if(methodName.equals("connect") && description.equals(INTERFACE_DRIVER_CONNECT_METHOD_DESC)){
isConnectMethod = true;
}
}
public void visitCode() {
super.visitCode();
mv.visitLabel(startFinally);
}
protected void onMethodEnter(){
if(isConnectMethod){
mv.visitInsn(Opcodes.ICONST_0);
mv.visitVarInsn(ISTORE, okFlag);
mv.visitLdcInsn(className);
mv.visitLdcInsn(methodName);
mv.visitLdcInsn(description);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "com/abc/agent/trace/Tracer", "jdbcConnectionMethodBegin", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", false);
mv.visitVarInsn(ISTORE, okFlag);
}
}
protected void onMethodExit(int opcode){
if(opcode!=ATHROW) {
onFinally(opcode);
}
}
public void visitMaxs(int maxStack, int maxLocals){
Label endFinally = new Label();
mv.visitTryCatchBlock(startFinally, endFinally, endFinally, null);
mv.visitLabel(endFinally);
onFinally(ATHROW);
mv.visitInsn(ATHROW);
mv.visitMaxs(maxStack+4, maxLocals);
}
private void onFinally(int opcode){
if(isConnectMethod){
mv.visitInsn(Opcodes.DUP); // This is return object
mv.visitLdcInsn(className);
mv.visitLdcInsn(methodName);
mv.visitLdcInsn(description);
mv.visitVarInsn(ILOAD, okFlag);
mv.visitLdcInsn(opcode);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "com/abc/agent/trace/Tracer", "jdbcConnectionMethodEnd", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZI)V", false);
}
}
}
I am using the flags ClassWriter.COMPUTE_FRAMES for ClassWriter and ClassReader.EXPAND_FRAMES | ClassReader.SKIP_FRAMES for ClasseReader.accept().
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am quite new to Java and JUnit testing and am very confused with an error I am getting. The error, Null Pointer exception as the code below I am guessing is because something is equal to null but i am unsure why.
java.lang.NullPointerException
at com.nsa.y1.trafficlights.FourWayJunctionTest.PhaseOneInitiation(FourWayJunctionTest.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:377)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745) com.nsa.y1.trafficlights.FourWayJunctionTest > PhaseOneInitiation FAILED
java.lang.NullPointerException at FourWayJunctionTest.java:47
Here is the test file:
package com.nsa.y1.trafficlights;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created by c167 on 12/03/2017.
*/
public class FourWayJunctionTest {
private Light greenLight, amberLight, redLight, greenRightArrow, greenLeftArrow;
private FourLightTrafficLight turnRightTrafficLight;
boolean lightStateRed;
boolean lightStateAmber;
boolean lightStateGreen;
private TrafficLight northLeftStraight;
private FourLightTrafficLight northLeftArrow;
private FourLightTrafficLight northRightArrow;
private TrafficLight eastLeftStraight;
private TrafficLight westStraightRight;
private FourWayJunction junction = new FourWayJunction();
#Before
public void createLights() throws Exception {
greenLight = (new Light(Shape.CIRCLE, Colour.GREEN));
amberLight = (new Light(Shape.CIRCLE, Colour.AMBER));
redLight = (new Light(Shape.CIRCLE, Colour.RED));
northRightArrow = new FourLightTrafficLight();
northLeftArrow = new FourLightTrafficLight();
northLeftStraight = new TrafficLight();
eastLeftStraight = new TrafficLight();
westStraightRight = new TrafficLight();
}
#Test
public void PhaseOneInitiation() throws Exception {
createLights();
//Greenleftarrow should be on, northleft on, and eat left on. All others off.
junction.initiatePhaseOne();
assertEquals(greenLeftArrow.isOn(), true);
}
}
This is the code containing the methods:
package com.nsa.y1.trafficlights;
/**
* Created by on 13/03/2017.
*/
public class FourWayJunction extends FourLightTrafficLight{
// Evans junction recreation in cardiff
private Light greenLight, amberLight, redLight, greenRightArrow, greenLeftArrow;
private TrafficLight oppositeTrafficLight;
private FourLightTrafficLight turnRightTrafficLight;
boolean lightStateRed;
boolean lightStateAmber;
boolean lightStateGreen;
private TrafficLight northLeftStraight;
private FourLightTrafficLight northLeftArrow;
private FourLightTrafficLight northRightArrow;
private TrafficLight eastLeftStraight;
private TrafficLight westStraightRight;
public FourWayJunction() {
greenLight = (new Light(Shape.CIRCLE, Colour.GREEN));
amberLight = (new Light(Shape.CIRCLE, Colour.AMBER));
redLight = (new Light(Shape.CIRCLE, Colour.RED));
northRightArrow = new FourLightTrafficLight();
northLeftArrow = new FourLightTrafficLight();
northLeftStraight = new TrafficLight();
eastLeftStraight = new TrafficLight();
westStraightRight = new TrafficLight();
}
public void initiatePhaseOne() {
// Left arrow for buses and taxis on, north green light for left on but no right arrow.
// Also green light on for the East Traffic light.
// All others off.
westStraightRight.getRedLight().turnOn();
northRightArrow.getGreenLight().turnOff();
if (westStraightRight.getRedLight().isOn() && !northRightArrow.getGreenLight().isOn()){
northLeftArrow.getGreenLight().turnOn();
northLeftStraight.setTrafficLightOn(northLeftStraight);
eastLeftStraight.setTrafficLightOn(eastLeftStraight);
}
else {
System.out.println("Problems, traffic wil collide");
westStraightRight.setTrafficLightOff(westStraightRight);
northRightArrow.getGreenLight().turnOff();
}
}
public void initiatePhaseTwo() {
// North left straight, left arrow, and right arrow are on.
// West straight right light off.
// East Left Straight light is off.
if (!eastLeftStraight.getRedLight().isOn()) {
eastLeftStraight.setTrafficLightOff(eastLeftStraight);
northRightArrow.getGreenLight().turnOn();
}
else {
northRightArrow.getGreenLight().turnOn();
}
}
public void initiatePhaseThree() {
// All lights are off except for the EastStraightRight light.
if (northRightArrow.getGreenLight().isOn() && !northLeftStraight.getRedLight().isOn() &&
northLeftArrow.getGreenLight().isOn()) {
northRightArrow.getGreenLight().turnOff();
northLeftArrow.getGreenLight().turnOff();
northLeftStraight.setTrafficLightOff(northLeftStraight);
}
else {
eastLeftStraight.setTrafficLightOn(eastLeftStraight);
}
}
public FourLightTrafficLight getTrafficLight(FourLightTrafficLight light) {
return light;
}
}
public void setTrafficLightOn(TrafficLight trafficLight) {
trafficLight.getRedLight().turnOff();
LightPause();
trafficLight.getAmberLight().turnOn();
LightPause();
trafficLight.getGreenLight().turnOn();
}
public void setTrafficLightOff(TrafficLight trafficLight) {
trafficLight.getGreenLight().turnOff();
LightPause();
trafficLight.getGreenLight().turnOff();
trafficLight.getAmberLight().turnOn();
LightPause();
trafficLight.getRedLight().turnOn();
}
Thanks for your help :)
greenLeftArrow is not initialized to a value (it's automatically initialized to null) so calling greenLeftArrow.isOn() in the PhaseOneInitialization method will throw a NullPointerException.
You should initialize greenLeftArrow object first like you did for example greenLight. You cannot call methods on not initialized objects.
You can also use assertTrue or assertFalse to simplify your code.
I am using vaadin7 with grails i have created model and service and trying to access it when click on login button to check login details.
I search a lot but no relevant result, i am new to grails framework.
i am getting below error when trying to access service class:-
java.lang.NullPointerException
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at org.codehaus.groovy.grails.orm.support.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:85)
at com.xfuel.web.services.PeopleService.checkLogin(PeopleService.groovy)
at com.xfuel.web.services.PeopleService$checkLogin.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at test.Test$2.buttonClick(Test.groovy:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:984)
at com.vaadin.ui.Button.fireClick(Button.java:393)
at com.vaadin.ui.Button$1.click(Button.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
My Vaadincode is below :-
class Test extends UI {
public Test() {
// TODO Auto-generated constructor stub
}
#Override
protected void init(VaadinRequest request) {
HorizontalLayout fields = new HorizontalLayout();
fields.setSpacing(true);
fields.setMargin(true);
fields.addStyleName("fields");
final TextField username = new TextField("Username");
username.focus();
fields.addComponent(username);
final PasswordField password = new PasswordField("Password");
fields.addComponent(password);
final Button signin = new Button("Sign In");
signin.addStyleName("default");
fields.addComponent(signin);
fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);
final ShortcutListener enter = new ShortcutListener("Sign In",
KeyCode.ENTER, null) {
#Override
public void handleAction(Object sender, Object target) {
signin.click();
}
};
signin.addClickListener(new ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
if (username.getValue() != null
&& username.getValue().equals("")
&& password.getValue() != null
&& password.getValue().equals("")) {
signin.removeShortcutListener(enter);
PeopleService p1 = new PeopleService();
p1.checkLogin("", "");
// iPeopleService.checkLogin(username.getValue(), password.getValue());
buildMainView();
} else {
}
}
});
signin.addShortcutListener(enter);
setContent(fields);
}
}
And domain class :-
class People {
String name;
String apppassword;
static constraints = {
}
}
and Grails services code :-
#Transactional
class PeopleService {
def serviceMethod() {
}
public People checkLogin(String username, String password) {
def query = People.where{
peopleID == username &&
apppassword == password &&
visible == true
}
return people = query.find()
}
i below is the datasource :-
development {
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost/sample"
username = "root"
password = "root"
loggingSql = true
}
}
i did not understand the reason of this error. Can someone please help me?
Thanks