繁体   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