ImageView

76 views
Skip to first unread message

ninadpa...@gmail.com

unread,
Jun 22, 2015, 1:30:32 AM6/22/15
to javafx...@googlegroups.com
Hello. I need some help with a null pointer I'm getting for the ImageView in JavaFX. Logcat shows a nullpointer exception on the ImageView. I guess the directory to store the images in is not correct or I'm not using the proper path in the code.

Code:
ImageView iv1 = new ImageView();
Image splashImage = new Image(getClass().getClassLoader().getResourceAsStream("mainback.png"));
iv1.setImage(splashImage);


Link to image showing the structure of the gluon project
https://drive.google.com/open?id=0B1QMRzblOJpbM0pFWldJU1g0LUU&authuser=0

The below code was added automatically from the script I think:

stage.getIcons().add(new Image(gluonTest.class.getResourceAsStream("/icon.png")));

and it works properly. Tried to set my Image source as the same but it still threw the same error.

Message has been deleted

ninadpa...@gmail.com

unread,
Jun 22, 2015, 1:48:39 AM6/22/15
to javafx...@googlegroups.com, ninadpa...@gmail.com
Ok so the nullpointer exception went away but now the following is shown in the logcat

D/dalvikvm( 525): GC_FOR_ALLOC freed 104K, 3% free 26236K/27015K, paused 88ms
I/dalvikvm-heap( 525): Grow heap (frag case) to 29.638MB for 4064272-byte alloc
ation
D/dalvikvm( 525): GC_FOR_ALLOC freed <1K, 3% free 30204K/31047K, paused 87ms
I/System.out( 525): max rectangle texture cell size = 62
I/System.out( 525): wrap rectangle texture = 2 x 2
I/System.out( 525): ES2ResourceFactory: Prism - createStockShader: AlphaTexture
_Color.frag
W/System.err( 525): java.lang.UnsupportedOperationException: Pixel format BYTE_
BGRA_PRE not supported on this device
W/System.err( 525): at com.sun.prism.es2.ES2Texture.create(ES2Texture.java:1
02)
W/System.err( 525): at com.sun.prism.es2.ES2ResourceFactory.createTexture(ES
2ResourceFactory.java:138)
W/System.err( 525): at com.sun.prism.impl.BaseResourceFactory.createTexture(
BaseResourceFactory.java:242)
W/System.err( 525): at com.sun.prism.impl.BaseResourceFactory.getCachedTextu
re(BaseResourceFactory.java:218)
W/System.err( 525): at com.sun.prism.impl.BaseResourceFactory.getCachedTextu
re(BaseResourceFactory.java:152)
W/System.err( 525): at com.sun.javafx.sg.prism.NGImageView.renderContent(NGI
mageView.java:121)
W/System.err( 525): at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2
053)
W/System.err( 525): at com.sun.javafx.sg.prism.NGImageView.doRender(NGImageV
iew.java:103)
W/System.err( 525): at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:194
5)
W/System.err( 525): at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup
.java:235)
W/System.err( 525): at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegi
on.java:576)
W/System.err( 525): at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2
053)
W/System.err( 525): at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:194
5)
W/System.err( 525): at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPai
nter.java:474)
W/System.err( 525): at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewP
ainter.java:327)
W/System.err( 525): at com.sun.javafx.tk.quantum.PresentingPainter.run(Prese
ntingPainter.java:91)
W/System.err( 525): at java.util.concurrent.Executors$RunnableAdapter.call(E
xecutors.java:442)
W/System.err( 525): at java.util.concurrent.FutureTask$Sync.innerRunAndReset
(FutureTask.java:322)
W/System.err( 525): at java.util.concurrent.FutureTask.runAndReset(FutureTas
k.java:149)
W/System.err( 525): at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
W/System.err( 525): at java.util.concurrent.ThreadPoolExecutor.runWorker(Thr
eadPoolExecutor.java:1076)
W/System.err( 525): at java.util.concurrent.ThreadPoolExecutor$Worker.run(Th
readPoolExecutor.java:569)
W/System.err( 525): at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRun
nable.run(QuantumRenderer.java:125)
W/System.err( 525): at java.lang.Thread.run(Thread.java:856)

It appears for 4 times after which

D/OpenGLRenderer( 173): Flushing caches (mode 1)
D/dalvikvm( 173): GC_FOR_ALLOC freed 519K, 15% free 38219K/44871K, paused 427ms

D/dalvikvm( 173): GC_FOR_ALLOC freed 2K, 12% free 39838K/44871K, paused 350ms
D/dalvikvm( 173): GC_FOR_ALLOC freed 0K, 10% free 40811K/44871K, paused 79ms
I/dalvikvm-heap( 173): Grow heap (frag case) to 43.521MB for 3700240-byte alloc
ation
D/dalvikvm( 173): GC_FOR_ALLOC freed 0K, 9% free 44424K/48519K, paused 83ms
W/InputManagerService( 79): Starting input on non-focused client com.android.i
nternal.view.IInputMethodClient$Stub$Proxy@4255f600 (uid=10021 pid=173)
D/OpenGLRenderer( 173): Flushing caches (mode 0)
W/NetworkManagementSocketTagger( 79): setKernelCountSet(10021, 0) failed with
errno -2
D/dalvikvm( 173): GC_CONCURRENT freed 6244K, 20% free 38954K/48519K, paused 8ms
+27ms
D/dalvikvm( 163): GC_CONCURRENT freed 443K, 3% free 23230K/23879K, paused 8ms+7
ms

I'm running it on the API 15 arm emulator. Should I run it on a device?

Dino Quimson

unread,
Jun 25, 2015, 12:36:07 AM6/25/15
to javafx...@googlegroups.com, ninadpa...@gmail.com
Take a look at this example: Game2048FX. Make it as your reference on how to add ImageView in JavaFX running on Android.

ninadpa...@gmail.com

unread,
Jun 25, 2015, 5:03:05 PM6/25/15
to javafx...@googlegroups.com, ninadpa...@gmail.com
Oh great!!! Thank You for that!
After a lot of tinkering and referencing with the game I finally made an app which used all animations and images properly.
Now, I have just two questions. Hope you bear with me, I am trying to learn as fast as I can. :)

1) After the successful run of the app I decided to use the Android API. For this, the platform provider and service are required correct? I correctly wrote them including the META-INF.services file. I kept two methods in the interface, first the default getName() which ran properly on the desktop and android device via their respective provider files, second a void setNotify() method which ran properly on the desktop since I just made a System out. However, in the android part I made it to display a Toast with all the relevant android packages and the FXActivity.getInstance(). When I ran the code, it made the application "Unfortunately stop". Should I add more stacksize in the properties file?
The code for this provider file is in the end.

2) To display a Notification on the android device requires to add the support library v4. How do I go about achieving that?

The code in AndroidPlatformProvider.java

import android.content.Context;
import android.widget.Toast;
import javafxports.android.FXActivity;

public class AndroidPlatformProvider implements PlatformProvider {

@Override
public String getName() {
return "Android";
}

@Override
public void setNotify() {
Toast.makeText(FXActivity.getInstance(), "You have been toasted!!!",
Toast.LENGTH_LONG).show();
}

}

Code in DesktopPlatformProvider.java

public class DesktopPlatformProvider implements PlatformProvider {

@Override
public String getName() {
return "Desktop";
}

@Override
public void setNotify() {
System.out.println("Notified");
}

}

Code in PlatformProvider.java

public interface PlatformProvider {

String getName();

void setNotify();

}

Releveant code in PlatformService.java


public void setNotify(){
provider.setNotify();
}

Reply all
Reply to author
Forward
0 new messages