Libgdx Game crashes when using Box2d World - java

I created a libgdx game that works fine on desktop mode, then I tried it to run on android platform. The game goes to the menu screen without any problem but when I click the play button, the game closes "Unfortunately, mygame stopped working".
I have a loding screen and when it's done loading the assets it goes to the menu screen:
if(assetManager.update()){
game.setScreen(new MenuScreen(game, assetManager));
}
Then on my menu screen I have a play button that when clicked it goes to the game screen:
ChangeListener listener = new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
//play button
if(actor.equals(playBtn)) {
menuMusic.stop();
game.setScreen(new GameScreen(game, assetManager, settingsPrefs));
}
}
}
On desktop mode it works fine but on Android once I click the play button I get these errors (not the full log):
E/AndroidRuntime: FATAL EXCEPTION: GLThread 4474
java.lang.NoClassDefFoundError: com.myname.mygame.worlds.MyContactListener
E/AndroidGraphics: waiting for pause synchronization took too long; assuming deadlock and killing
The error log says that the problem is is the box2d world and it's contact listener, but to me it's all good. I'm thinking it's the ParticleEffect I have quite a few of them and I did not load them properly I just used the Gdx.files.internal(). How do you load Libgdx ParticleEffect on AssetManager?
is there a way for the application to not assume deadlock? so that the application does not close
UPDATE (I found what causes the error)
So I tried to change my code cause I taught the way I coded the game is not that good and still have the same problem on the Android platform. The game run properly and it goes to the menu screen but when you click the play button it crashes. So what I did is added a Box2d world in the menu screen
world = new World(0f, -10f);
Then I got the same error when I try to transition to the game screen
FATAL EXCEPTION: GLThread 8739
Process: com.myname.mygame, PID: 12794
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/badlogic/gdx/physics/box2d/World;
Once I added box2d world to the class I just get the error, the problem is on the World class, so how do I know if the package which contains the class is properly installed? or there are other solutions?

As the documention says:
https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/physics/box2d/World.html,
World has only this constructor
World(Vector2 gravity, boolean doSleep)
So how is it possible that you are creating a World object in that way?
Furthemore, check this answer :
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=22311

Related

Automatically/Programmaticaly tap foreground service window that is always on top

I have challenged myself to code an in house app similar to Google's assistant voice tapping app. Everything is finished except the auto tap feature. When I launch the app it spins up a foreground service that draws a 8x8 grid that is always on top. Even when the main activity is minimized. The service uses an imageview that is set drawable. I then wrote an algorithm that draws a grid within it numbered 1 through 64. The user says which number to tap and the service does just that but nothing happens. I Log.wtf the tap coordinates x,y and it works perfectly when my main activity is open. when minimized it doesnt log the event OR its taping the wrong view.
Any suggestions?
Here is the code inside my custom window class that pops the window and sets the tap transperency so that taps pass through to the target app behind it. tPars is different for testing purposes. Both are window parameters.
`
mPars=new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);
lInflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
gridView = lInflater.inflate(R.layout.window_overlay,null);
iv = gridView.findViewById(R.id.iv);
ivHolder= gridView.findViewById(R.id.ivHolder);
((ImageView)iv).setImageDrawable(new Draw());
mPars.gravity=Gravity.CENTER;
mWManager=(WindowManager) context.getSystemService(WINDOW_SERVICE);
`
Ive even tried using System.exec("Touch X,Y"). Still same issue. Broadcast receivers wont work as the goal is to stay within the service WHILE using other apps. Its an auto tap assistant app like googles.
I would like to utilize this ---> MOTION EVENT
To reiterate, Once Main Activity spins up the service I no longer want or need it as the user will be using other apps. My app allows them to Tap/Scroll with their voice via the foreground service overlay.
Thanks in advance.
I tried MotionEvent, System.exec, and a few 3rd party APIs. It will only tap withing Main Activities view.
EDIT
Here is my tap and recognition code.
else if(sentence.get(0).equalsIgnoreCase("tap")){
mWManager.addView(gridView, mPars);
grid.draw(new Canvas());
tap(548F,946F);
}
and execution
private void tap(Float x, Float y) {
gridView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis()+100, (int)MotionEvent.ACTION_DOWN, x, y, 0));
gridView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis()+100, (int)MotionEvent.ACTION_UP, x, y, 0));
}

Changing from a non activity to an activity Android Studio

I'm currently developing a game app for my 2nd year project at uni, but i'm a little stuck on how i can move from a non-activity class to an activity. So my none activity class is a quit screen within the game (yes i know you shouldn't use quit in a game but its one of my requirements), when i click on a button i want it to take me to the activity. (which basically thanks the user for playing and then exits the app) using System.exit(0) is just going back to the last activity visited.
The screen extends my Game Screen Class which is a parent class i created, this is the code for what happens when the user touches the 'yes' button in the quit screen:
#Override
public void update(ElapsedTime elapsedTime) {
Input input = game.getInput();
List<GameTouchEvent> touchEvents = input.getTouchEvents();
if(touchEvents.size() > 0){
GameTouchEvent touchEvent = touchEvents.get(0);
if(yesButtonBound.contains((int) touchEvent.x, (int) touchEvent.y)){
System.exit(0);
}
I'm not looking for specific code answers as this is a project but any advice or hints would be very appreciated thanks!!

Android Application for Kids

I'm Developing Android Application for Parental Controlling, so I want to disable home and back button. Because kids are unpredictable, their can push home button or back button and so on. Than i want to disable sliding notification bar. (Because notification bar can change device configuration and setting)
I'm planning to create Android Application which is similar to the Samsung Kids Mode-Parental Control.
Is possible to create application like Samsung Kids Mode? Can you give some link/article or even example program to me?
I Have tried this :
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
but it not handle home button, the Home button still working.
Thanks in advance to everyone for taking time to read this, hoping a positive solution.
I dont know of anyway to override the home button. Im not sure that it can be done. You can override the back button like so.
#Override
public void onBackPressed() {
//do nothing, important dont call super.onBackPressed
}
Another this you can do is set the app to immersive mode to reduce the chance of accidently exiting the app
https://developer.android.com/training/system-ui/immersive.html
Extended from Activity
#Override
public void onBackPressed() {
}
can be used to override back button. Be sure to remove super.onBackPressed().

I want to run the application in background of mobile without any GUI in mobile using J2ME?

I am developing the network application in which I want to run my J2ME MIDP application in background without any GUI so that is any way to construct the application is such manner.
try this
set your current Display to null. so there will not be any form or alert running on the screen. But however your code will be running in the background.
Display display = Display.getDisplay(this); // here 'this' points to Midlet
display.setCurrent(null);
it easy just have a code of line on any event for example in the click of button
Display.getDisplay (this).setCurrent (null);
and return back the control via
Display.getDisplay (this).setCurrent (mycanvas);
Yes this code works Good,
display = Display.getDisplay(this);
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void hide()
{
Display.getDisplay (this).setCurrent (null);
}
This is will work like, make a button can after clicking it call hide Function, or you call this hide function in constructor so it will hide itself when app start, can you keep unHide statement in appStart() so if you Tab the program then it will unHide app again.
NOTE: you said you are working on Network app, but some mobile will turn off the Internet Connection, when the Mobile screen Turn Off. please check this. and If you found any solution It will be Good to share here.

How to make a J2ME application run in Background?

I have a written a J2ME application which uses Bluetooth and search a file within the peer mobile and download it. I would like to make my application run in background , whenever I get a call , or message and later resume after few seconds , Has anybody worked on this please share your experience . Is there any way to run a Midlet in background ?
to set a j2me app to the background use the following in your midlet class:
Display.getDisplay (this).setCurrent (null);
to get the screen back use the following:
Display.getDisplay (this).setCurrent (myCanvas);
Where myCanvas is your canvas instantiation
R
p.s. You can still use a thread or timer to do things in the background while your midlet is hidden.
p.s.2: this does not work on all models. (Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others.
A device's ability to run an application in the background depends on its ability to multitask. Therefore, more expensive, PDA-type devices are more likely to support background execution than lower-cost devices.
For in background :-
private Display display = Display.getDisplay(this);
private Displayable previousDisplayable;
public void toBack() {
previousDisplayable = display.getCurrent();
display.setCurrent(null);
}
And to come in Fore ground :-
public void toFront() {
display.setCurrent(previousDisplayable);
}
But be aware that it not supports every device.(Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others).

Categories