Forum Stats

  • 3,874,152 Users
  • 2,266,674 Discussions
  • 7,911,744 Comments

Discussions

ADF MAF application won't reopen on device or emulator

Brian Robbins
Brian Robbins Member Posts: 17
edited Sep 9, 2014 10:50AM in Mobile Application Framework

jDeveloper 12.1.3, MAF 2.0.0.0

The application will not re-open after exiting out. Using the back arrow, the home key, force stop the application. Application will only open once per deployment. This occurs on both the emulator and after to deploying to a mobile device. Has anyone else experienced this?

Tagged:

Best Answer

  • Deepak-Jain
    Deepak-Jain Member Posts: 510
    Answer ✓

    I guess I got the place from where you are getting NullPointerException.

    finally {

                          if (conn != null)

                              conn.commit();

                              conn.close();

                      }

    The above finally will always be called, even after DB initialization when you open the app for second time.

    Finally is executed even when you return from your try statement.

    Since second time your conn will be null and conn.close() will still be executed resulting in NPE

    Change the above code to the below and your issue should get resolved:

    finally {

                          if (conn != null)

                            {

                              conn.commit();

                              conn.close();

                             }

                      }

    Regards,

    Deepak

Answers

  • I believe the issue comes somewhere in the LifeCycleListenerImpl.java class. This is the only error I can find:

    [SEVERE - oracle.adfmf.application - LifeCycleListenerImpl - start] null

    ERROR [oracle.adfmf.framework.exception.AdfException] - application.LifeCycleListenerImpl: java.lang.RuntimeException: java.lang.NullPointerException

  • Deepak-Jain
    Deepak-Jain Member Posts: 510

    Using back button will not close the application. The application will be in background.

    activate method of LifeCycleListenerImpl is called when you are opening your application for second time.

    Check the code of activate and start method?

    Can you try stopping the application and then open the application and see if it works?

  • There is no code in the activate method. The start method looks like this:

      public void start()

      {

        try

        {

          initializeDatabaseFromScript();

        }

        catch(Exception ex)

        {

          Utility.ApplicationLogger.severe(ex.getMessage());

          throw new RuntimeException(ex);

        }

      }

          private void initializeDatabaseFromScript() throws Exception {

              InputStream scriptStream = null;

              Connection conn = null;

              try {

                 

      // 2: Retrieve the path to the local database file          

                  Utility.ApplicationLogger.info("Initializing DB...");

                  String docRoot = AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.ApplicationDirectory);

                  String dbName = docRoot + "/myDatabase.db";

                 

      // 3: Check if the db file exists or not

                  File dbFile = new File(dbName);

                  if (dbFile.exists())

                      return;

                 

      // 4: If it doesn't exist then we create it - make sure to turn off autocommit - db file created when opened, if it doesn't exist

                  conn = new JDBCDataSource("jdbc:sqlite:" + dbName).getConnection();

                  conn.setAutoCommit(false);

                 

      //  5: Retrieve the db script from storage and store it in memory

                  Utility.ApplicationLogger.info("Reading script");

                  scriptStream =

                      Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/initializedb.sql");

                  BufferedReader scriptReader = new BufferedReader(new InputStreamReader(scriptStream));

                  String nextLine;

                  StringBuffer nextStatement = new StringBuffer();

                 

      // 6: Iterate line after line in the script - if line starts with rem or comment, then skip it.  Otherwise execute each line

                  Statement stmt = conn.createStatement();

                  while ((nextLine = scriptReader.readLine()) != null) {

                  if (nextLine.startsWith("REM") || nextLine.startsWith("COMMIT") || nextLine.length() <1)

                      continue;

                  nextStatement.append(nextLine);

                      if (nextLine.endsWith(";")) {

                          Utility.ApplicationLogger.info("Execute statement: " + nextStatement.toString());

                          stmt.execute(nextStatement.toString());

                          nextStatement = new StringBuffer();

                      }

                  }

                 

      // 7: Exception handeling

                      }finally {

                          if (conn != null)

                              conn.commit();

                              conn.close();

                      }

          }

  • Deepak-Jain
    Deepak-Jain Member Posts: 510
    edited Sep 5, 2014 11:59AM

    Did you try stopping the app from Application Manager and then opening it again?

    The start method looks fine.

    Also check your logs to in monitor to see if there is any exception.

  • I have tried the force stop from the Application Manager, same thing. This is from the logs, but doesn't make much sense to me...

    !MESSAGE Application error

    !STACK 1

    java.lang.NullPointerException

      at org.eclipse.core.runtime.URIUtil.toURI(URIUtil.java:280)

      at org.eclipse.e4.ui.internal.workbench.ResourceHandler.loadMostRecentModel(ResourceHandler.java:127)

      at org.eclipse.e4.ui.internal.workbench.swt.E4Application.loadApplicationModel(E4Application.java:370)

      at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:220)

      at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:557)

      at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)

      at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)

      at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)

      at com.android.ide.eclipse.monitor.MonitorApplication.start(MonitorApplication.java:86)

      at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)

      at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)

      at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)

      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)

      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

      at java.lang.reflect.Method.invoke(Unknown Source)

      at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)

      at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)

      at org.eclipse.equinox.launcher.Main.run(Main.java:1438)

      at org.eclipse.equinox.launcher.Main.main(Main.java:1414)

  • Deepak-Jain
    Deepak-Jain Member Posts: 510

    This looks like an issue in your code.

    Can you just make a static page as your default page and try the above scenario, it should work in that case.

    I think some data corruption is happening and hence your first page is not getting displayed when reopened.

    Brian Robbins
  • Well well well...

    After commenting out the database initialization code from LifeCycleListenerImpl.java the application will launch after exiting. Do I need to check for a connection and close it if one exists in the deactivate() method?

  • Deepak-Jain
    Deepak-Jain Member Posts: 510
    Answer ✓

    I guess I got the place from where you are getting NullPointerException.

    finally {

                          if (conn != null)

                              conn.commit();

                              conn.close();

                      }

    The above finally will always be called, even after DB initialization when you open the app for second time.

    Finally is executed even when you return from your try statement.

    Since second time your conn will be null and conn.close() will still be executed resulting in NPE

    Change the above code to the below and your issue should get resolved:

    finally {

                          if (conn != null)

                            {

                              conn.commit();

                              conn.close();

                             }

                      }

    Regards,

    Deepak

  • So simple! Thank you SO VERY MUCH!