【问题标题】:Gmapsfx Integration not working properly in android app Build using Gluon-mobileGmapsfx 集成在使用 Gluon-mobile 构建的 android 应用程序中无法正常工作
【发布时间】:2017-06-30 14:06:21
【问题描述】:

我是使用 Gluon-mobile 进行 Android 开发的新手。
我一直在尝试将 Google MapView 与我的 Android 应用程序集成,所以我使用这个 GMapsFX Api 来构建 Mapview。
我的问题是应用程序在桌面上运行更流畅,但在 Android 设备上部署时应用程序退出。

这是此项目的 build.gradle 文件

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'org.javafxports:jfxmobile-plugin:1.2.0'
}
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
jcenter()
maven {
    url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}

mainClassName = 'com.gluonapplication.Sample'

 dependencies {
compile 'com.gluonhq:charm:4.1.0'
 androidRuntime 'org.sqldroid:sqldroid:1.0.3'
 compileNoRetrolambda 'com.jfoenix:jfoenix:1.0.0'

 compile 'com.lynden:GMapsFX:2.11.0'
 }

 jfxmobile {
downConfig {
    version = '3.2.4'
    // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
    plugins 'display', 'lifecycle', 'local-notifications', 'runtime-args', 'statusbar', 'storage'
}
android {
    manifest = 'src/android/AndroidManifest.xml'
}

}


这是具有 MapView

的 FXML 文件
<?xml version="1.0" encoding="UTF-8"?>

<?import com.lynden.gmapsfx.GoogleMapView?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>

<VBox alignment="CENTER" prefHeight="566.0" prefWidth="353.0" spacing="10" stylesheets="@Maps.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gluonapplication.views.MapController">
<children>

   <Label fx:id="header" layoutX="120.0" layoutY="14.0" text="the Sacred Groves" />
 <GoogleMapView fx:id="MapView" layoutX="4.0" layoutY="62.0" prefHeight="525.0" prefWidth="353.0">
     <children>
        <TextField prefHeight="25.0" prefWidth="173.0" promptText="Enter a Location!" />
     </children></GoogleMapView>

  </children>
 </VBox>


这是创建场景的主类。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
  */
   package com.gluonapplication;

   import javafx.application.Application;
   import javafx.fxml.FXMLLoader;
   import javafx.scene.Scene;
   import javafx.scene.layout.VBox;
   import javafx.stage.Stage;

   /**
     *
     * @author Guru
     */
    public class Sample extends Application{


public static void main(String args[])
{
    launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception 
{

    FXMLLoader loader=new FXMLLoader(getClass().getResource("MapsView.fxml"));
VBox box=loader.load();
Scene scene=new Scene(box);
primaryStage.setScene(scene);
primaryStage.show();

}

}


这是上述 fxml 的 Controller 类

/*
 * To change this license header, choose License Headers in Project Properties.
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
   */
 package com.gluonapplication.views;

 import com.gluonapplication.scenes.Backup;
 import com.gluonapplication.scenes.SceneController;
 import com.lynden.gmapsfx.*;
 import com.lynden.gmapsfx.javascript.object.*;
 import com.lynden.gmapsfx.service.directions.*;
 import java.net.URL;
 import java.util.List;
 import java.util.ResourceBundle;
 import javafx.collections.FXCollections;
 import javafx.fxml.*;


 /**
   *
  * @author Guru
  */
  public class MapController  implements Initializable,   MapComponentInitializedListener, DirectionsServiceCallback,SceneController {
   GoogleMap map;
   Backup backup=null;
    protected DirectionsService directionsService;
protected DirectionsPane directionsPane;
   @FXML
protected GoogleMapView MapView;
   @Override


public void initialize(URL location, ResourceBundle resources)
{
            MapView.addMapInializedListener(this);
            }



public void refresh()
{
    MapView.relocate(10.876224, 77.021764);
}
@Override
public void mapInitialized() {
   MapOptions options = new MapOptions();

    options.center(new LatLong(10.876224, 77.021764))
            .zoomControl(true)
            .zoom(12)
            .overviewMapControl(false)
            .mapType(MapTypeIdEnum.ROADMAP);

     map = MapView.createMap(options);

    directionsService = new DirectionsService();
    directionsPane = MapView.getDirec();


}

@Override
public void directionsReceived(DirectionsResult dr, DirectionStatus ds) 
{
}

@Override
public void setParentScene(Backup backup) {
   this.backup=backup;
}

}


提前致谢!
帮助解决这个问题对我来说一切似乎都很好,但是应用程序在启动时会退出。
但在桌面上工作正常。
我已经运行 adb logcat -v threadtime 并在 cmd 上得到了这个输出

        04-07 22:07:25.029 31214 31214 W System.err: java.lang.reflect.InvocationTargetException
    04-07 22:07:25.030 31214 31214 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-07 22:07:25.030 31214 31214 W System.err:    at javafxports.android.FXDalvikEntity.onGlobalLayout(FXDalvikEntity.java:389)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:912)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1996)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1134)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6050)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.Choreographer.doCallbacks(Choreographer.java:672)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.Choreographer.doFrame(Choreographer.java:608)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.os.Handler.handleCallback(Handler.java:742)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:95)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.os.Looper.loop(Looper.java:154)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:5469)
    04-07 22:07:25.030 31214 31214 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-07 22:07:25.030 31214 31214 W System.err:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    04-07 22:07:25.030 31214 31214 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
    04-07 22:07:25.030 31214 31214 W System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double javafx.scene.Scene.getHeight()' on a null object reference
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.adjustSize(TextFieldSkinAndroid.java:111)
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.lambda$showSoftwareKeyboard$643(TextFieldSkinAndroid.java:107)
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.access$lambda$2(TextFieldSkinAndroid.java)
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid$$Lambda$3.accept(Unknown Source)
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.glass.ui.android.DalvikInput.keyboardSize(DalvikInput.java:72)
    04-07 22:07:25.031 31214 31214 W System.err:    ... 17 more
    04-07 22:07:25.103 31214 31214 W System.err: java.lang.reflect.InvocationTargetException
    04-07 22:07:25.104 31214 31214 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-07 22:07:25.104 31214 31214 W System.err:    at javafxports.android.FXDalvikEntity.onGlobalLayout(FXDalvikEntity.java:389)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:912)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1996)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1134)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6050)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.Choreographer.doCallbacks(Choreographer.java:672)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.Choreographer.doFrame(Choreographer.java:608)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.os.Handler.handleCallback(Handler.java:742)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:95)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.os.Looper.loop(Looper.java:154)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:5469)
    04-07 22:07:25.104 31214 31214 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-07 22:07:25.104 31214 31214 W System.err:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    04-07 22:07:25.104 31214 31214 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
    04-07 22:07:25.105 31214 31214 W System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double javafx.scene.Scene.getHeight()' on a null object reference
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.adjustSize(TextFieldSkinAndroid.java:111)
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.lambda$showSoftwareKeyboard$643(TextFieldSkinAndroid.java:107)
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.access$lambda$2(TextFieldSkinAndroid.java)
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid$$Lambda$3.accept(Unknown Source)
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.glass.ui.android.DalvikInput.keyboardSize(DalvikInput.java:72)
    04-07 22:07:25.105 31214 31214 W System.err:    ... 17 more
    04-07 22:07:25.110 31214 31572 E libEGL  : validate_display:255 error 3008 (EGL_BAD_DISPLAY)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime: FATAL EXCEPTION: JavaFX Application Thread
    04-07 22:07:25.150 31214 31255 E AndroidRuntime: Process: com.gluonapplication, PID: 31214
    04-07 22:07:25.150 31214 31255 E AndroidRuntime: java.lang.UnsupportedOperationException: Not supported yet.
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.webkit.WebPage.executeScript(WebPage.java:152)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine.executeScript(WebEngine.java:860)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.javascript.JavaFxWebEngine.executeScript(JavaFxWebEngine.java:42)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.GoogleMapView.initialiseScript(GoogleMapView.java:253)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.GoogleMapView.access$000(GoogleMapView.java:47)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.GoogleMapView$1.changed(GoogleMapView.java:224)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.GoogleMapView$1.changed(GoogleMapView.java:221)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.beans.property.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:176)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:142)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine$LoadWorker.updateState(WebEngine.java:1023)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine$LoadWorker.dispatchLoadEvent(WebEngine.java:1134)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine$LoadWorker.access$1000(WebEngine.java:1016)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine$PageLoadListener.dispatchLoadEvent(WebEngine.java:1003)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.webkit.WebPage.fireLoadEvent(WebPage.java:251)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.webkit.NativeWebView$1.run(NativeWebView.java:100)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl.lambda$null$156(PlatformImpl.java:295)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl.access$lambda$18(PlatformImpl.java)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at java.security.AccessController.doPrivileged(AccessController.java:52)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl.lambda$runLater$157(PlatformImpl.java:294)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl.access$lambda$5(PlatformImpl.java)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:818)
    04-07 22:07:25.154 31214 31255 E MQSEventManagerDelegate: failed to get MQSService.

【问题讨论】:

  • 转到 Android sdk platform-tools 文件夹,并在连接手机的情况下从命令行 adb logcat -v threadtime 运行。然后运行您的应用程序并在控制台上检查应用程序退出时可能出现的异常。解决不了的请贴出相关部分。
  • 实际上,我已经完成了,我得到了 Invocationtarget 异常,不支持的操作异常:不支持的异常先生,
  • 您正在切断消息,正是它会显示错误原因的位置:TextField 中存在 NPE。尽可能详细地复制粘贴堆栈跟踪的文本,而不是屏幕截图。
  • 我已按照您的要求进行了更改!先生

标签: java android javafx javafxports gluon-mobile


【解决方案1】:

你可以在堆栈跟踪中检查,这个调用:

com.lynden.gmapsfx.javascript.JavaFxWebEngine.executeScript()

JavaFXPorts 不支持:GMapsFX 库使用WebView 控件,虽然支持此控件,但不支持使用 Javascript。

实际上,移动设备中的 WebView 控件的实现与其 JavaFX 版本一不同,因为它使用本机实现(android 或 iOS webKit)。

因此,JavaFX WebView 中包含的 Javascript 和其他功能(如历史浏览)在移动设备上不可用。

作为 GMapsFX 的可能替代方案,您可以查看 Gluon Maps,这是一个在 JavaFX 容器上运行的开源库,无需 WebView。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-06
    • 2018-12-18
    • 2015-03-20
    • 2021-04-09
    • 1970-01-01
    • 2020-06-24
    • 2020-05-08
    • 2011-09-26
    相关资源
    最近更新 更多