我收到此错误:
java.lang.RuntimeException:无法恢复活动
java.lang.RuntimeException:无法生成本机字体
我发布了下面的相关代码并指出错误行。
堆栈跟踪:
01-27 06:57:39.872: E/AndroidRuntime(1791): FATAL EXCEPTION: main
01-27 06:57:39.872: E/AndroidRuntime(1791): Process: com.qrme.quranmadeeasy, PID: 1791
01-27 06:57:39.872: E/AndroidRuntime(1791): java.lang.RuntimeException: Unable to resume activity {com.qrme.quranmadeeasy/com.qrme.quranmadeeasy.SettingsActivity}: java.lang.RuntimeException: native typeface cannot be made
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2774)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2803)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2238)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.ActivityThread.access$800(ActivityThread.java:135)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.os.Handler.dispatchMessage(Handler.java:102)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.os.Looper.loop(Looper.java:136)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.ActivityThread.main(ActivityThread.java:5001)
01-27 06:57:39.872: E/AndroidRuntime(1791): at java.lang.reflect.Method.invokeNative(Native Method)
01-27 06:57:39.872: E/AndroidRuntime(1791): at java.lang.reflect.Method.invoke(Method.java:515)
01-27 06:57:39.872: E/AndroidRuntime(1791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
01-27 06:57:39.872: E/AndroidRuntime(1791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
01-27 06:57:39.872: E/AndroidRuntime(1791): at dalvik.system.NativeStart.main(Native Method)
01-27 06:57:39.872: E/AndroidRuntime(1791): Caused by: java.lang.RuntimeException: native typeface cannot be made
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.graphics.Typeface.<init>(Typeface.java:175)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.graphics.Typeface.createFromAsset(Typeface.java:149)
01-27 06:57:39.872: E/AndroidRuntime(1791): at com.qrme.quranmadeeasy.SettingsActivity.initialize(SettingsActivity.java:118)
01-27 06:57:39.872: E/AndroidRuntime(1791): at com.qrme.quranmadeeasy.SettingsActivity.onResume(SettingsActivity.java:104)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.Activity.performResume(Activity.java:5310)
01-27 06:57:39.872: E/AndroidRuntime(1791): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2764)
01-27 06:57:39.872: E/AndroidRuntime(1791): ... 12 more
SettingsActivity.java:
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
initialize(); -->104th line
onclick();
}
public void initialize() {
txtGeneral=(TextView)findViewById(R.id.textviewGeneral);
txtplay=(TextView)findViewById(R.id.textviewContinuousPlay);
txtplatdes=(TextView)findViewById(R.id.textviewContinousplay_des);
txtrepeat=(TextView)findViewById(R.id.textviewRepeat);
txtrepeatdes=(TextView)findViewById(R.id.textviewCount_des);
txtlanguage=(TextView)findViewById(R.id.textviewLanguage);
txtlanguagedes=(TextView)findViewById(R.id.textviewLanguage_des);
Typeface type=Typeface.createFromAsset(getAssets(), "UthmanicHafs.ttf"); --->118th line
txtplatdes.setTypeface(type);
txtrepeatdes.setTypeface(type);
txtlanguagedes.setTypeface(type);
type=Typeface.createFromAsset(getAssets(), "UthmanicHafs.ttf");
txtGeneral.setTypeface(type);
txtplay.setTypeface(type);
txtrepeat.setTypeface(type);
txtlanguage.setTypeface(type);
}
}
答案 0 :(得分:2)
试试这种方式
Typeface type=Typeface.createFromAsset(getBaseContext().getAssets(), "UthmanicHaf.ttf");
您还可以使用Asset
getBaseContext().getAssets()