Welcome to my blog! If you've stumbled across this in your travels on the internet, please take a moment click on an ad - or two! You might see something you like, *and* it helps finance the blogosphere. Think of the children!
As I've been playing around with my app, I've come to realize that some of the characters are actually not actually Japanese. At first, this didn't bother me too much, but the more I work with it, the more annoying it's become. I've actually gone through the exercise of replacing it with a proper font before, but I thought it was too stylized. But, I definitely need to get the correct font in there, and that's what this post will be about.
Well, for some odd reason, I didn't blog about that. But, I had found a good set of Japanese fonts, and saved them in a folder. Here's the name of one of them: epgyobld.ttf. Let's google it.
Ah, here it is: http://www.ilovegkr.com/pages/fungames/typejap.html
It give examples of the fonts. Now, my wife likes epminbld.ttf, so I'll go with that one. I have a "fonts" folder set up in the "assets" folder of my project, so, I'm assuming I pop it into there. Ok, I think I just uncommented the code, so let's find it...
Here it is, in QuestionActivity:
private static final String CURRENT_FONT = "epminbld.ttf";
and:
private Typeface mTypeFace;
Here's another one:
mTypeFace = Typeface.createFromAsset(getAssets(), CURRENT_FONT);
And in setting up the listView:
ListView v = getListView();
int childCount = v.getChildCount();
for (int i = 0; i < childCount; i++) {
TextView c = (TextView) v.getChildAt(i);
c.setTypeface(mTypeFace);
mDisplayQuestion.setTypeface(mTypeFace);
}
mDisplayQuestion.setTypeface(mTypeFace);
Ok, that just about covers it. Lets she how she looks.
Errr...crash. It doesn't like that font:
E/AndroidRuntime(26647): java.lang.RuntimeException: Unable to resume activity {com.jlptquiz.app/com.jlptquiz.app.QuestionActivity}: java.lang.RuntimeException: native typeface cannot be made
E
Let's got back to the ones I know were working from last time:
// private static final String CURRENT_FONT = "epgyosho.ttf"; - too cursive
// private static final String CURRENT_FONT = "epgyobld.ttf"; - too cursive
// private static final String CURRENT_FONT = "epmarugo.ttf"; - readable, basic.
Ok, the epgyosho is too cursive. How about epgyobld? Is that the some, only in bold? Yeah.
Let's try epmarugo. Ok, it's definitely readable. I'll go with that, but I want to check out the rest.
Let's try epmgobld.ttf - that crashes the app
How about:
private static final String CURRENT_FONT = "epkgobld.ttf";
It's taking a while to load because of all the fonts. No, it looks like I'm getting a null pointer exception on the database. Why that, and now?
Let's take a look at the log.
/Database(28303): sqlite returned: error code = 14, msg = cannot open file at source line 25467
E/Database(28303): sqlite3_open_v2("nulljlpt", &handle, 1, NULL) failed
E/AndroidRuntime(28303): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jlptquiz.app/com.jlptquiz.app.StartActivity}: java.lang.NullPointerException
W/ApplicationContext(28303): Unable to create external cache directory
W/System.err(28303): java.io.IOException: No such file or directory
W/System.err(28303): at java.io.File.createNewFileImpl(Native Method)
W/System.err(28303): at java.io.File.createNewFile(File.java:1257)
W/System.err(28303): at com.jlptquiz.app.DataBaseHelper.copyDataBase(DataBaseHelper.java:175)
W/System.err(28303): java.io.FileNotFoundException: /null/data/.com.kanjisoft.jlpt/jlpt (No such file or directory)
Is it a problem with the SD card not being mounted?
I can get to it from adb.
Astro sees it.
Here's the code:
// Create the directory if it's not there
File dirs = new File(DownloadAudioData.getRootPath(this.myContext));
dirs.mkdirs();
// Create path to the just created empty db
String outFileName = DownloadAudioData.rootPathSingleton + DB_NAME;
// create the db file
File file = new File(outFileName);
try {
file.createNewFile();
That actually is kind of a funny name - aren't you supposed to get singletons from static method the checks for null or something?
What's the value..
public static String rootPathSingleton = null;
Oooh kay. Whatever is supposed to be initializing, apparently is happening as usual for some reason. Let's change the access to a method, like is should be. Actually, that should be in DatabaseHelper, not Download AudioData.
Ok, so, actually, for some reason, the getRootPath must have returned a null, but let's run it again just in case all my refactoring somehow makes a difference - although I don't see how.
Yep.
E/AndroidRuntime(29698): Caused by: java.lang.NullPointerException
E/AndroidRuntime(29698): at com.jlptquiz.app.DataBaseHelper.copyDataBase(DataBaseHelper.java:200)
Wait, what's this:
D/szipinf (29698): Initializing inflate state
W/System.err(29698): java.io.IOException: Read-only file system
W/System.err(29698): at java.io.File.createNewFileImpl(Native Method)
No, I think I just need to always grab the name through the method...
Ah, that's better. We're back to where we started.
E/AndroidRuntime(30160): FATAL EXCEPTION: main
E/AndroidRuntime(30160): java.lang.RuntimeException: Unable to resume activity {com.jlptquiz.app/com.jlptquiz.app.QuestionActivity}: java.lang.RuntimeException: native typeface cannot be made
E/AndroidRuntime(30160): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
E/
Ok, it's working, at least for one font - but we've got another problem. Although I'm setting the font in the list activity child views, they are coming up with the default font. Ouch.
Hmm. Let's see if I set them later on. Ok, I can get it to display in the answer. So, it's seems to be question of timing, I guess. I'll check this after dinner.
Well, it seems as if the problem is there is some kind of a lag between setting the listActivity with the array and it actually getting populated. Luckily, I have a countdown timer, and by the time it hits that, the children have been populated. So, I set the font from the tick on the countdown timer. That works. I'll clean it up tomorrow. Time to catch a movie!
No comments:
Post a Comment