API 10 编译错误 [英] Compiling error with API 10

查看:23
本文介绍了API 10 编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注 developer.android.com 上的基本教程,并创建了名为 DisplayMessageActivity 的活动.这是一个空白活动,具有教程中给出的所有规范.仅供参考,我正在使用 Min SDK = API 8,目标 SDK = API 16,使用 = API 10 编译

I was following the basic tutorials on developers.android.com and came by creating the activity named DisplayMessageActivity. It is a blank activity with all the specifications given as shown in the tutorial. FYI, I am using Min SDK = API 8, Target SDK = API 16, Compile with = API 10

接下来有两个错误:

  1. "未定义 DisplayMessageActivity 类型的 getActionBar() 方法
  2. home 无法解析或不是字段"

我尝试将 API 更改为 14,这导致了另一个问题,它希望最小 API 为 11.

I tried changing the API to 14 which called for another problem, it wants the minimum API to be 11.

这解决了这些问题,但主要问题是许多设备仍在使用 Gingerbread 或 FroYo.我不能为他们写作吗?我必须走得更高吗?如何为他们写作?

That solves these problems, but the main problem is so many devices still use Gingerbread or maybe FroYo. Can't I write for them? Do I have to go higher? How to write for them?

推荐答案

首先,您需要确保针对最新版本的 Android 进行编译.您应该更新您的 sdk 版本,因为您正在为 API 10 编译但目标是 16.如果您这样做,内容可能会损坏,因此最好保持更新以确保安全.这意味着在 Eclipse 中右键单击您的项目,单击属性,然后单击 Android.检查那里的最高版本 API.如果您有最新版本,那就是 Android 4.2.然后在您的 AndroidManifest.xml 中,将 android:targetSdkVersion 设置为您选择的内容(我的案例 api 17).

First, you're going to want to make sure that you are compiling against the latest version of Android. You should update your sdk version because you're compiling for API 10 but targeting 16. Stuff may break if you do that, so it's best to stay updated to be safe. This means right clicking on your project in Eclipse, clicking on Properties then clicking on Android. Check off the highest version API that is there. If you have the latest version, it is Android 4.2. Then in your AndroidManifest.xml, set the android:targetSdkVersion to what you chose (my case api 17).

这应该确保您的应用程序基本上可以在 HoneyComb 到 JellyBean 上运行.但是,这个应用程序至少要在 froyo 上运行.下一部分将允许您的应用在所有设备上运行.

This should ensure that your app can run on basically HoneyComb to JellyBean. However, this app wants to run on at least froyo. This next part will allow your app to run on all devices.

制作一个这样的方法:

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setupActionBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // Show the Up button in the action bar.
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

它会检查它正在运行的 API,并且只有当它是蜂窝和更高版本时,才会启用操作栏.从 onCreate() 调用它您将需要取出 onCreate() 中的 getActionBarCall,因为那里不再需要它.

It checks to see which API it is running on and only if it is honeycomb and above, enables the action bar. Call it from onCreate() You will need to take out the getActionBarCall that is in onCreate() as it is not needed anymore there.

至于 home 没有启用,可能只是项目目标错误,或者你忘记写 android.R.id.home 而是写了 R.id.home.

As for home not being enabled, it might have just been a wrong project target or you forgot to write android.R.id.home and instead wrote R.id.home.

最后,通过所有这些更改,您应该清理您的项目(项目 -> 清理).

Lastly with all these changes you should clean your project (Project -> Clean).

这篇关于API 10 编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆