Categories
discuss

Implementing GLSurfaceView.Renderer Issues

Code derived from the tutorial

I am beginning some OpenGL-ES 2.0 for the Android system. I took the following code from: http://developer.android.com/training/graphics/opengl/environment.html#renderer

public class MyRenderer implements GLSurfaceView.Renderer {
    public void onSurfaceCreated(GL10 unused, EGLConfig config) {
        GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    }

    public void onDrawFrame(GL10 unused) {
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    }

    public void onSurfaceChanged(GL10 unused, int width, int height) {
        GLES20.glViewport(0, 0, width, height);
    }
}

I am receiving the following error

Gradle: error: MyRenderer is not abstract and does not override abstract method onSurfaceCreated(GL10,EGLConfig) in Renderer

Does anyone know how to proceed? I need to use the MyRenderer class to pass to the GLSurfaceView, so simply declaring it abstract is not a viable solution. Can anybody shed some light on my problem?

Answer

Found the Issue!

The Incorrect version of the imports looked like this

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.EGLConfig;

import javax.microedition.khronos.opengles.GL10;

But GLSurfaceView.Renderer wanted the EGLConfig from the javax library

The following code is the Correct version of the imports

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

I discovered this after looking at the interface implementation

public static interface Renderer {
    void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl10, javax.microedition.khronos.egl.EGLConfig eglConfig);

    void onSurfaceChanged(javax.microedition.khronos.opengles.GL10 gl10, int i, int i1);

    void onDrawFrame(javax.microedition.khronos.opengles.GL10 gl10);
}
Categories
discuss

Difference between Kivy and Java for android apps

I’m a python developer with little experience creating android apps in java and want to create an app that will access my university web portal, retrieve some data and show on a view.

So, after researching Kivy, I have a few questions:

1) Which one is easier and faster to develop android apps?

2) Does Kivy have any android feature limitations?

3) And finally, would an android app developed using kivy run as fast as one developed using java?

Answer

This is a rather subjective question.

1) Which one its easier and faster to develop android apps?

I think there’s a strong argument for kivy, but this doesn’t have an objective answer.

2) Does Kivy has limitations to access certain parts of android (like not fully integrated with its api)?

The kivy project includes pyjnius, a tool for accessing java classes through python, and in principle I think this should give arbitrary (edit: on reflection, not arbitrary, but probably not limited in immediately important ways) access to the java apis.

In practice, prebuilt python wrappers are a work in progress, though rapidly improving. The android python library already gives easy access to many things (including but not limited to intents, vibration, accelerometer etc.). Even where there isn’t already a python wrapper, it can be very easy to do the necessary work.

Edit: There has recently been great work on Kivy’s plyer project, intended to provide a transparent api to platform specific tools so that you can call it once and get the same behaviour on different systems without knowing about the details. It includes useful support for parts of the android api.

3) And finally, an android app developed using kivy would run as fast as one developed using java?

Ultimately the answer is probably no, but the difference is highly unlikely to be important unless you’re doing something strongly cpu limited. The task you suggest would not be limited in that way.

Categories
discuss

Passing arguments to an IIFE

What’s the correct syntax for passing arguments to an IIFE stored in a variable?

Example below tells me that foo is not defined, regardless on if I call the function or not:

var bar = (function(foo){

    return { 
        getFoo: function(){
            return foo;
        } 
    }

})(foo);

console.log(bar.getFoo(1));

http://jsfiddle.net/eSTkL/

Answer

The IIFE is immediately invoked. You are passing foo to it at the moment of invocation, and I suppose it’s undefined.

What gets stored in bar is not the IIFE, but the object returned by the IIFE, that doesn’t have anything to do with foo (beside having access to it via closure). If you want foo to be 1, don’t pass that value to getFoo, but to the IIFE itself:

var bar = (function(foo){

    return { 
        getFoo: function(){
            return foo;
        } 
    }

})(1);

console.log(bar.getFoo()); // 1

If you want a getter and a setter (actually, getter/setter-like functions), use this:

var bar = (function(foo){

    return { 
        getFoo: function(){
            return foo;
        },
        setFoo: function(val) {
            foo = val;
        }
    }

})(1);

console.log(bar.getFoo()); // 1
bar.setFoo(2);
console.log(bar.getFoo()); // 2
Categories
discuss

Trying to run Android game using libgdx on Genymotion

Anybody experienced with libgdx and genymotion?

I’m trying to get a libgdx game running on genymotion android emulator – http://www.genymotion.com/

Everytime I try to run on genymotion I get the following exception:

java.lang.ExceptionInInitializerError
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1319)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
    at android.app.ActivityThread.access$600(ActivityThread.java:130)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load shared library 'gdx' for target: Linux, 32-bit
    at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:113)
    at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:34)
    at com.badlogic.gdx.backends.android.AndroidApplication.<clinit>(AndroidApplication.java:61)
    ... 15 more
 Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gdx: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
    at java.lang.System.loadLibrary(System.java:535)
    at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:109)
    ... 17 more

Any Ideas?

Works fine with AVD

Android API 16 libgdx 0.9.9 Genymotion 1.1.0

Answer

You should try to add the x86 native libraries to your libs folder as mentioned in this post

To use the x86 natives, simply copy the x86/ folder from the nightlies to your Android project’s libs/ folder (next to the armeabi and armeabi-v7a folder). The setup-ui will not add those libraries for you automatically. I opted to do it this way for the time being as x86 Android devices are super rare, and you’d just blow up the size of your APK unnecessarily.

Categories
discuss

Create a new line in Java’s FileWriter

I have coded the following FileWriter:

try {
    FileWriter writer = new FileWriter(new File("file.txt"), false);

    String sizeX = jTextField1.getText();
    String sizeY = jTextField2.getText();
    writer.write(sizeX);
    writer.write(sizeY);

    writer.flush();
    writer.close();
} catch (IOException ex) {}

Now I want to insert a new line, just like you would do it with n normally, but it doesn’t seem to work.

What can be done to solve this?

Thank you.

Answer

If you want to get new line characters used in current OS like rn for Windows, you can get them by

  • System.getProperty("line.separator");
  • since Java7 System.lineSeparator()
  • or as mentioned by Stewart generate them via String.format("%n");

You can also use PrintStream and its println method which will add OS dependent line separator at the end of your string automatically

PrintStream fileStream = new PrintStream(new File("file.txt"));
fileStream.println("your data");
//         ^^^^^^^ will add OS line separator after data 

(BTW System.out is also instance of PrintStream).

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..