I don't know if this is a Java problem or Android's one. But recently I have updated everything concerning my Android development setup.
So I upgraded
Java to 1.7_40 64 bit (i have 1.7_25 32 bit also installed),
Android studio to 0.2.10,
SDK tools to version 22.2.1,
SDK platform tools to version 18.0.1,
Gradle 1.7
And my android app started to behave very oddly. Before this update of my tools this line of code worked perfectly just like expected:
Category.getNew(1,"СЕНДВИЧАРА")
Now, on the other side of the get new function
public static Category getNew(int id, String name){
Category result = new Category();
result.setId(id);
result.setName(name);
return result;
}
for the name parameter I get this string СЕÐ�ДВИЧÐ�Ð Ð� which is not what I expected, I want my СЕНДВИЧАРА back, this string is passed along to the UI.
I can't let that cryptic string to be displayed on on the UI.
Please help.
Ok guys I found the solution by myself. And I'll post the answer here for future reference.
Apparently the cause of my problem was in Gradle. This is the first time I've been using it, by suggestion of Android Studio.
I have noticed that Gradle isn't very good in reporting problems during the building of the application, it displays them at random. At one moment while building the app I noticed this error:
Gradle: error: unmappable character for encoding Cp1252
This error looks like it was the cause of my problem. Quick google search and I bump into this article: Get rid of “unmappable character for encoding Cp1252″ once and for all which in summary says to add new Environment Variable named JAVA_TOOL_OPTIONS with value of -Dfile.encoding=UTF8 this way Java would always use UTF-8 as default encoding.
Related
Hello!
The goal I have is pretty simple: I want to create an executable .jar file which should be able to bring up a form (made using swing) and write the put-in information into a well structurized plain text file. Due to portability/mobility reasons I will have to run this on an Android phone.
Since Android unfortunately doesn't have native Java support and I am unable to code a real Android application myself, I tried to use a Java emulator. Unfortunately, it appears that a working Java Emulator is hard to find to begin with. JBED instantly crashes on my Medion X701. Netmite's Website, which also seems to offer a .jar to .apk converter, appears to be down. JBlend seems to have installed properly, but I do not know how to work with the program now that it presents me nothing but an empty screen with the caption "0 Java ME Application(s)". On the web, I could not find a proper manual. PhoneME's official website was Java.net, which is no longer active. But during my research, I could find an older Version of PhoneME which seems to be running well.
As a test, I created a simple jar file that shows a maximized JFrame. Unfortunately, it isn't able to run my simple executable Jar file on my phone. The main reason for that should be the aforementioned error, which implies that the interpreter there is probably Java version 1.7, since PhoneME's last release was in 2015. There are more error messages referring to an "unknown source", which I believe originate from the first error. I tried to recompile my jar file using Eclipse, by setting the Compiler compliance level to 1.7 and choosing the jre 1.7 before exporting my project. Unfortunately, this didn't change the error messages I got on PhoneME!
As my last attempt, I created a Startup.class file which does the very same thing as my jar file.
import javax.swing.*;
public class Startup {
public static void main(String[] args) {
JFrame fishForm = new JFrame("Questionnaire");
fishForm.setExtendedState(JFrame.MAXIMIZED_BOTH);
fishForm.setVisible(true);
}
}
I compiled it using the command prompt in order to make sure that it is indeed using java 1.7 as the target. This .class file, which ran fine on my computer, leads me into a different error: "Main class name missing.", followed by multiple lines of usage explaination. The command line PhoneME presents doesn't seem to allow me to post command operations myself, as pressing Enter on the virtual keyboard does nothing.
My Questions
Is it even possible to run a Java application on Android which relies on the GUI libraries of Swing, or am I wasting my time?
Is there a different, up-to-date Java emulator for Android which I could use? Or is there a working jar2apk converter somewhere out there?
If not, then there's probably a reason why Java emulators ceased to exist. Is there a much simpler solution for my initial problem which I am missing?
I'll await your ideas eagerly!
I'm working with a struts 2.3.4.1 and am using the struts2-jasperreports-plugin to display a pre-compiled report. Fonts have been giving me issues, which I found was supposedly fixed in Jasperreports 6 (specifically issues with Calibri). Because I'm on a legacy system running java 6, the last version I can use is 6.2.2. But when I try to display my report, I get java.lang.NoSuchMethodError: net.sf.jasperreports.engine.util.JRLoader.loadObject(Ljava/lang/String;)Ljava/lang/Object;
org.apache.struts2.views.jasperreports.JasperReportsResult.doExecute(JasperReportsResult.java:323), which seems to be a function called by the struts2-jasperreports-plugin that doesn't exist in jasperreports 6+. I've been looking around, but cannot find out if/how to change this behavior and am beginning to think that I need to update the version of my plugin.
Is there a way to change the function called by the plugin, or am I going to need to change the version of struts to get the behavior I expect? Is it possible to write an adapter for a plugin?
After some more troubleshooting, I found https://stackoverflow.com/a/37864625/892327 in which an adapter was made using existing code, which I got from https://web.archive.org/web/20180523111530/http://grepcode.com/file/repo1.maven.org/maven2/net.sf.jasperreports/jasperreports/6.1.0/net/sf/jasperreports/engine/util/JRLoader.java/, and added the missing loadObject(String fileName) function as an adapter for the loadFromFile(String fileName). Which cleared the NoSuchMethodError.
However, the original issue java.lang.ArrayIndexOutOfBoundsException: 0 sun.font.ExtendedTextSourceLabel.createCharinfo(ExtendedTextSourceLabel.java:592 returned, which was "fixed" by changing the version of Java I was running, found at Error generating JasperReport in Development mode.
Because I'm working with a legacy system that runs on Java 6, I've given up since the original issue is JRE based and not a bad Jasperreports library or struts plugin.
I've been working for some time on my current project with Java (1.8.0_31) in IntelliJ IDEA (15.0.1 for Windows x64), where I use some text lines with special characters (e.g. "ó"). It has been working so far with no issue, but today it won't.
To put it short, I have a code line like this:
System.out.println("ó");
which has been outputting this (expected):
ó
Today, the output with the same source code is (unexpected):
ó
Code files are encoded in UTF-8 and the editor is setup accordingly. AFAIK, I've changed nothing.
I've created a brand new project to test this and it worked properly, so it may be something related specifically with my project.
Any idea about how to solve this?
I'm trying to use JRuby in projects created in Android studio. I have built the latest (as of 9/10/2014) JRuby, and have completely updated Android Studio. I have a working app that I can use to test. I have a copy of jruby.jar in the MyApp/app/libs directory. Once there I right-clicked on jruby.jar and selected "Add as Library", which presumably did something (though what I am not certain), and have added the line "compile files('libs/jruby.jar')" to the build.gradle that is in MyApp/app/.
In one of the class files I have "import org.jruby.embed.ScriptingContainer;", which Android Studio says is fine (if I hadn't added jruby.jar as a library I couldn't include this without an error). Then in one of the working methods I say "ScriptingContainer container = new ScriptingContainer();". When I run this method the app will crash. I won't try to include the whole error message, but the important part seems to be:
Caused by: java.lang.ExceptionInInitializerError
at org.jruby.embed.internal.AbstractLocalContextProvider.<init>(AbstractLocalContextProvider.java:42)
at org.jruby.embed.internal.SingletonLocalContextProvider.<init>(SingletonLocalContextProvider.java:88)
at org.jruby.embed.ScriptingContainer.getProviderInstance(ScriptingContainer.java:248)
at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:228)
at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:185)
and
Caused by: java.lang.RuntimeException: unsupported Java version: 0.9
at org.jruby.RubyInstanceConfig.initGlobalJavaVersion(RubyInstanceConfig.java:1858)
at org.jruby.RubyInstanceConfig.<clinit>(RubyInstanceConfig.java:1608)
At least, those are the parts that make sense to me. I hav no idea why I would get the error "java.lang.RuntimeException: unsupported Java version: 0.9", since I am using 1.8.0_20. The rest of the errors I cannot follow. When I click on any of the files giving me an error (say AbstractLocalContextProvider.java:42) Android Studio will show the file but also say "Sources not found". That could be the problem, but I don't know why it can't find the sources.
Thanks for any help,
Brian
Uwe Kubosch (#donv70) was able to tell me the solution to this via Twitter, so credit to him, but I wanted to post the solution here in case anyone else needs it.
It was Java version that was causing the problem. In Ruboto the problem is solved here: https://github.com/ruboto/ruboto/blob/master/assets/src/org/ruboto/JRubyAdapter.java#L137
and for use in Android Studio it is necessary only to include the line: System.setProperty("jruby.bytecode.version", "1.6");
The number of course can be 1.6, 1.7, or 1.8, depending on your version of Java.
Looks like an interoperability problem between JRuby and the Dalvik VM (don't forget that you're running against Dalvik, not the Java VM).
There's a bug report at http://jira.codehaus.org/browse/JRUBY-5774 that may lead you in the right direction.
It's kind of old, and is marked 'fixed', but maybe it'll provide some clues?
I downloaded the Android Development Tools SDK which include Eclipse and SDK.
The Eclipse IDE crashes when i try to write a line that include "R.", like:
EditTex Password= (EditText)FindViewById(R.id.pass)
It won't show the error, it just crashes.
You should use: R.id.yourControlId
In the autogenerated class R are you're ID's stored for multiple things like your resources; images/strings etc..
To get your images from your drawable folder: R.drawable.image
To get your string from your strings.xml: R.string.hello_world
So you should do this instead: EditText Password = (EditText)FindViewById(R.id.pass);
I have the problem, too, seems to be a bug in the openjdk in connection with the ADT. This has nothing to do with the code you write in eclipse. It can be triggered in more ways. And it seems that it is no problem with eclipse itself, because it is no Java-Exception but the javavm that segfaults. Looking for a workaround myself atm.
Edit: May be this bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=404776
Edit2: And this here may be a workaround: https://bugs.eclipse.org/bugs/show_bug.cgi?id=404776#c7