Hello world problem

Started by xender, May 16, 2012, 09:18:47 PM

Previous topic - Next topic

xender

does not want to run hello world application
library to load, run
Eclipse I wrote

05-16 18:59:39.503: D/dalvikvm(466): VFY: dead code 0x0005-0008 in Lcom/android/Game;.onStop ()V
05-16 18:59:39.512: D/AndroidRuntime(466): Shutting down VM
05-16 18:59:39.512: W/dalvikvm(466): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-16 18:59:39.523: E/AndroidRuntime(466): FATAL EXCEPTION: main
05-16 18:59:39.523: E/AndroidRuntime(466): java.lang.NoClassDefFoundError: com.threed.jpct.RGBColor
05-16 18:59:39.523: E/AndroidRuntime(466): at com.android.Game.<init>(Game.java:51)
05-16 18:59:39.523: E/AndroidRuntime(466): at java.lang.Class.newInstanceImpl(Native Method)
05-16 18:59:39.523: E/AndroidRuntime(466): at java.lang.Class.newInstance(Class.java:1429)
05-16 18:59:39.523: E/AndroidRuntime(466): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-16 18:59:39.523: E/AndroidRuntime(466): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-16 18:59:39.523: E/AndroidRuntime(466): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-16 18:59:39.523: E/AndroidRuntime(466): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-16 18:59:39.523: E/AndroidRuntime(466): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-16 18:59:39.523: E/AndroidRuntime(466): at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 18:59:39.523: E/AndroidRuntime(466): at android.os.Looper.loop(Looper.java:123)
05-16 18:59:39.523: E/AndroidRuntime(466): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-16 18:59:39.523: E/AndroidRuntime(466): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 18:59:39.523: E/AndroidRuntime(466): at java.lang.reflect.Method.invoke(Method.java:521)
05-16 18:59:39.523: E/AndroidRuntime(466): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-16 18:59:39.523: E/AndroidRuntime(466): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-16 18:59:39.523: E/AndroidRuntime(466): at dalvik.system.NativeStart.main(Native Method)



here's the code...
package com.android;


import java.lang.reflect.Field;

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

import android.app.Activity;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.OnScaleGestureListener;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.GLSLShader;
import com.threed.jpct.ITextureEffect;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Logger;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureInfo;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.MemoryHelper;

/**
*
*
* @author EgonOlsen
*
*/
public class Game extends Activity implements OnScaleGestureListener {

// Used to handle pause and resume...
private static Game master = null;

private ScaleGestureDetector gestureDec = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;
private RGBColor back = new RGBColor(50, 50, 100);

private float touchTurn = 0;
private float touchTurnUp = 0;

private float xpos = -1;
private float ypos = -1;

private Texture font = null;

private Object3D plane;
private Light light;

private GLSLShader shader = null;

private float scale = 0.05f;

protected void onCreate(Bundle savedInstanceState) {
Logger.log("onCreate");
Logger.setLogLevel(Logger.LL_DEBUG);

if (master != null) {
copy(master);
}

super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());

// Enable the OpenGL ES2.0 context
mGLView.setEGLContextClientVersion(2);

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);

gestureDec = new ScaleGestureDetector(this.getApplicationContext(), this);
}

@Override
protected void onPause() {
Logger.log("onPause");
super.onPause();
mGLView.onPause();
}

@Override
protected void onResume() {
Logger.log("onResume");
super.onResume();
mGLView.onResume();
}

@Override
protected void onStop() {
Logger.log("onStop");
super.onStop();
}

private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public boolean onTouchEvent(MotionEvent me) {

gestureDec.onTouchEvent(me);

if (me.getAction() == MotionEvent.ACTION_DOWN) {
xpos = me.getX();
ypos = me.getY();
return true;
}

if (me.getAction() == MotionEvent.ACTION_UP) {
xpos = -1;
ypos = -1;
touchTurn = 0;
touchTurnUp = 0;
return true;
}

if (me.getAction() == MotionEvent.ACTION_MOVE) {
float xd = me.getX() - xpos;
float yd = me.getY() - ypos;

xpos = me.getX();
ypos = me.getY();

touchTurn = xd / -100f;
touchTurnUp = yd / -100f;
return true;
}

try {
Thread.sleep(15);
} catch (Exception e) {
// No need for this...
}

return super.onTouchEvent(me);
}

protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private int fps = 0;
private int lfps = 0;

private long time = System.currentTimeMillis();

public MyRenderer() {
Texture.defaultToMipmapping(true);
Texture.defaultTo4bpp(true);
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null) {
fb.dispose();
}

Resources res = getResources();

fb = new FrameBuffer(w, h);

if (master == null) {
world = new World();

TextureManager tm = TextureManager.getInstance();

Texture face = new Texture(res.openRawResource(R.raw.face));
Texture normals = new Texture(res.openRawResource(R.raw.face_norm), true);
Texture height = new Texture(res.openRawResource(R.raw.face_height2));

plane = Primitives.getPlane(1, 100);

TexelGrabber grabber = new TexelGrabber();
height.setEffect(grabber);
height.applyEffect();
int[] heighties = grabber.getAlpha();

AlphaMerger setter = new AlphaMerger(heighties);
normals.setEffect(setter);
normals.applyEffect();

font = new Texture(res.openRawResource(R.raw.numbers));
font.setMipmap(false);

tm.addTexture("face", face);
tm.addTexture("normals", normals);

TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("face"));
ti.add(TextureManager.getInstance().getTextureID("normals"), TextureInfo.MODE_BLEND);

plane.setTexture(ti);

shader = new GLSLShader(Loader.loadTextFile(res.openRawResource(R.raw.vertexshader_offset)), Loader.loadTextFile(res.openRawResource(R.raw.fragmentshader_offset)));
plane.setShader(shader);
plane.setSpecularLighting(true);
shader.setStaticUniform("invRadius", 0.0003f);

plane.build();
plane.strip();

world.addObject(plane);

light = new Light(world);
light.enable();

light.setIntensity(60, 50, 50);
light.setPosition(SimpleVector.create(-10, -50, -100));

world.setAmbientLight(10, 10, 10);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 70);
cam.lookAt(plane.getTransformedCenter());

MemoryHelper.compact();

world.compileAllObjects(fb);

if (master == null) {
Logger.log("Saving master Activity!");
master = Game.this;
}
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Logger.log("onSurfaceCreated");
}

public void onDrawFrame(GL10 gl) {
if (touchTurn != 0) {
plane.rotateY(touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
plane.rotateX(touchTurnUp);
touchTurnUp = 0;
}

shader.setUniform("heightScale", scale);

fb.clear(back);
world.renderScene(fb);
world.draw(fb);
blitNumber(lfps, 5, 5);
fb.display();

if (System.currentTimeMillis() - time >= 1000) {
lfps = fps;
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}

private void blitNumber(int number, int x, int y) {
if (font != null) {
String sNum = Integer.toString(number);

for (int i = 0; i < sNum.length(); i++) {
char cNum = sNum.charAt(i);
int iNum = cNum - 48;
fb.blit(font, iNum * 5, 0, x, y, 5, 9, 5, 9, 10, true, null);
x += 5;
}
}
}
}

public boolean onScale(ScaleGestureDetector detector) {
float div = detector.getCurrentSpan() - detector.getPreviousSpan();
div /= 5000;

scale += div;

if (scale > 0.063f) {
scale = 0.063f;
}
if (scale < 0) {
scale = 0;
}

return true;
}

public boolean onScaleBegin(ScaleGestureDetector detector) {
// TODO Auto-generated method stub
return true;
}

public void onScaleEnd(ScaleGestureDetector detector) {
// TODO Auto-generated method stub
}

/**
* Merges the height map into the alpha channel of the normal map.
*
* @author EgonOlsen
*
*/
private static class AlphaMerger implements ITextureEffect {

private int[] alpha = null;

public AlphaMerger(int[] alpha) {
this.alpha = alpha;
}

public void apply(int[] arg0, int[] arg1) {
int end = arg1.length;
for (int i = 0; i < end; i++) {
arg0[i] = arg1[i] & 0x00ffffff | alpha[i];
}
}

public boolean containsAlpha() {
return true;
}

public void init(Texture arg0) {
// TODO Auto-generated method stub
}
}

/**
* Extracts the alpha channel from a texture.
*
* @author EgonOlsen
*
*/
private static class TexelGrabber implements ITextureEffect {

private int[] alpha = null;

public void apply(int[] arg0, int[] arg1) {
alpha = new int[arg1.length];
int end = arg1.length;
for (int i = 0; i < end; i++) {
alpha[i] = (arg1[i] << 24);
}
}

public int[] getAlpha() {
return alpha;
}

public boolean containsAlpha() {
return true;
}

public void init(Texture arg0) {
// TODO Auto-generated method stub
}
}
}



what's the problem??
I apologize for Literacy Russian, use a translator

EgonOlsen

Google decided to change the export behaviour of the Eclipse plugin. Here's a solution: http://www.jpct.net/forum2/index.php/topic,2663.0.html

xender

next problem

05-16 20:09:52.242: E/AndroidRuntime(586): FATAL EXCEPTION: GLThread 8
05-16 20:09:52.242: E/AndroidRuntime(586): java.lang.IllegalArgumentException: No configs match configSpec
05-16 20:09:52.242: E/AndroidRuntime(586):    at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:760)
05-16 20:09:52.242: E/AndroidRuntime(586):    at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:916)
05-16 20:09:52.242: E/AndroidRuntime(586):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1246)
05-16 20:09:52.242: E/AndroidRuntime(586):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
05-16 20:09:52.332: I/jPCT-AE(586): onPause
05-16 20:09:53.473: I/jPCT-AE(586): onStop

EgonOlsen

Which device are you using?

xender

#4
Eclipse  AVD manager android 2.2

EgonOlsen

It that one using/trying to use the new hardware accelerated gl emulation? Try to remove the mGLView.setEGLConfigChooser... part from the code. I just noticed that you are trying to use OpenGL ES 2.0. The emulator doesn't support this. Get a real device, the emulator sucks anyway.

xender

Thank you very much for your help, it worked.