我正在我的应用程序中实现一个导航抽屉,我想更改字体。下面是我的 oncreate 方法,我在其中更改了导航抽屉的字体问题是当应用程序运行时它会立即崩溃,我无法弄清楚出了什么问题
代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navdrawer);
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
Home fragment = new Home();
fragmentTransaction.replace(R.id.llhome, fragment);
fragmentTransaction.commit();
Typeface tf = Typeface.createFromAsset(getAssets(),
"robotomed.ttf");
TextView tv = (TextView) findViewById(R.id.tvmenu);
tv.setTypeface(tf);
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles));
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
getActionBar().setTitle("Home");
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle("StayHealthy");
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
这是我的日志猫
06-22 21:44:21.562: E/AndroidRuntime(32042): FATAL EXCEPTION: main
06-22 21:44:21.562: E/AndroidRuntime(32042): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.OptimusApps.stayhealthy/com.OptimusApps.stayhealthy.MainActivity}: java.lang.NullPointerException
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.app.ActivityThread.access$600(ActivityThread.java:132)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.os.Looper.loop(Looper.java:137)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.app.ActivityThread.main(ActivityThread.java:4575)
06-22 21:44:21.562: E/AndroidRuntime(32042): at java.lang.reflect.Method.invokeNative(Native Method)
06-22 21:44:21.562: E/AndroidRuntime(32042): at java.lang.reflect.Method.invoke(Method.java:511)
06-22 21:44:21.562: E/AndroidRuntime(32042): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-22 21:44:21.562: E/AndroidRuntime(32042): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-22 21:44:21.562: E/AndroidRuntime(32042): at dalvik.system.NativeStart.main(Native Method)
06-22 21:44:21.562: E/AndroidRuntime(32042): Caused by: java.lang.NullPointerException
06-22 21:44:21.562: E/AndroidRuntime(32042): at com.OptimusApps.stayhealthy.MainActivity.onCreate(MainActivity.java:40)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.app.Activity.performCreate(Activity.java:4465)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-22 21:44:21.562: E/AndroidRuntime(32042): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
06-22 21:44:21.562: E/AndroidRuntime(32042): ... 11 more