简体   繁体   English

Android应用不断在模拟器和Nexus 10中崩溃

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

This app keeps on crashing inside the emulator (for which I have allocated 700 MB for RAM, and is a Nexus 4), and when I try loading it onto my Nexus 10, and Galaxy S3. 这个应用程式在模拟器中不断崩溃(我已为其分配700 MB的RAM,并且是Nexus 4),并且当我尝试将其加载到Nexus 10和Galaxy S3上时。 I think it is because of several errors in Java on how to switch Android activities, for which I'm warnings from, but not errors. 我认为这是由于Java中有关如何切换Android活动的一些错误所致,但我并没有因此而警告。 This is the code: 这是代码:

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

} }

Because the other activities just have a different activity to switch to, I simply copied the code to the other activities' Java source code files, but changed the activities to switch to (the students will click on a button and it will send them to another problem to solve). 因为其他活动只有一个不同的活动可以切换到,所以我只是将代码复制到其他活动的Java源代码文件中,但是将活动更改为切换到(学生将单击一个按钮,并将其发送给另一个活动。问题解决)。

However, this seems like this is not the only problem in the app. 但是,这似乎不是应用程序中的唯一问题。 The app is supposed to display images, but there is another warning that comes up for that function as well. 该应用程序应该显示图像,但是该功能也会出现另一个警告。 This is the XML code, once again copied to the other activities files because they just need to display another image. 这是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"/>

These are the warnings that come up in the Eclipse problems tab. 这些是Eclipse Problems选项卡中出现的警告。 For the XML code, this is the error that comes up: "Description: The value of the local variable Intent is not used line 16 Java Problem, and for the Java code: Description Resource Path Location Type [Accessibility] Missing contentDescription attribute on image line 37 Android Lint Problem. 对于XML代码,这是出现的错误:“描述:本地变量Intent的值未使用,第16行Java问题,对于Java代码:描述资源路径位置类型[Accessibility]图像上缺少contentDescription属性第37行Android Lint问题。

Finally, this is the error that comes up when I try launching the app inside the emulator. 最后,这是我尝试在模拟器中启动应用程序时出现的错误。 在此处输入图片说明

You need to use LogCat to see what it says. 您需要使用LogCat来查看其内容。 There will be some clue as to what is happening. 关于正在发生的事情会有一些线索。

[Accessibility] Missing contentDescription attribute  

is for the visually impaired. 适用于视障人士。 This value is read out by screen readers. 该值由屏幕阅读器读出。 Basically what it is saying is that there is a possibility of an accessibility bug. 基本上,这就是说存在可访问性错误的可能性。

The value of the local variable Intent is not used  

This tells you that although you have assigned a value to your variable, you have never used it anywhere in your code. 这告诉您,尽管您已为变量分配了一个值,但是您从未在代码中的任何地方使用它。 You may safely delete this unless you plan on using it. 您可以安全地删除它,除非您打算使用它。 Since it is an Intent , I guess you are planning on starting some other Activity 由于这是一个Intent ,我想您正在计划开始其他一些Activity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM