1. 程式人生 > >幾個Android開發中遇到的問題

幾個Android開發中遇到的問題

本文轉載自:

麥田開發者

百度知道

百度知道

----------------------------------------------------------------------------------------------------------------

問題一:報錯: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的程式碼中,解決方案應該相同。

-----------------------------------------------------------------------------------------------------------------------

【問題描述】

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>

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);
}
});
}
}
另外,
註冊activity 要在AndroidManifest.xml中寫上
<activity android:name="com.example.library.RegisterActivity"></activity>
這種形式