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

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

问题描述

我按照developers.android.com上的基本教程,创建了名为DisplayMessageActivity的活动。它是一个空白活动,所有的规格如本教程中所示。 FYI,我使用Min SDK = API 8,Target SDK = API 16,Compile with = API 10



接下来的事情有两个错误:


  1. 方法getActionBar()未定义为DisplayMessageActivity类型

  2. home无法解析或不一个字段

我试图将API更改为14,这引发了另一个问题,但它要求最小API为11。 p>

这解决了这些问题,但主要的问题是这么多设备仍然使用姜饼或者也许FroYo。我不能为他们写吗?我必须走高吗?为他们编写?

解决方案

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



>



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



创建如下方法:

  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar(){
if(Build.VERSION.SDK_INT> = Build.VERSION_CODES.HONEYCOMB){
//在操作栏中显示向上按钮。
getActionBar()。setDisplayHomeAsUpEnabled(true);
}
}

它检查运行的是哪个API,只有当它是蜂窝及以上,启用操作栏。
调用它onCreate()您将需要取出中的getActionBarCall onCreate()因为它不再需要了。



对于没有启用的家庭,它可能是一个错误的项目目标或者你忘了写 android.R.id.home ,并写下 R.id.home



最后,对于所有这些更改,您应该清理您的项目(项目 - >清洁)。


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

The next thing is that there are two errors:

  1. "The method getActionBar() is undefined for the type DisplayMessageActivity
  2. "home cannot be resolved or is not a field"

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

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?

解决方案

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).

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.

Make a method like this:

@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);
        }
    }

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.

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天全站免登陆