簡體   English   中英

Android應用不斷在模擬器和Nexus 10中崩潰

[英]Android app keeps crashing in emulator and Nexus 10

這個應用程式在模擬器中不斷崩潰(我已為其分配700 MB的RAM,並且是Nexus 4),並且當我嘗試將其加載到Nexus 10和Galaxy S3上時。 我認為這是由於Java中有關如何切換Android活動的一些錯誤所致,但我並沒有因此而警告。 這是代碼:

    package com.example.ldsm2;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;

public class Instructions extends Activity {

/** Called when the user clicks the Send button */
public void Ldsm (View view) {
    Object Intent = startActivity(Ldsm.class);  
}

private com.example.ldsm2.intent startActivity(
        Class<Ldsm> class1) {
    // TODO Auto-generated method stub
    return null;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_instructions);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.instructions, menu);
    return true;
}

}

因為其他活動只有一個不同的活動可以切換到,所以我只是將代碼復制到其他活動的Java源代碼文件中,但是將活動更改為切換到(學生將單擊一個按鈕,並將其發送給另一個活動。問題解決)。

但是,這似乎不是應用程序中的唯一問題。 該應用程序應該顯示圖像,但是該功能也會出現另一個警告。 這是XML代碼,再次復制到其他活動文件,因為它們只需要顯示另一個圖像。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Ldsm" >

<EditText
    android:id="@+id/launch_codes"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/enter_launch_codes"
    android:imeActionLabel="@string/launch"
    android:inputType="number" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:onClick="methodName"
    android:text="@string/instructions" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/launch_codes"
    android:layout_alignParentRight="true"
    android:onClick="modeon"
    android:text="@string/button_send" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_below="@+id/launch_codes"
    android:layout_marginTop="141dp"
    android:layout_toLeftOf="@+id/button2"
    android:src="@drawable/ic_pro1" android:contentDescription="TODO"/>

這些是Eclipse Problems選項卡中出現的警告。 對於XML代碼,這是出現的錯誤:“描述:本地變量Intent的值未使用,第16行Java問題,對於Java代碼:描述資源路徑位置類型[Accessibility]圖像上缺少contentDescription屬性第37行Android Lint問題。

最后,這是我嘗試在模擬器中啟動應用程序時出現的錯誤。 在此處輸入圖片說明

您需要使用LogCat來查看其內容。 關於正在發生的事情會有一些線索。

[Accessibility] Missing contentDescription attribute  

適用於視障人士。 該值由屏幕閱讀器讀出。 基本上,這就是說存在可訪問性錯誤的可能性。

The value of the local variable Intent is not used  

這告訴您,盡管您已為變量分配了一個值,但是您從未在代碼中的任何地方使用它。 您可以安全地刪除它,除非您打算使用它。 由於這是一個Intent ,我想您正在計划開始其他一些Activity

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM