jxbrowser on macosx using SWT deadlock - swt

I have finished evaluating jxbrowser integration with Eclipse for Windows and Linux. My last roadblock is Mac. I get a dead lock while instantiating the browser. I am new to cocoa programming, so any pointer will be greatly appreciated.
I took the example project and modify it to work with SWT.
import java.awt.BorderLayout;
import java.awt.Frame;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
public class JxBrowserApp {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
Composite composite = new Composite(shell, SWT.EMBEDDED | SWT.NO_BACKGROUND);
Frame frame = SWT_AWT.new_Frame(composite);
Browser browser = new Browser(); // deadlock here
BrowserView browserView = new BrowserView(browser);
frame.add(browserView, BorderLayout.CENTER);
frame.setLocationRelativeTo(null);
frame.setFocusable(true);
browser.loadURL("http://www.google.com");
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Here is the callstack
JxBrowserApp at localhost:57970
Thread [main] (Suspended)
owns: IPC (id=72)
Unsafe.park(boolean, long) line: not available [native method]
LockSupport.parkNanos(Object, long) line: 215
CountDownLatch$Sync(AbstractQueuedSynchronizer).doAcquireSharedNanos(int, long) line: 1037
CountDownLatch$Sync(AbstractQueuedSynchronizer).tryAcquireSharedNanos(int, long) line: 1328
CountDownLatch.await(long, TimeUnit) line: 277
LatchUtil.await(CountDownLatch, RuntimeException, int) line: 25
LatchUtil.await(CountDownLatch, RuntimeException) line: 20
IPC.a(boolean) line: 159
IPC.start() line: 128
Browser.<init>(BrowserType, BrowserContext, Channel) line: 195
Browser.<init>(BrowserType, BrowserContext) line: 172
Browser.<init>(BrowserContext) line: 139
Browser.<init>() line: 125
JxBrowserApp.main(String[]) line: 27
Thread [AWT-EventQueue-0] (Suspended)
CPlatformView.nativeCreateView(int, int, int, int, long) line: not available [native method]
CPlatformView.initialize(LWWindowPeer, CPlatformResponder) line: 61
CViewPlatformEmbeddedFrame.initialize(Window, LWWindowPeer, PlatformWindow) line: 55
LWWindowPeer.<init>(Window, PlatformComponent, PlatformWindow, LWWindowPeer$PeerType) line: 156
LWCToolkit(LWToolkit).createDelegatedPeer(Window, PlatformComponent, PlatformWindow, LWWindowPeer$PeerType) line: 210
LWCToolkit.createEmbeddedFrame(CViewEmbeddedFrame) line: 204
CViewEmbeddedFrame.addNotify() line: 55
SWT_AWT$1.run() line: not available
InvocationEvent.dispatch() line: 311
EventQueue.dispatchEventImpl(AWTEvent, Object) line: 756
EventQueue.access$500(EventQueue, AWTEvent, Object) line: 97
EventQueue$3.run() line: 709
EventQueue$3.run() line: 703
AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: 76
EventQueue.dispatchEvent(AWTEvent) line: 726
EventDispatchThread.pumpOneEventForFilters(int) line: 201
EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 116
EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 105
EventDispatchThread.pumpEvents(int, Conditional) line: 101
EventDispatchThread.pumpEvents(Conditional) line: 93
EventDispatchThread.run() line: 82
Daemon Thread [Timer-0] (Suspended)
waiting for: TaskQueue (id=87)
Object.wait(long) line: not available [native method]
TimerThread.mainLoop() line: 552
TimerThread.run() line: 505
Daemon Thread [IPC Server Thread] (Suspended)
PlainSocketImpl.socketAccept(SocketImpl) line: not available [native method]
SocksSocketImpl(AbstractPlainSocketImpl).accept(SocketImpl) line: 409
ServerSocket.implAccept(Socket) line: 545
ServerSocket.accept() line: 513
Server.start(int) line: 81
e.run() line: 1237
Thread.run() line: 745
Daemon Thread [IPC Process Thread] (Suspended)
CGraphicsDevice.nativeGetScreenInsets(int) line: not available [native method]
CGraphicsDevice.getScreenInsets() line: 128
LWCToolkit.getScreenInsets(GraphicsConfiguration) line: 407
SwingUtilities$SharedOwnerFrame(Window).init(GraphicsConfiguration) line: 506
SwingUtilities$SharedOwnerFrame(Window).<init>() line: 537
SwingUtilities$SharedOwnerFrame(Frame).<init>(String) line: 420
SwingUtilities$SharedOwnerFrame(Frame).<init>() line: 385
SwingUtilities$SharedOwnerFrame.<init>() line: 1758
SwingUtilities.getSharedOwnerFrame() line: 1833
JWindow.<init>(Frame) line: 187
JWindow.<init>() line: 139
InternalChromiumProcess.doStart(List<String>) line: 1078
InternalChromiumProcess(ChromiumProcess).start(int) line: 123
d.run() line: 184
Thread.run() line: 745

Related

What would cause a try/catch block to fail exception handling despite execution landing in catch block?

The execution from below code
line 108 try
line 109 {
line 110 columnValCSV = columns_List(fileNumber)(columnNumber)
line 111 }
line 112 catch
line 113 {
line 114 case e: Exception => println(columnValCSV +"OtherLogText")
line 115 }
lands in the catch block as shown in the stack trace.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
10 at Main$.$anonfun$parseSecondDataSource$2(Main.scala:114) at
Main$.$anonfun$parseSecondDataSource$2$adapted(Main.scala:85) at
scala.collection.Iterator.foreach(Iterator.scala:929) at
scala.collection.Iterator.foreach$(Iterator.scala:929) at
scala.collection.AbstractIterator.foreach(Iterator.scala:1417) at
Main$.$anonfun$parseSecondDataSource$1(Main.scala:85) at
Main$.$anonfun$parseSecondDataSource$1$adapted(Main.scala:68) at
scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:59)
at
scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:52)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at Main$.parseSecondDataSource(Main.scala:68) at
Main$.main(Main.scala:147) at Main.main(Main.scala)
However, instead of avoiding throwing an exception as my code is supposed to do, it crashes.
An exception handler can also throw.
scala> try throw null catch { case _: NullPointerException => ??? }
scala.NotImplementedError: an implementation is missing
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:347)
at .liftedTree1$1(<console>:1)
... 28 elided
The actual print statement in the catch block references the same variable I put in the try block. That was the problem

mongodb v3 driver vc++ community addition linker errors

I'm getting the following linker errors in types.hpp while compiling in vc++ 2017. How shall i solve them ?
Below is the code I'm tyring to compile in vc++.
Additional directories included.
E:\boost_1_61_0-bin-msvc-all-32-64\boost_1_61_0;E:\nosql_db\mongo-cxx-driver-r3.1.3\include\mongocxx\v_noabi;E:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi;E:\nosql_db\mon-c-driver\include\libbson-1.0;E:\nosql_db\mon-c-driver\include\libmongoc-1.0;%(AdditionalDependencies)
#include "stdafx.h"
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
using bsoncxx::builder::stream::document;
int main()
{
mongocxx::instance inst{};
mongocxx::client conn{ mongocxx::uri{} };
bsoncxx::builder::stream::document document{};
auto collection = conn["testdb"]["testcollection"];
document << "hello" << "world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
return 0;
}
everity Code Description Project File Line Suppression State
Error (active) E0145 member "bsoncxx::v_noabi::types::b_double::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 86
Error (active) E0145 member "bsoncxx::v_noabi::types::b_utf8::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 111
Error (active) E0145 member "bsoncxx::v_noabi::types::b_document::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 149
Error (active) E0145 member "bsoncxx::v_noabi::types::b_array::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 181
Error (active) E0145 member "bsoncxx::v_noabi::types::b_binary::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 206
Error (active) E0145 member "bsoncxx::v_noabi::types::b_undefined::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 230
Error (active) E0145 member "bsoncxx::v_noabi::types::b_oid::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 246
Error (active) E0145 member "bsoncxx::v_noabi::types::b_bool::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 264
Error (active) E0145 member "bsoncxx::v_noabi::types::b_date::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 289
Error (active) E0145 member "bsoncxx::v_noabi::types::b_null::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 350
Error (active) E0145 member "bsoncxx::v_noabi::types::b_regex::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 366
Error (active) E0145 member "bsoncxx::v_noabi::types::b_dbpointer::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 402
Error (active) E0145 member "bsoncxx::v_noabi::types::b_code::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 421
Error (active) E0145 member "bsoncxx::v_noabi::types::b_symbol::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 462
Error (active) E0145 member "bsoncxx::v_noabi::types::b_codewscope::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 500
Error (active) E0145 member "bsoncxx::v_noabi::types::b_int32::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 533
Error (active) E0145 member "bsoncxx::v_noabi::types::b_timestamp::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 562
Error (active) E0145 member "bsoncxx::v_noabi::types::b_int64::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 581
Error (active) E0145 member "bsoncxx::v_noabi::types::b_decimal128::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 606
Error (active) E0145 member "bsoncxx::v_noabi::types::b_minkey::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 637
Error (active) E0145 member "bsoncxx::v_noabi::types::b_maxkey::type_id" may not be initialized textapp e:\nosql_db\mongo-cxx-driver-r3.1.3\include\bsoncxx\v_noabi\bsoncxx\types.hpp 653
Error LNK1107 invalid or corrupt file: cannot read at 0x398 textapp E:\nosql_db\mongo-cxx-driver-r3.1.3\bin\mongocxx.dll 1
Steps followed for installing the driver.
cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=E:\\nosql_db\\mongo-c-driver" "-DCMAKE_BUILD_TYPE=Release"
msbuild.exe /p:Configuration=Release ALL_BUILD.vcxproj
msbuild.exe /p:Configuration=Release INSTALL.vcxproj
cmake -G "Visual Studio 14 2015 Win64" "-DENABLE_SSL=WINDOWS" "-DENABLE_SASL=SSPI" "-DCMAKE_INSTALL_PREFIX=E:\\nosql_db\\mongo-c-driver1" "-DCMAKE_PREFIX_PATH=E:\\nosql_db\\mongo-c-driver" "-DCMAKE_BUILD_TYPE=Release"
msbuild.exe /p:Configuration=Release ALL_BUILD.vcxproj
msbuild.exe /p:Configuration=Release INSTALL.vcxproj
cmake.exe -G "Visual Studio 14 Win64" -DCMAKE_INSTALL_PREFIX=E:\\nosql_db\\mongo-cxx-driver1 -DCMAKE_PREFIX_PATH=E:\\nosql_db\\mon-c-driver -DBOOST_ROOT=E:\\boost_1_65_1
msbuild.exe ALL_BUILD.vcxproj
msbuild.exe INSTALL.vcxproj
Then added additional libraries in vc++ configuration.
E:\nosql_db\mongo-cxx-driver1\include\bsoncxx\v_noabi;E:\nosql_db\mongo-cxx-driver1\include\mongocxx\v_noabi;E:\nosql_db\mon-c-driver\include\libbson-1.0;E:\nosql_db\mon-c-driver\include\libmongoc-1.0;
E:\nosql_db\mongo-cxx-driver1\bin\mongocxx.dll;E:\nosql_db\mongo-cxx-driver1\bin\bsoncxx.dll;E:\nosql_db\mon-c-driver\bin\libbson-1.0.dll;E:\nosql_db\mon-c-driver\bin\libmongoc-1.0.dll;
Here are my linker settings:
/MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"E:\workouts\cpp\textapp\textapp\x64\Release\textapp.pdb" /DYNAMICBASE "mongocxx.dll" "bsoncxx.dll" "libbson-1.0.dll" "libmongoc-1.0.dll" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"E:\nosql_db\mongo-cxx-driver1\bin\mongocxx.dll;E:\nosql_db\mongo-cxx-driver1\bin\bsoncxx.dll;E:\nosql_db\mon-c-driver\bin\libbson-1.0.dll;E:\nosql_db\mon-c-driver\bin\libmongoc-1.0.dll;" /DEBUG:FULL /MACHINE:X64 /OPT:REF /INCREMENTAL:NO /PGD:"E:\workouts\cpp\textapp\textapp\x64\Release\textapp.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\textapp.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"E:\nosql_db\mongo-cxx-driver1\lib\bsoncxx.lib" /LIBPATH:"E:\nosql_db\mongo-cxx-driver1\lib\libbsoncxx.lib" /LIBPATH:"E:\nosql_db\mongo-cxx-driver1\lib\libmongocxx.lib" /LIBPATH:"E:\nosql_db\mongo-cxx-driver1\lib\mongocxx.lib" /LIBPATH:"E:\nosql_db\mon-c-driver\lib\bson-1.0.lib" /LIBPATH:"E:\nosql_db\mon-c-driver\lib\mongoc-1.0.lib" /TLBID:1

Nativescript and angular 2 app breaks when making http calls

On updating to tns core module 2.2.0 and angular rc4 (officially released version by telerik), My app can no longer make http calls to a server, I keep getting this error
com.tns.NativeScriptException:
Calling js method onClick failed
EXCEPTION: Error in /data/data/org.nativescript.EatSafe/files/app/pages/login/login.html:5:75
ORIGINAL EXCEPTION: Error: not implemented
ORIGINAL STACKTRACE:
Error: not implemented
at NativeScriptDomAdapter.Parse5DomAdapter.getCookie (/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/platform-server/src/parse5_adapter.js:619:68)
at CookieXSRFStrategy.configureRequest (/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/http/src/backends/xhr_backend.js:150:82)
at XHRBackend.createConnection (/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/http/src/backends/xhr_backend.js:165:28)
at httpRequest (/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/http/src/http.js:22:20)
at Http.post (/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/http/src/http.js:78:16)
at UserService.signin (/data/data/org.nativescript.EatSafe/files/app/shared/services/user.service.js:13:27)
at LoginComponent.login (/data/data/org.nativescript.EatSafe/files/app/pages/login/login.component.js:31:27)
at DebugAppView._View_LoginComponent0._handle_tap_8_0 (LoginComponent.template.js:355:28)
at /data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/core/src/linker/view.js:375:24
at /data/data/org.nativescript.EatSafe/files/app/tns_modules/nativescript-angular/renderer.js:204:26
ERROR CONTEXT:
[object Object]
File: "/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/core/src/linker/view.js, line: 365, column: 16
StackTrace:
Frame: function:'DebugAppView._rethrowWithContext', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/core/src/linker/view.js', line: 365, column: 17
Frame: function:'', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/core/src/linker/view.js', line: 378, column: 23
Frame: function:'', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/nativescript-angular/renderer.js', line: 204, column: 26
Frame: function:'ZoneDelegate.invoke', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/zone.js/dist/zone-node.js', line: 290, column: 29
Frame: function:'NgZoneImpl.inner.inner.fork.onInvoke', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/core/src/zone/ng_zone_impl.js', line: 53, column: 41
Frame: function:'ZoneDelegate.invoke', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/zone.js/dist/zone-node.js', line: 289, column: 35
Frame: function:'Zone.run', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/zone.js/dist/zone-node.js', line: 183, column: 44
Frame: function:'NgZoneImpl.runInner', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/core/src/zone/ng_zone_impl.js', line: 84, column: 71
Frame: function:'NgZone.run', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/#angular/core/src/zone/ng_zone.js', line: 235, column: 66
Frame: function:'zonedCallback', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/nativescript-angular/renderer.js', line: 203, column: 24
Frame: function:'Observable.notify', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/data/observable/observable.js', line: 174, column: 23
Frame: function:'Observable._emit', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/data/observable/observable.js', line: 193, column: 18
Frame: function:'_android.setOnClickListener.android.view.View.OnClickListener.onClick', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/ui/button/button.js', line: 33, column: 32
at com.tns.Runtime.callJSMethodNative(Native Method)
at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:862)
at com.tns.Runtime.callJSMethodImpl(Runtime.java:727)
at com.tns.Runtime.callJSMethod(Runtime.java:713)
at com.tns.Runtime.callJSMethod(Runtime.java:694)
at com.tns.Runtime.callJSMethod(Runtime.java:684)
at com.tns.gen.android.view.View_OnClickListener.onClick(View_OnClickListener.java:11)
at android.view.View.performClick(View.java:5233)
at android.view.View$PerformClick.run(View.java:21209)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:152)
at android.app.ActivityThread.main(ActivityThread.java:5507)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I have been trying to look online for a release log of the update to see if there are any breaking changes, but to no avail. does anyone have any pointers on how to make http calls with the new nativescript angular updates?
Thank you
I got this fixed by importing in app.moudle.ts the following
import {NativeScriptHttpModule} from 'nativescript-angular/http';
And then
imports: [NativeScriptHttpModule]
You need this code in your main.ts file
import {Parse5DomAdapter} from '#angular/platform-server/src/parse5_adapter';
(<any>Parse5DomAdapter).prototype.getCookie = function (name) { return null; };

Load and Parse a portion of External HTML

I want to extract(parse) a portion HTML document from an external website using php
For example: To extract news from yahoo, i tried using SimpleHTML DOM Parser from sourceforge
<?php
$url="http://news.yahoo.com/einsteins-brain-now-interactive-ipad-app-071441969.html";
include('simple_html_dom.php');
$html=new simple_html_dom();
$html->load_file($url);
$xxx=$html->find('title')->innertext;
echo $xxx;
?>
Fatal error: Call to a member function find() on a non-object in
/home/a1234bc/public_html/simple_html_dom.php on line 1113
Then I tried to echo the loaded html
<?php
$url="http://news.yahoo.com/einsteins-brain-now-interactive-ipad-app-071441969.html";
include('simple_html_dom.php');
$html=new simple_html_dom();
$html->load_file($url);
echo $html;
?>
Now I get:
Fatal error: Call to a member function innertext() on a non-object in
/home/a1234bc/public_html/simple_html_dom.php on line 1688
I also tried using DOMDocument() through file_get_contents()
<?php
$url="http://news.yahoo.com/einsteins-brain-now-interactive-ipad-app-071441969.html";
$content = file_get_contents($url);
// echo $content works perfect
$doc = new DOMDocument();
$doc->loadHTML($content);
$jjj=$doc->getElementsByTagName('title')->item(0);
echo $jjj;
?>
This throws up a very long list of Warnings. So let me just copy paste the first 10 alone
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]:
htmlParseEntityRef: no name in Entity, line: 166 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]:
htmlParseEntityRef: expecting ';' in Entity, line: 166 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]:
htmlParseEntityRef: no name in Entity, line: 256 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]:
htmlParseEntityRef: expecting ';' in Entity, line: 256 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag
fb:login-button invalid in Entity, line: 256 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]:
htmlParseEntityRef: expecting ';' in Entity, line: 275 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]:
htmlParseEntityRef: expecting ';' in Entity, line: 287 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]:
htmlParseEntityRef: expecting ';' in Entity, line: 292 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]:
htmlParseEntityRef: expecting ';' in Entity, line: 311 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute
class redefined in Entity, line: 325 in
/home/a1234bc/public_html/simple_html_dom.php on line 37
Can someone please point me to the right direction?
I got the same error when using the Object-oriented way as shown in the manual:
// Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load('<html><body>Hello!</body></html>');
// Load HTML from a URL
$html->load_file('http://www.google.com/');
// Load HTML from a HTML file
$html->load_file('test.htm');
Got rid of the error and got my script working when I switched to the Quick way as shown in the manual:
// Create a DOM object from a string
$html = str_get_html('<html><body>Hello!</body></html>');
// Create a DOM object from a URL
$html = file_get_html('http://www.google.com/');
// Create a DOM object from a HTML file
$html = file_get_html('test.htm');
After this $html->find worked just fine!
The PHP Simple HTML DOM Parser manual can be found here: http://simplehtmldom.sourceforge.net/manual.htm
Hope this helps!
DOMDocument/SimpleXML are designed for parsing XML not HTML. You would need to use file_get_contents to get the HTML into a string and then using string manipulation functions to get the portion you need. preg_match_all would be a good place to start.

Prevent UIDocumentInteractionController PresentPreview from crashing my App

I'm trying to preview a file with UIDocumentInteractionController. Seems simple enough but randomly the app crashes with a SIGSEGV, and after a few hours trying all kind of hacks I just don't get what's missing.
This code is called from my UIViewController class :
void Initialize ()
{
mInteractionControllerDelegate = new UIDocumentInteractionControllerDelegateClass(this, mFile);
mInteractionController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(mFile.Name));
mInteractionController.Delegate = mInteractionControllerDelegate;
}
mInteractionControllerDelegate and mInteractionController are member variables of my view controller class (I tried that, in order to make sure an event wasn't firing on a variable that would have been GCed)
I present the preview on a button click (the part with the MPMoviePlayerViewController is working fine :
void btnShowTouchUpInside (object sender, EventArgs e)
{
if (mFile.Name.EndsWith(".mpeg") || mFile.Name.EndsWith(".avi") || mFile.Name.EndsWith(".mpg"))
{
MPMoviePlayerViewController mp = new MPMoviePlayerViewController(NSUrl.FromString(mFile.VideoURL));
this.PresentMoviePlayerViewController(mp);
}
else
{
InvokeOnMainThread(delegate {
mInteractionController.PresentPreview(true);
});;
}
}
In some cases, the preview will work (small txt files for example : but I'm not sure of the file size => crash correlation). But if I try with some bigger png files for example (500 ko), I see the preview for a few seconds, and then then app crashes with the following stack trace :
Stacktrace:
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) <IL 0x00024, 0xffffffff>
at MonoTouch.Foundation.NSObject/MonoTouch_Disposer.Drain (MonoTouch.Foundation.NSObject) [0x0002a] in /Users/plasma/Source/iphone/monotouch/Foundation/NSObject.cs:305
at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <IL 0x00052, 0xffffffff>
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26
at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:31
at DTS.Application.Main (string[]) [0x00000] in /Users/seb/Projects/DTS/DTS/Main.cs:14
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
0 DTS 0x000d1965 mono_handle_native_sigsegv + 343
1 DTS 0x0000ffb4 mono_sigsegv_signal_handler + 322
2 libSystem.B.dylib 0x98a9f45b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 ??? 0x0d24837c 0x0 + 220496764
5 ??? 0x077520d6 0x0 + 125116630
6 DTS 0x0000fd6f mono_jit_runtime_invoke + 1332
7 DTS 0x001ee239 mono_runtime_invoke + 137
8 DTS 0x0029e9ab monotouch_trampoline + 2527
9 Foundation 0x0140e94e __NSThreadPerformPerform + 251
10 CoreFoundation 0x00ea08ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
11 CoreFoundation 0x00dfe88b __CFRunLoopDoSources0 + 571
12 CoreFoundation 0x00dfdd86 __CFRunLoopRun + 470
13 CoreFoundation 0x00dfd840 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x00dfd761 CFRunLoopRunInMode + 97
15 GraphicsServices 0x0404c1c4 GSEventRunModal + 217
16 GraphicsServices 0x0404c289 GSEventRun + 115
17 UIKit 0x01ce0c93 UIApplicationMain + 1160
18 ??? 0x09d540a3 0x0 + 164970659
19 ??? 0x09d53e74 0x0 + 164970100
20 ??? 0x09d53474 0x0 + 164967540
21 ??? 0x09d532cc 0x0 + 164967116
22 ??? 0x09d5341e 0x0 + 164967454
23 DTS 0x0000fd6f mono_jit_runtime_invoke + 1332
24 DTS 0x001ee239 mono_runtime_invoke + 137
25 DTS 0x001f0920 mono_runtime_exec_main + 669
26 DTS 0x001efd0a mono_runtime_run_main + 843
27 DTS 0x000a3c62 mono_jit_exec + 200
28 DTS 0x002a25eb main + 3838
29 DTS 0x000030c9 _start + 208
30 DTS 0x00002ff8 start + 40
Debug info from gdb:
/tmp/mono-gdb-commands.VWK7bK:1: Error in sourced command file:
unable to debug self
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Final clue : this is the code for the UIDocumentInteractionControllerDelegateClass (created from other questions on SO) :
public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate
{
private UIViewController mViewController;
private DTSVirtualFile mFile;
public UIDocumentInteractionControllerDelegateClass(UIViewController viewController, DTSVirtualFile file)
{
mViewController = viewController;
mFile = file;
}
public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
{
return mViewController;
}
public override UIView ViewForPreview (UIDocumentInteractionController controller)
{
return mViewController.View;
}
public override RectangleF RectangleForPreview (UIDocumentInteractionController controller)
{
return mViewController.View.Frame;
}
public override void DidEndPreview (UIDocumentInteractionController controller)
{
mFile.DeleteCopy();
}
public override void DidDismissOptionsMenu (UIDocumentInteractionController controller)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
public override void WillBeginPreview (UIDocumentInteractionController controller)
{
Console.WriteLine("WillBeginPreview");
}
public override void WillBeginSendingToApplication (UIDocumentInteractionController controller)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
public override void WillPresentOpenInMenu (UIDocumentInteractionController controller)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
public override void WillPresentOptionsMenu (UIDocumentInteractionController controller)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
}
When I debug I can step over PresentPreview fine, but it then crashes right afterwards. If I comment the PresentPreview line, no crash.
Any pointers, solutions ?
There's an ABI bug that affects MonoTouch when methods returns structs (not classes), like a RectangleF and leads to similar crashes. Device builds (using a different ABO) are not affected by this issue.
A workaround is to avoid overriding methods that returns structure such as:
public override RectangleF RectangleForPreview (UIDocumentInteractionController controller)