Migrate from Javafx2.2 to Javafx8 - fxml

I am trying to migrate Javafx2.2 application to Javafx8. I am getting following issue while using nested FXML:
javafx.fxml.LoadException: Root hasn't been set.
Use method setRoot() before load.
FXML file:
<fx:root type="javafx.scene.layout.VBox"
xmlns:fx="http://javafx.com/fxml"
xmlns="http://javafx.com/javafx/8"
fx:controller="com.ui.TestController">
<TextField fx:id="textField"/>
<Button text="Click Me"/>
</fx:root>
Code:
FXMLLoader loader = new FXMLLoader();
loader.setResources(bundle);
InputStream in = Main.class.getClassLoader().getResourceAsStream(fxml);
loader.setBuilderFactory(new JavaFXBuilderFactory());
loader.setLocation(Main.class.getResource(fxml));
Node page = null;
try {
page = (Node) loader.load(in);
} catch (IOException e) {
logger.error("{}", e);
} finally {
try {
in.close();
} catch (IOException e) {
logger.error("{}", e);
}
}
I need page node to set in another BorderPane.center. It works with Javafx2.2. What I am missing here? Any help would be appreciated.

Using <VBox></VBox> instead of <fx:root type="javafx.scene.layout.VBox"></fx:root> has fixed this issue, atleast for Javafx build b121.

Related

Cannot catch NoSuchElementException with Selenide

I’m trying to catch NoSuchElementException. This is my code:
public void checkActiveApps() {
try {
$(BUTTON).click();
} catch (org.openqa.selenium.NoSuchElementException e) {
System.out.println(e);
}
}
But the exception is still thrown. How to catch it?
This is the log:
Element not found {button[role='checkbox']}
Expected: visible
Screenshot: file:/Users/user/source/project/build/reports/tests/1537866631954.0.png
Page source: file:/Users/user/source/project/build/reports/tests/1537866631954.0.html
Timeout: 4 s.
Caused by: NoSuchElementException: Unable to locate element: button[role='checkbox']
at com.codeborne.selenide.impl.WebElementSource.createElementNotFoundError(WebElementSource.java:31)
at com.codeborne.selenide.impl.ElementFinder.createElementNotFoundError(ElementFinder.java:82)
at com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:59)
at com.codeborne.selenide.impl.WebElementSource.findAndAssertElementIsVisible(WebElementSource.java:72)
at com.codeborne.selenide.commands.Click.execute(Click.java:16)
at com.codeborne.selenide.commands.Click.execute(Click.java:12)
at com.codeborne.selenide.commands.Commands.execute(Commands.java:144)
at com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:90)
at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65)
I use selenide version 4.12.3
Selenide does not throw Selenium exceptions as it uses it's own.
You can try using:
public void checkActiveApps() {
try {
$(BUTTON).click();
} catch (com.codeborne.selenide.ex.ElementNotFound e) {
System.out.println(e);
}
}
Why do you want to catch it anyway?

system.threading .threadAbortException error

I am taking over an existing website and I am trying to get the application running on my machine, however I can't launch the application because I get the following error.
System.Threading.ThreadAbortException occurred
HResult=0x80131530
Message=Thread was being aborted.
Source=mscorlib
StackTrace:
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
This is my code
protected void Application_BeginRequest(object sender, EventArgs e) {
if (DemoWeb.Helpers.Application.ApplicationManager.StartUpError != "")
{
Response.Write("<div class=\"demoweb-securityerror\">" + demoweb.Helpers.Application.ApplicationManager.StartUpError + "</div>");
Response.End();
}
How can I get it to bypass the response.end?
I got it to work.
I just added a try and catch method and moved the Response.End
try {
// code
}
catch(exception ex)
{
Response.End();
}

OnElementPropertyChanged called infinely in xamarin forms

I have a custom Time picker renderer in my xamarin forms application
In my renderer i have
protected override void OnElementPropertyChanged(object sender,
PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
try
{
if (e.PropertyName == iOSCustomTimePicker.TimeProperty.PropertyName)
{
var temp = sender as iOSCustomTimePicker;
picker.Hour = temp.Time.Hours;
picker.Minute = temp.Time.Minutes;
//TimeSpan value = new TimeSpan(8, 0, 0);
//this.Element.SetValue(iOSCustomTimePicker.TimeProperty, value);
}
}
catch (Exception e1)
{
}
}
And i use it in xaml
<control:iOSCustomTimePicker x:Name="cli_staffrequest_addShiftTime_timePicker1" Grid.Column="2" Grid.Row="1" Time="{Binding ShiftEndTimeSelected}"
HorizontalOptions="Fill" VerticalOptions="Fill" StyleId="uit_staffHiring_addShifts__timePicker1"/>
So when the ShiftEndTimeSelected in ViewModel changes i get a hit in OnElementPropertyChanged and i change the time
Now my issue is sometimes i get infinite hits in OnElementPropertyChanged
and thus calling the Garbage Collector infinitely. How to figure out whats wrong. I am completely new to xamarin Forms
Sorry for the poor english
I think those lines are raising the event again:
base.OnElementPropertyChanged(sender, e);
and
picker.Hour = temp.Time.Hours;
picker.Minute = temp.Time.Minutes;
Maybe this will not happens if you make this way on your event handler (you need to test):
try
{
if (e.PropertyName == iOSCustomTimePicker.TimeProperty.PropertyName)
{
var temp = sender as iOSCustomTimePicker;
picker.Hour = temp.Time.Hours;
picker.Minute = temp.Time.Minutes;
}
else
base.OnElementPropertyChanged(sender, e);
}
catch (Exception e1)
{
}

How to know that camera is currently being used by another application with UWP?

I am trying to show error message "Cannot setup camera; currently being using" when there is already a process running the camera. I have the code that starts the preview using the MediaCapture and it works fine when running without another application using camera. I do get the exception
0x40080201: WinRT originate error (parameters: 0xC00D3704, 0x00000049, 0x10EFF1CC)
in my logs but my try catch block doesn't catch the error.
create_task(_mediaCapture->StartPreviewToCustomSinkAsync(encoding_profile, media_sink)).then([this, &hr](task<void>& info) {
try {
info.get();
} catch (Exception^ e) {
hr = e->HResult;
}
}).wait();
StartPreviewAsync method will throw a FileLoadException if another app has exclusive control of the capture device. We can catch this error to alert the user that the camera is currently being used by another application. A simple sample can be found at Use MediaCapture to start the preview stream.
However, this is a C# sample and FileLoadException is what used in .Net. For C++/CX, we can check the HRESULT value which should be 0x80070020. Following is the simple sample in C++/CX version.
MainPage.xaml
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<CaptureElement Name="PreviewControl" Stretch="Uniform"/>
<Button Click="Button_Click">Click</Button>
</Grid>
MainPage.xaml.h
public ref class MainPage sealed
{
public:
MainPage();
private:
// Prevent the screen from sleeping while the camera is running
Windows::System::Display::DisplayRequest^ _displayRequest;
// MediaCapture
Platform::Agile<Windows::Media::Capture::MediaCapture^> _mediaCapture;
void Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
MainPage.xaml.cpp
MainPage::MainPage()
: _mediaCapture(nullptr)
, _displayRequest(ref new Windows::System::Display::DisplayRequest())
{
InitializeComponent();
}
void MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_mediaCapture = ref new Windows::Media::Capture::MediaCapture();
create_task(_mediaCapture->InitializeAsync())
.then([this](task<void> previousTask) {
try
{
previousTask.get();
_displayRequest->RequestActive();
Windows::Graphics::Display::DisplayInformation::AutoRotationPreferences = Windows::Graphics::Display::DisplayOrientations::Landscape;
PreviewControl->Source = _mediaCapture.Get();
create_task(_mediaCapture->StartPreviewAsync())
.then([this](task<void>& previousTask)
{
try
{
previousTask.get();
}
catch (Exception^ exception)
{
if (exception->HResult == 0x80070020)
{
auto messageDialog = ref new Windows::UI::Popups::MessageDialog("Cannot setup camera; currently being using.");
create_task(messageDialog->ShowAsync());
}
}
});
}
catch (AccessDeniedException^)
{
auto messageDialog = ref new Windows::UI::Popups::MessageDialog("The app was denied access to the camera.");
create_task(messageDialog->ShowAsync());
}
});
}
StartPreviewToCustomSinkAsync method is similar to StartPreviewAsync method and can also throw a FileLoadException. You should be able to handle it using the same way. For more info, please also see Handle changes in exclusive control.

Java 8 Path Stream and FileSystemException (Too many open files)

geniuses!
I'm practicing Java 8.
So if I do something like this:
Files.walk(Paths.get(corpusPathStr))
.filter(path -> path.toFile().isFile())
.forEach(path -> {
try {
Files.lines(path)
.forEach(...);
} catch (IOException e) {
e.printStackTrace();
}
});
I got FileSystemException error.
If I open a file under forEach, may too many files be opened?
Or are there other reasons causing FileSystemException (Too many open files)?
Thanks for your help in advance!
Use
try(Stream<Path> stream = Files.walk(Paths.get(corpusPathStr))) {
stream.filter(path -> Files.isRegularFile(path) && Files.isReadable(path))
.flatMap(path -> {
try { return Files.lines(path); }
catch (IOException e) { throw new UncheckedIOException(e); }
})
.forEach(...);
}
catch(UncheckedIOException ex) {
throw ex.getCause();
}
The streams returned by Files.walk and Files.lines must be properly closed to release the resources, which you do by either, a try(…) construct or returning them in the mapping function of a flatMap operation.
Don’t use nested forEachs.
The UncheckedIOException might not only be thrown by our mapping function, but also the stream implementations. Translating it back to an IOException allows to treat them all equally.
Files::line opens and reads the file in a lazy manner, i.e. Stream<String>. Since you're not closing any of your opened Streams you're getting such an error.
So when you're done reading a file you should close its handle. Since the returned Stream is AutoCloseable you can and should use a try-with-resource block.
try (Stream<Path> walk = Files.walk(Paths.get(""))) {
walk.filter(Files::isRegularFile).forEach(path -> {
try (Stream<String> lines = Files.lines(path)) {
lines.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}

Resources