# GetAppInstance returns null!

**URL:** <https://community.wowza.com/t/getappinstance-returns-null/36445>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [April 23, 2014, 2:42pm UTC](https://community.wowza.com/t/getappinstance-returns-null/36445 "2014-04-23T14:42:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janez\_Makovsek](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Janez\_Makovsek](https://community.wowza.com/u/Janez_Makovsek)\
**Post date:** [April 23, 2014, 2:42pm UTC](https://community.wowza.com/t/getappinstance-returns-null/36445/1 "2014-04-23T14:42:48Z")

</div>

Hi!

What could be the possible reasons that:

```auto
public void onServerInit(IServer server)
{
		IVHost vhost = null;
		IApplication application = null;
		IApplicationInstance app = null;
		application = vhost.getApplication(appName); // appName = "myApp"
		app = application.getAppInstance(appInstName); // appInstName = "_definst_"
....
}

```

This sequence would return app == null ?? The vhost is found (not null), the application is found (not null), but trying to get appInstance returns null. There are no errors reported by the startup log. (except that this variable is null). Once the server starts, the application works fine, only my code which depends upon it does not work.

Thanks!

Atmapuri

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [April 23, 2014, 3:07pm UTC](https://community.wowza.com/t/getappinstance-returns-null/36445/2 "2014-04-23T15:07:48Z")

</div>

Hi Atmapuri,

Do this first:

```auto
vhost.startApplicationInstance(appName, appInstName)

```

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [April 23, 2014, 6:42pm UTC](https://community.wowza.com/t/getappinstance-returns-null/36445/3 "2014-04-23T18:42:01Z")

</div>

Try it like this, which works in my test:

```auto
public void onServerInit(IServer server) {
		WMSLoggerFactory.getLogger(null).info("onServerInit");
		
		IVHost vhost = VHostSingleton.getInstance(VHost.VHOST_DEFAULT);
		IApplication application ;
		IApplicationInstance app ;
		
		vhost.startApplicationInstance("vod","_definst_");
		while (true)
		{
			application = vhost.getApplication("vod"); 
			if (!application.equals(null));
				break;
		}
		
		app = application.getAppInstance("_definst_"); 
	}

```

Richard

---

<div class="post-metadata">

**Author:** ![Janez\_Makovsek](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Janez\_Makovsek](https://community.wowza.com/u/Janez_Makovsek)\
**Post date:** [April 23, 2014, 7:13pm UTC](https://community.wowza.com/t/getappinstance-returns-null/36445/4 "2014-04-23T19:13:18Z")

</div>

It turns out, if I dont try to debug the code mentioned (no breakpoint), then this line is not needed:

```auto
vhost.startApplicationInstance(appName, appInstName)

```

Somehow getAppInstance returns a valid object and everything works fine. Now I have put breakpoint after the getAppInstance. Is that usual behaviour?
