I am following a youtube tutorial on how to make an android (probably not but I can hope for compatability) and iOS game using LibGDX and I have encountered a problem accessing a .tmx file from my res folder.
tileMap = new TmxMapLoader().load("res/level1.tmx");
using the above code I figured that the application would find my .tmx file in my res folder but I must be giving it incorrect information on how to find a file I have open in another tab. here is a screenshot of the search method called by hitting shift twice. http://imgur.com/PYd9Y5T
I see the file in the search method, but no matter what I seem to type in I cannot find level1.tmx
01-24 20:14:01.717 10013-10040/com.mac.elevator.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 60898
Process: com.mac.elevator.android, PID: 10013
com.badlogic.gdx.utils.SerializationException: Error parsing file: res/level1.tmx
at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:83)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:92)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:80)
at com.mac.elevator.com.mac.elevator.states.Play.<init>(Play.java:91)
at com.mac.elevator.handlers.GameStateManager.getState(GameStateManager.java:35)
at com.mac.elevator.handlers.GameStateManager.pushState(GameStateManager.java:45)
at com.mac.elevator.handlers.GameStateManager.<init>(GameStateManager.java:22)
at com.mac.elevator.Game.create(Game.java:46)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1521)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1249)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: res/level1.tmx (Internal)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
at com.badlogic.gdx.files.FileHandle.reader(FileHandle.java:163)
at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:81)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:92)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:80)
at com.mac.elevator.com.mac.elevator.states.Play.<init>(Play.java:91)
at com.mac.elevator.handlers.GameStateManager.getState(GameStateManager.java:35)
at com.mac.elevator.handlers.GameStateManager.pushState(GameStateManager.java:45)
at com.mac.elevator.handlers.GameStateManager.<init>(GameStateManager.java:22)
at com.mac.elevator.Game.create(Game.java:46)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1521)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1249)
Caused by: java.io.FileNotFoundException: res/level1.tmx
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
test this, copy the asset of your game, go to the folder of Android project, because that is how it works, LibGDX, is that the wiki LibGDX, talk about this but I do not remember where, try to put the file .tmx inside folder:
AndroidProyect -> asset -> maps -> yourmap.tmx.
and try to call it:
tileMap = new TmxMapLoader().load("maps/level1.tmx");
in your case, the, resources should go in the Asset Android project folder. While our code will be in the project completion "Core".
Related
I'm trying to build an app for my store.
downloaded the sample app from github (mobile-buy-sdk-android)
but when I try to run it it gives this error and crashes:
FATAL EXCEPTION: main
Process: com.shopify.sample, PID: 4157
java.lang.RuntimeException: Unable to create application com.shopify.sample.application.SampleApplication: java.lang.IllegalArgumentException:
Add your shop credentials to a shop.properties file in the main app folder (e.g. 'app/shop.properties'). Include these keys:
SHOP_DOMAIN=.myshopify.com
API_KEY=0123456789abcdefghijklmnopqrstuvw
You must populate the 'APP_ID' entry in app/shop.properties
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4559)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalArgumentException:
Add your shop credentials to a shop.properties file in the main app folder (e.g. 'app/shop.properties'). Include these keys:
SHOP_DOMAIN=.myshopify.com
API_KEY=0123456789abcdefghijklmnopqrstuvw
You must populate the 'APP_ID' entry in app/shop.properties
at com.shopify.sample.application.SampleApplication.initializeBuyClient(SampleApplication.java:125)
at com.shopify.sample.application.SampleApplication.onCreate(SampleApplication.java:109)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4556)
Please, read carefully debug log. The answer is there:
Add your shop credentials to a shop.properties file in the main app
folder (e.g. 'app/shop.properties'). Include these keys:
SHOP_DOMAIN=.myshopify.com API_KEY=0123456789abcdefghijklmnopqrstuvw
You must populate the 'APP_ID' entry in app/shop.properties at
Their sample app comment is slightly out of date. The location you need to put the shop.properties file is:
/MobileBuy/sample/shop.properties
You need to put the API key / domain in
SHOP_DOMAIN=YOURSHOP.myshopify.com
API_KEY=<your-api-key>
If you are still having problems, then just modify the SampleApplication.java and change the lines t
String shopUrl = BuildConfig.SHOP_DOMAIN;
String shopifyApiKey = BuildConfig.API_KEY;
I'm new to Android Studios and I am doing this OCR http://swlock.blogspot.com/2016/07/ocr-tesseract-2.html where the image convert to text but everytime I take an image app the will close and got this error. Anyone can guide me to fix this error? Thanks
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.datumdroid.android.ocr.simple, PID: 2425
java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_0-classes.dex"],nativeLibraryDirectories=[/data/app/com.datumdroid.android.ocr.simple-2/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libjpgt.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:972)
at java.lang.System.loadLibrary(System.java:1530)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44)
at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onPhotoTaken(SimpleAndroidOCRActivity.java:214)
at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onActivityResult(SimpleAndroidOCRActivity.java:138)
at android.app.Activity.dispatchActivityResult(Activity.java:6915)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Application terminated.
That means that the *.so files are not in your *.apk file. Follow the steps in this stackoverflow question/answer.
You can always go to Build > Analyze APK... to see if the *.so files are getting added. Obviously, if they are not in the APK, then there is no reason to attempt to run the app that needs the *.so files.
I'm trying to use Realm as a database for high scores in my app. However, when this line of code is called:
realmConfig = new RealmConfiguration.Builder(getActivity().getApplicationContext()).build();
in the Fragment where I'm trying to save the user's score, I get this:
FATAL EXCEPTION: main
Process: com.tommy.mastersproject, PID: 21387
Theme: themes:{com.android.settings=overlay:com.cyngn.hexo, default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/RealmConfiguration$Builder;
at com.tommy.mastersproject.fragments.MemoryRecallFragment.onCreate(MemoryRecallFragment.java:144)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1951)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
at android.support.v4.app.BackStackRecord.setLastIn(BackStackRecord.java:779)
at android.support.v4.app.BackStackRecord.calculateFragments(BackStackRecord.java:802)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:660)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1238)
at android.app.Activity.performStart(Activity.java:6268)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.RealmConfiguration$Builder" on path: DexPathList[[dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-support-annotations-23.4.0_d80f4a0fc2ae8e1f7cf76e4c536a48795da28487-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-library-2.4.0_e0d22a6e7ea9a4d2326a0c8c16bbc09d4d04442c-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-internal_impl-23.4.0_bd67bdb6ef0c094e8f4157e2567e8b30b9d0dd7f-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.jakewharton-butterknife-8.0.1_9246a0d023a2de89ba20a84f0fb1ecc6b733b004-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.code-troopers.betterpickers-library-3.0.0_f98f8b23c6650d93d8479a647f8f2162db8834e8-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.astuetz-pagerslidingtabstrip-1.0.1_474986b4f5d06e547dc72e3bf0988a95fa9d3973-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.android.support-support-vector-dr
I've also tried using
realm = Realm.getDefaultInstance();
but without any luck.
From a quick Google search, there have been similar complaints which were due to Realm's poor compatibility with the Android multidex and for not being up-to-date with Gradle, but I'm currently running Gradle 2.1.2.
I am also using Gradle 2.1.2 and Realm is working perfectly fine, problem could be with Instant Run, Did you try loading the project without Instant Run? If not disable it(In Android studio -> Preferences -> Build, Execution, Deployment -> Instant Run), clean the project and run it again.
If it does not work, share the actual code where you are creating RealmConfiguration and using Realm.
I am trying to create a game in libgdx, and I want to load a ttf font and draw some text in the screen but it does not work on my android device, I get Unfortunately, game has stopped. I am using Android Studio as the IDE.
It works on desktop.
This is how I load the font:
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));
I get the following error in logcat:
03-07 20:41:44.902 9759-9779/com.mygdx.game.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 5345
com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: font.ttf (Internal)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.g2d.freetype.FreeType$Library.newFace(FreeType.java:69)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.<init>(FreeTypeFontGenerator.java:106)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:42)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1513)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
Caused by: java.io.FileNotFoundException: font.ttf
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:315)
at android.content.res.AssetManager.open(AssetManager.java:289)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.g2d.freetype.FreeType$Library.newFace(FreeType.java:69)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.<init>(FreeTypeFontGenerator.java:106)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:42)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1513)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
This is where the file is:
This is my build.gradle file
Try:
... Gdx.files.internal("font.TTF"));
The Android filesystem is case sensitive.
Currently, I have an Android project, consists of 1 main project, and multiple library projects.
Just that recently, I realize that if there is same layout filename among main project and library project, bad thing can happen.
third-party-library-project
- res
- layout
- actionbar_custom_view_done_discard.xml
main-project
- res
- layout
- actionbar_custom_view_done_discard.xml
So, if in third-party-library-project, if you are having line of code in its activity,
final View customActionBarView = inflater.inflate(
R.layout.actionbar_custom_view_done_discard, null);
Error stack trace caused by layout file naming conflict
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.yccheok.jstock.gui/group.pals.android.lib.ui.lockpattern.LockPatternActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
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: android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at group.pals.android.lib.ui.lockpattern.LockPatternActivity.initActionBar(LockPatternActivity.java:356)
at group.pals.android.lib.ui.lockpattern.LockPatternActivity.onCreate(LockPatternActivity.java:347)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 25 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010137 a=-1}
at android.content.res.Resources.loadDrawable(Resources.java:1892)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.TextView.<init>(TextView.java:614)
at android.widget.TextView.<init>(TextView.java:442)
... 28 more
If I change the layout XML file in third-party-library-project to actionbar_custom_view_done_discard1.xml, the runtime error will gone.
This is not an issues, if the number of library projects is small. Conflict can be solved easily with simple renaming. However, when comes across huge number of library projects, what is a robust way, or strategy to overcome this problem?
Library projects need to ensure that their resource names will be distinctive and not collide with other library projects, such as by applying a prefix to those resource names.
Note that apparently the new Gradle-based build system supports resource subdirectories. I have not yet experimented with this, but if the subdirectory names form part of the resource ID, then putting your resources in a distinctive subdirectory would help to keep the resource IDs distinct (at least for non-values resources).
First I would suggest renaming your project resource file and not the 3rd party file in your first example since you may want to pull changes from the 3rd party library project again. Secondly I would suggest not using too many 3rd party library projects to begin with. From my experience the Android build system still has lots of hiccups with library projects. Things like BuildConfig.DEBUG do not work and I've had issues with library projects that contain jar file dependencies breaking the ability to run unit tests through Android instrumentation. There are tons of other bugs as well, most of them probably fairly obscure but enough of an issue that I don't suggest using library projects any more than absolutely necessary.