Hi I am using Libgdx to create a game. I am currently trying to add a button to my main menu screen. I have created a stage and have added the button actor to the stage. The problem is my app crashes on start up and my logcat says there is an error reading file data/ui/uiskin.json. This is really frustrating me please can you help me solve the error.
I have followed this exactly to no avail this is also where I got the uiskin files.Using scene2d.ui with libgdx: where does the skin come from?. Sample code below.
Skin skin = new Skin(Gdx.files.internal("data/ui/uiskin.json"));
stage = new Stage();
btnlogin = new TextButton("click me",skin);
stage.addActor(btnlogin);
Render method
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
stage.draw();
Have you included the uiskin.atlas and uiskin.png in the same folder as your uiskin.json file? If not you will get an error.
The name of the atlas file must be the same as your json also, bar the file extension.
Hi all thank you for your comments. I sat up all night fumbling over this and now it is working somehow. I updated Libgdx and that has seemed to fix it somehow even though I was on the latest version.
Related
I have been trying to make the accessibility service dispatchGesture with a click and not a swipe.
This code is just swiping down on the screen, and not actually clicking on the x,y cords.
What I have tried.
Path clickPath = new Path();
clickPath.moveTo(Float.intBitsToFloat(x), Float.intBitsToFloat(y));
GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(clickPath, 0, 1));
dispatchGesture(gestureBuilder.build(), null, null);
I have also tried replaced the clickPath.moveTo to add clickPath.addCircle, and clickPath.addRect, But both of those just crash the application.
I know this question was a few months ago, but from what I've seen, your duration is too short. I wasn't able to get touch events to register with a duration of less than 50ms. I also passed a custom handler:
val handler = Handler(Looper.myLooper()!!)
It's possible that one or both of these could be the source of the reason it wasn't working for you. In general, you seem to be doing the same thing that I am, and I'm having some success with it.
I am trying to change photos in android studio by clicking on my button.
When I put code for changing the photo in my MainActivity.java I keep getting this type of error messages and it says :
Cannot resolve symbol "image"
image.setImageResource(R.drawable.xxx);
I am watching Udemy course for android development and I have done everything same like the professor on that video.
I have tried to restart android studio.
I have tried to make new project.
I have tried to clear invalidate caches and restart.
public void changeImage(View view)
{
ImageView bitcoin = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
}
I hope there is actual error with android studio,because code is clone of the video that I am watching.
You are binding your layout's ImageView in Java file with bitcoin variable and you are trying to set an image on an unknown variable 'image'(maybe it's not defined in the class). So you have to set as below.
ImageView bitcoin = findViewById(R.id.bitcoin);
bitcoin.setImageResource(R.drawable.xxx);
Set Your Code Like this
ImageView image = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
change your this line
image.setImageResource(R.drawable.xxx)
to this one:
bitcoin.setImageResource(R.drawable.xxx)
For some reason on the project I am working on in Android Studio the XML graphic editor has stopped showing me the picture of the screen layout. The app itself works fine and the layout woks fine on my device, but I don't have a picture of it on my computer screen in the editor.
The editor shows a error Rendering Problem - Exception raised during rendering
in the details it shows me a stack trace of a java.lang.NullPointerException, and it tip is to try and refresh the layout, but that doesn't work. I tried to refresh, to rebuild, and every other kind of refresh possible but nothing works. I checked other projects that I had worked on and thy where OK the graphics was fine, but not on my current project. So I need help finding the problem.
java.lang.NullPointerException
at android.graphics.BidiRenderer.getScriptFont(BidiRenderer.java:290)
at android.graphics.BidiRenderer.getScriptRuns(BidiRenderer.java:280)
at android.graphics.BidiRenderer.renderText(BidiRenderer.java:133)
at android.graphics.BidiRenderer.renderText(BidiRenderer.java:108)
at android.graphics.Paint_Delegate.measureText(Paint_Delegate.java:1310)
at android.graphics.Paint_Delegate.nGetTextAdvances(Paint_Delegate.java:972)
at android.graphics.Paint_Delegate.nGetRunAdvance(Paint_Delegate.java:1147)
at android.graphics.Paint.nGetRunAdvance(Paint.java)
at android.graphics.Paint.getRunAdvance(Paint.java:2729)
at android.text.TextLine.getRunAdvance(TextLine.java:729)
at android.text.TextLine.handleText(TextLine.java:778)
at android.text.TextLine.handleRun(TextLine.java:1018)
at android.text.TextLine.measureRun(TextLine.java:417)
at android.text.TextLine.measure(TextLine.java:310)
at android.text.TextLine.metrics(TextLine.java:281)
at android.text.Layout.measurePara(Layout.java:1966)
at android.text.Layout.getDesiredWidthWithLimit(Layout.java:186)
at android.widget.TextView.onMeasure(TextView.java:8168)
at android.view.View.measure(View.java:22035)
at android.widget.Toolbar.measureChildCollapseMargins(Toolbar.java:1548)
at android.widget.Toolbar.onMeasure(Toolbar.java:1662)
at android.view.View.measure(View.java:22035)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6622)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.widget.ActionBarContainer.onMeasure(ActionBarContainer.java:291)
at android.view.View.measure(View.java:22035)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6622)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:378)
at android.view.View.measure(View.java:22035)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:22035)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:590)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:343)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
In xml toolbar you can find refresh button, so that it will notify if it is any warnings in your xml.
If your used custom layout then rendering problem shown..
Let see the error log:
java.lang.NullPointerException
at android.graphics.BidiRenderer.getScriptFont(BidiRenderer.java:290)
I think you need to clone project like library module, then add #Nullable to this method to avoid exception here.
if view is rendering fine at run time but you are only having problem showing preview in layout editor then you should use isInEditMode() method and should not do unsupported operations if view is being rendered in layout editor
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!isInEditMode()) {
//custom logic
}
}
I am sorry to say that your answers did not help me at all. The solution for me was to go back to one of my backup visions, when the edit display still worked, and start from there. I found that when changing too many parameters in the Theme Editor (three) cause a bug that stops the XML editor from showing the layout picture.
One of the things I learned many years ago when first started to learn programming was that there is no such thing as to many backups, this is one of those time when I am glad I listed to my teachers.
I've been running into a problem lately where I try to se a JMenuItems icon which when I define and point to the icon the application it self don't start/show.
I started looking for errors, but there where none; started looking for write occurencies, which typically pretty much does appear when I add the icon and after that as pointed above the application doesn't start/show.
When the icon is set but commented:
Code
mntmMaximize = new JMenuItem();
mntmMaximize.setText("Maximize Window");
mntmMaximize.setActionCommand("maximize");
mntmMaximize.addActionListener(this);
mntmMaximize.setMnemonic(KeyEvent.VK_PLUS);
mntmMaximize.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, ActionEvent.CTRL_MASK));
// mntmMaximize.setIcon(new ImageIcon(Vision.class.getResource("xray/fullscreen16x.png")));
mnWindow.add(mntmMaximize);<br>
Picture:
Screen Shot Of Visible Application
After the icon is set and trying to execute application:
Code:
mntmMaximize = new JMenuItem();
mntmMaximize.setText("Maximize Window");
mntmMaximize.setActionCommand("maximize");
mntmMaximize.addActionListener(this);
mntmMaximize.setMnemonic(KeyEvent.VK_PLUS);
mntmMaximize.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, ActionEvent.CTRL_MASK));
mntmMaximize.setIcon(new ImageIcon(Vision.class.getResource("xray/fullscreen16x.png")));
mnWindow.add(mntmMaximize);<br>
Picture:
The window not created and application terminated
Note that when the window is not created in this picture the application is therefor terminated.
Please try to answer nice, and if you need the whole source file it is possible.
Edit:
Also if needed i can make a video where i show when i start the application when the icon is set but not commented.
getResource uses the relative path with respect to the package (folder), like in
Vision.class.getResource("fullscreen16x.png")
or absolute like in:
Vision.class.getResource("/xray/fullscreen16x.png")
There are a few questions here on SO about capturing screenshots of an android application. However, I haven't found a solid solution on how to take a screenshot programatically using the android SDK or any other method.
So I thought I would ask this question again in the hopes that I can find a good solution, hopefully one that will allow capturing full length images that I can save to the SD card or somewhere similar.
I appreicate any help
This is not possible directly on the device/emulator, unless it is rooted.
to honest all I need it for is the emulator as this is for a testing application on a PC
This sounds like a job for monkeyrunner.
monkeyrunner tool can do the job for you with bit of adb command, [python script]
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
//waits for connection
device = MonkeyRunner.waitForConnection()
//take the current snapshot
device.takeSnapshot()
//stores the current snapshot in current dir in pc
device.writeToFile('current.png')\
//copy it to the sd card of device
os.subprocess.call('adb push current.png /sdcard/android/com.test.myapp/current.png')
Note: call this jython script file
monkeyrunner.bat <file name>
You will most likely not be happy with this answer, but the only ones that I have seen involve using native code, or executing native commands.
Edit:
I hadn't seen this one before. Have you tried it?:
http://code.google.com/p/android-screenshot-library/
Edit2: Checked that library, and it also is a bad solution. Requires that you start the service from a pc. So my initial answer still holds :)
Edit3: You should be able to save a view as an image by doing something similar to this. You might need to tweek it a bit so that you get the width/height of the view. (I'm inflating layouts, and specify the width/height when I layout the code)
View content = getView();
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
File file = new File(pathAndFilename);
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
You can look at http://codaset.com/jens-riboe/droidatscreen/wiki (with a write up at http://blog.ribomation.com/2010/01/droidscreen/): this is a Java library that uses adb to capture a screen shots. I've been able to (with a lot of elbow grease) modify the source to let me automatically capture a timed series of screen shots (which I use for demo videos).
You can see the class structure at http://pastebin.com/hX5rQsSR
EDIT: You'd invoke it (after bundling all the requirements) like this:
java -cp DroidScreen.jar --adb "" --device "" --prefix "" --interval