Error: Content not allowed in prolog - android

I know this question has been asked before but I can't find the solution in previous solutions. The error points to the file Game.java. The code for that file is very simple:
package framework;
public interface Game {
public Input getInput();
public FileIO getFileIO();
public Graphics getGraphics();
public Audio getAudio();
public void setScreen(Screen screen);
public Screen getCurrentScreen();
public Screen getStartScreen();
}
I have used the file several times before without problems. I have updated the manifest file. I have updated Android Studio and all the plug-ins (in fact I have re-installed them). The project was created using Android Studio instead of being imported. I have tried cleaning the project. I just can't see what the problem is. Can you please help?
The location of the problem is
G:\AndroidStudioProjects\Marvelous2\app\src\main\res\framework\Game.java

You shouldn't place Java files under the res folder, those belong under src/main/java. Correct directory for Game.java is src/main/java/framework/Game.java.

Related

Error searching for native library (libjnidispatch.so) using JNA to access .so file

Please note that this question is a follow-up question to another question I asked here some time ago.
What would I like to achieve?
I would like to use JNA (version 4.5.2 with Android Studio) to achieve the following:
First I would like to get a list of all callable functions from a given .so file.
Once I have this list, I would like to call a specific function
What did I do so far?
So far, the code of the file "MainActivita.java" of my test app looks as follows:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String MyLibraryString = MyLibrary.Instance.toString();
}
public interface MyLibrary extends Library
{
MyLibrary Instance = (MyLibrary ) Native.loadLibrary("nameOfMyLibraryWithoutSoExtension", MyLibrary.class);
}
}
What issues am I facing?
I used to get an error message that my library is not found on my Android device but after putting it in the "jniLibs" subfolder my app seems to be able to detect it. Unfortunately, I now get the error message
java.lang.UnsatisfiedLinkError: Native library
(com/sun/jna/android-aarch64/libjnidispatch.so) not found in resource
path (.)
whenever I try to start the app on my device. I already tried to extract the file "libjnidispatch.so" from the JNA.jar file and put it in its respective subfolders (as described here) but that doesn't work.
The folder structure of the subfolder "app\src\main\jniLibs" of my app looks as follows:
app\src\main\jniLibs\arm64-v8a\myLibrary.so
...
app\src\main\jniLibs\arm64-v8a\libjnidispatch.so
app\src\main\jniLibs\armeabi\myLibrary.so
...
app\src\main\jniLibs\armeabi\libjnidispatch.so
app\src\main\jniLibs\armeabi-v7a\myLibrary.so
...
app\src\main\jniLibs\armeabi-v7a\libjnidispatch.so
app\src\main\jniLibs\mips\myLibrary.so
...
app\src\main\jniLibs\mips\libjnidispatch.so
app\src\main\jniLibs\mips64\myLibrary.so
...
app\src\main\jniLibs\mips64\libjnidispatch.so
app\src\main\jniLibs\x86\myLibrary.so
...
app\src\main\jniLibs\x86\libjnidispatch.so
app\src\main\jniLibs\x86_64\myLibrary.so
...
app\src\main\jniLibs\x86_64\libjnidispatch.so
Any help would be highly appreciated.

SDL keeps failing to find font on Android

When I attempt to deploy my app using Eclipse it throws FileNotFoundException on my font, which I've now copied to both the assets/src and assets directory to be doubly sure.
I had this problem before, after succesfully integrating SDL_ttf into my Visual C++ build of the same app and transferring across to Eclipse for Android. Now I'm facing it again I thought I better write about it. The SDL_ttf source comes with a freetype folder already in place and referenced by android as external/freetype-2.4.12. DinoMage states I need to download this separately although he refers to freetype-2.4.11 being the latest. That's the only obvious difference from my VC build, apart from minor compiler intolerances.
I've got it working a bit now. I can sign the app (unsigned didn't work), disable USB debugging, and it will load the font and display a menu. From there it breaks, again, so I can't see how I'm supposed to debug it further. I'm sure I'll fix it somehow. But I'll also forget the obscura if I don't post here.
I don't know much about using the debugger with Android, but I can make suggestions otherwise.
Is your assets path really named "assetts"? If possible, I'm not sure how one would get Android and SDL to look there instead of "assets".
SDL and it's friend libs like SDL_ttf search for files local to the assets directory first and then search relative to the root directory. So I would expect that your "res/stubbornFont.ttf" will never load because it is in the resources "res" directory and SDL_ttf will not look there.
Maybe you can specify it relative to assets/, like "../res/stubbornFont.ttf", but I haven't tested that. It would work if you put the font in assets/ and loaded it as "stubbornFont.ttf".
I've think I've got closure on this.
It is possible to debug the app. By continuing it will trap several times trying to load one font. I think it stops eventually, I'm not sure. I've stepped through it from where it lands me at the throw stage. However single stepping from there begins from the synchronized statement, sorry it's Java but from my quick reference to What does 'synchronized' mean? I think this is a race condition
public final AssetFileDescriptor openFd(String fileName)
throws IOException {
synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
ParcelFileDescriptor pfd = openAssetFd(fileName, mOffsets);
if (pfd != null) {
return new AssetFileDescriptor(pfd, mOffsets[0], mOffsets[1]);
}
}
throw new FileNotFoundException("Asset file: " + fileName);//DEBUGGER traps here
}
You might be there all day single stepping that! It appears to perform all steps required of it and finally I land in:
public static ReadableByteChannel newChannel(InputStream inputStream) {
return new InputStreamChannel(inputStream);
}
No, not finally, lastly, there is
public static Context getContext() {
return mSingleton;
}
In the SDLActivity I extend.
That has a bunch of members I don't want to know about:
Luckily I discovered I can selectively "Disconnect" using a button in eclipse two along from debug/run. It has no keyboard shortcut and I'm not sure why but it will reconnect when I next trigger an exception. This is debugging as I know and love it in Android and Eclipse, still probably easier than GDB.
For arguments sake I've even replaced:
//TTF_Font *gFont = TTF_OpenFont( "res/stubbornFont.ttf", 160 );
with
TTF_Font *font=TTF_OpenFontRW(SDL_RWFromFile("res/stubbornFont.ttf", "rb"), 1, 160);//Same difference
UPDATE/EDIT
Here is the solution I was really looking for,
turning off uncaught exceptions in eclipse, it really is just that, Window->Preferences->Java->Debug and it's the very first box at the top for me.

Android java.lang.VerifyError with exp4j Libraries

I tried to make my own small calculator, but I don't want to make all the business logic by myself. So I tried to use the javax.script since I heard that the javax.script needs a real JVM and is a JavaScriptParser. Then, I searched for other libraries with the functions I needed and found the project "exp4j". First, I made a small normal Java Project with JDK 1.7, and yes, it works with the source code:
public static void main(String[] args) throws UnknownFunctionException, UnparsableExpressionException {
ExpressionBuilder builder=new ExpressionBuilder("34*2");
Calculable calc=builder.build();
System.out.println(calc.calculate());
}
Then, I tried the same code in my model (MVC Pattern) of my calculator:
public void berechnen() throws UnknownFunctionException, UnparsableExpressionException {
ExpressionBuilder builder=new ExpressionBuilder("34*2");
Calculable calc=builder.build();
setErgebnis(calc.calculate());
}
But every time I got the same exception:
"AndroidRuntime(630): java.lang.VerifyError",
after I started the app. I can't click on the button that runs the method berechnen() because the app crashes after I start it.
I'm confused why my program doesn't work. When I delete all imports of exp4j and delete the source for the calculation, my calculator works fine.
My only idea is that the exp4j libaries is using a class or method that does not exist in Android.
Thank you.
You may have include jars twice, check once in libs folder and libraries in properties, I have faced same in the past What you need to do is to
Remove that in the libraries and paste freshly in your res/lib folder of android application project and then clear your project

Eclipse duplicate Android code error

I'm using Eclipse Indigo to develop Android application. The problem I'm experiencing is that some given error messages are duplicated many times, preventing the code to be compiled even when the errors are fixed. For example, I wrote:
private OnClickListener foo = new OnClickListener()
{
#Override
public void onClick( View v )
{
// ...
}
}
I was reported "Syntax error, insert ";" to complete FieldDeclaration" 7 times. I fixed it and 6 error messages remained.
I closed Eclipse then restarted it, nothing changed. I guess it is a file to delete or something like this. Any idea?
Thanks!
Here is how I fixed the problem, for those who may experience it someday.
1) I copied all the faulty (or reported as faulty but not really faulty) code to a text editor.
2) I deleted it from the java file and saved it. The errors disappeared.
3) I pasted back the code to the java file then saved it. The errors did not re-appear.
That's it.

Android/PhoneGap debugging: app not updated

I'm trying to use PhoneGap with Android. In the Sample that I run the main app opens an html file:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
Now if I change something in the html page, Android always shows the previous content.
Is it possible that the output files (resources in that case) are not updated?
Also if I change the name of the html file in /assets/newName.html and into .loadUrl nothing changes.
Thank you, F.
I'm determined to find a proper answer to this, at the moment changes in the assets dir do not trigger a rebuild.
At the moment I'm slapping a new line in the Activity.java code to force a rebild/deploy..
Will update once I've looked for a real solution.
I see this sometimes when I add a data file to a project in eclipse.
If you think you pkg isnt being updated (re-built) then just rebuild it manually. If your using eclipse just do project->clean and select the project you want to clean. it'll rebuild automatically and include anything that was missed out.
OK Guys found.
The tutorial in the wiki.phonegap.com is obsolete.
Samples instead are updated!
Many thanks.

Categories

Resources