是否可以使用像以下应用程序实例的getAssets:
public class MyApp extends Application
{
static private MyApp sInstance = null;
public static MyApp Instance()
{
if( sInstance == null )
{
sInstance = new MyApp();
}
return sInstance;
}
}
和功能使用:
*** AssetManager as = MyApp.Instance().getAssets();
Fonts.ARIAL = Typeface.createFromAsset(as, "Arial.ttf" );
清单: app_name是“MyApp”
getAssets函数调用返回NullPointerException( * 行)
我该如何解决?
很好地找到了答案: MyApp应该是这样的:
public class MyApplication extends Application {
private static MyApplication singleton;
public MyApplication getInstance(){
return singleton;
}
@Override
public void onCreate() {
super.onCreate();
singleton = this;
}
}
请看看里面: http://intridea.com/2011/5/24/how-to-use-application-object-of-android?blog=company