0

我试图实现“Font Awesome”引用这个 来源

我做了这些程序,但我的应用程序一启动就关闭了。
这有什么问题?

  1. 我复制了values/attrs.xml。并粘贴到我的应用程序(内容没有变化)

  2. 我复制了 的内容values/strings.xml,并粘贴到我的应用程序中的 strings.xml 中。

  3. 我复制了layouts/icon.xmlgrid.xml,并粘贴到我的应用程序中(内容没有变化)

  4. 我复制assets/icons.ttf并粘贴到我的应用程序中(内容没有变化。这是一个字体文件)

  5. 我复制src/com.example.IconView/IconView.java到我的应用程序(内容没有变化)

  6. 我将这些行添加到我的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();

但是,我的应用程序一启动就会自动关闭。
我怎样才能解决这些问题,并启用字体真棒?

日志猫

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
4

0 回答 0