我试图实现" Font Awesome"侮辱这个 source
我做了这些程序但是我的申请一旦关闭就关闭了。
这有什么问题?
我复制了values/attrs.xml
。并粘贴到我的申请表(内容没有变化)
我复制了values/strings.xml
的内容,并粘贴到我的应用中的strings.xml中。
我复制了layouts/icon.xml
和grid.xml
,并粘贴到我的应用中(内容无变化)
我复制了assets/icons.ttf
,并粘贴到了我的应用中(内容没有变化。它是一个字体文件)
我将src/com.example.IconView/IconView.java
复制到我的应用中(内容没有变化)
我将这些行添加到MainActivity.java
setContentView(R.layout.grid);
GridView grid = (GridView) findViewById(R.id.gridview);
grid.setAdapter(ArrayAdapter.createFromResource(this, R.array.icons, R.layout.icon));
然后我的当前代码看起来像这样
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.grid);
GridView grid = (GridView) findViewById(R.id.gridview);
grid.setAdapter(ArrayAdapter.createFromResource(this, R.array.icons, R.layout.icon));
mActionBar = getActionBar();
mActionBar.hide();
然而,我的应用程序一推出就会自动关闭。
我该如何解决这些问题,并使字体真棒?
logcat的
08-12 21:07:35.931: E/Trace(31646): error opening trace file: No such file or directory (2)
08-12 21:07:36.041: D/webcoreglue(31646): netstack: Memory Cache feature is ON
08-12 21:07:36.062: W/(31646): init htc webcore
08-12 21:07:36.122: W/dalvikvm(31646): threadid=1: thread exiting with uncaught exception (group=0x40e19468)
08-12 21:07:36.122: E/AndroidRuntime(31646): FATAL EXCEPTION: main
08-12 21:07:36.122: E/AndroidRuntime(31646): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sample/com.example.sample.MainActivity}: java.lang.NullPointerException
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.app.ActivityThread.access$600(ActivityThread.java:151)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.os.Looper.loop(Looper.java:155)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.app.ActivityThread.main(ActivityThread.java:5511)
08-12 21:07:36.122: E/AndroidRuntime(31646): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 21:07:36.122: E/AndroidRuntime(31646): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 21:07:36.122: E/AndroidRuntime(31646): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
08-12 21:07:36.122: E/AndroidRuntime(31646): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
08-12 21:07:36.122: E/AndroidRuntime(31646): at dalvik.system.NativeStart.main(Native Method)
08-12 21:07:36.122: E/AndroidRuntime(31646): Caused by: java.lang.NullPointerException
08-12 21:07:36.122: E/AndroidRuntime(31646): at com.example.sample.MainActivity.onCreate(MainActivity.java:62)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.app.Activity.performCreate(Activity.java:5066)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
08-12 21:07:36.122: E/AndroidRuntime(31646): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
08-12 21:07:36.122: E/AndroidRuntime(31646): ... 11 more