几个Android开发中遇到的问题

本文转载自:

麦田开发者

StackOverflow

百度知道

百度知道


问题一:报错:Android Call requires API level 11 (current min is 8)

(解决方案转载自:麦田开发者)

【错误描述】

在用Eclipse开发过程中,为了兼容Android2.2和4.0以上版本,我在使用Notification类时做了2个版本的代码,代码根据系统版本不同执行相应模块,结果,等我输完代码,发现系统提示了一个这么的错误。

【原因分析】

不 详,可能和Run Android Lint有点关系吧。就是创建项目时,我们设置了最低版本API Level,比如我的是8,因此,Eclipse检查我调用的API后,发现版本号不能向低版本兼容,比如我用的“Notification.Builder”是Level 11 以上才有的,自然超过了 8,所以提示错误。

【解决方案】

右键点击项目->Android tools ->Clear Link Markers.即可临时解决,但是如果调试用的模拟器是低版本的,则在调试完后还有这个错误。

如果把manifest文件中的user-sdk的android:minSdkVersion改为报错的那个高版本就没事。比如下面:

<uses-sdk

android:minSdkVersion=”11″   //这个之前是8

android:targetSdkVersion=”17″ />

【扩展】

这种错误不仅发生在Level11,也同时发生于其他因为设置了最低版本,但使用了高版本API的代码中,解决方案应该相同。


问题二:报错:Android CalendarView class cannot be found

(解决方案转载自:StackOverflow)

【问题描述】

Im designing the xml format for a calendar to be used in an app, but I cant get the calendar to show in the graphical layout shower.

Instead I get the following 'error':

The following classes could not be found: - CalendarView (Change to android.widget.CalendarView, Fix Build Path, Edit XML)

The min SDK version for this project is 14 and its target version is 15.

Here is my XML code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

        <RelativeLayout android:id="@+id/top"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
                <Button android:id="@+id/dash"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:maxWidth="200dp"
                    android:maxHeight="10dp"
                    android:text="DASHBOARD"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:layout_alignParentLeft="true"/>

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:paddingBottom="10px"
                    android:paddingTop="10px"
                    android:text="Calendar"
                    android:textAppearance="?android:attr/textAppearanceLarge"/>
                <Button
                    android:id="@+id/plusButton"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:text="+"
                    android:textAppearance="?android:attr/textAppearanceLarge"/>
        </RelativeLayout>
        <CalendarView
            android:id="@+id/calview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/top"
            android:maxHeight="300dp" />

        <RelativeLayout android:id="@+id/infoScroll"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/calview">

            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:maxHeight="100dp">

                <ListView
                    android:id="@+id/listView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </ListView>

            </ScrollView>
        </RelativeLayout>
        <RelativeLayout android:id="@+id/bottomBar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/infoScroll">
            <Button android:id="@+id/todayButton"
                android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:text="Today"
                android:textAppearance="?android:attr/textAppearanceSmall"/>

            <Button android:id="@+id/listButton"
                android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_toLeftOf="@+id/dayButton"
                    android:text="List"
                    android:textAppearance="?android:attr/textAppearanceSmall"/>

        <Button android:id="@+id/dayButton"
                android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerInParent="true"
                    android:text="Day"
                android:textAppearance="?android:attr/textAppearanceSmall"/>

        <Button
            android:id="@+id/monthButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/dayButton"
            android:text="Month"
            android:textAppearance="?android:attr/textAppearanceSmall"/>

        <Button android:id="@+id/PeopleButton"
            android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                    android:layout_alignParentRight="true"
                android:text="People"
                android:textAppearance="?android:attr/textAppearanceSmall"/>



        </RelativeLayout>

</RelativeLayout></span>

Much appreciated! Thanks!

【解决方案】

you might be previewing your screen on Android Target 16. Try using Android Target 15 for Graphic Layout Editor (android icon on the top, in ADT 20). Looks like there is issue with Android Target 16.

NOTE: You don't need to set the project target just the target in the graphical layout editor.


问题三:安卓模拟器运行程序出现:unfortunately 程序名 has stopped

(解决方案转载自:百度知道)

【解决方案】

查看logcat输出的错误信息,里面有详细的错误说明。


问题四:实现点击TextView跳转到其他页面(activity),失败

(解决方案转载自:百度知道)

在注册页面中想要点击某一Textview 然后进入注册页面
public class LoginActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
setTitle("用户登录界面");
TextView txtViewRegister = (TextView)findViewById(R.id.textViewRegister);

txtViewRegister.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
/**
 * 跳到注册页面RegisterActivity
 * */
ComponentName componentname = new ComponentName(LoginActivity.this, "com.example.library.RegisterActivity.java");
Intent intent = new Intent(LoginActivity.this,RegisterActivity.class);
LoginActivity.this.startActivity(intent);
startActivity(intent);
}
});
}
}</span>
另外,
注册activity 要在AndroidManifest.xml中写上
<activity android:name="com.example.library.RegisterActivity"></activity>

这种形式

你可能感兴趣的:(几个Android开发中遇到的问题)