这个应用程序在模拟器中不断崩溃(我已经为它分配了700 MB内存,是一个Nexus 4),当我尝试将它加载到我的Nexus 10和Galaxy上时。我认为这是因为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代码,出现的错误是:“描述:局部变量意图的值没有使用第16行Java问题,对于Java代码:描述资源路径定位类型可访问性类型缺少图像行37 Android问题上的contentDescription属性。
最后,这是当我尝试在模拟器中启动应用程序时出现的错误。
发布于 2014-02-01 17:37:40
您需要使用LogCat
来查看它的内容。对于正在发生的事情,将会有一些线索。
[Accessibility] Missing contentDescription attribute
是为视障人士准备的。此值由屏幕阅读器读出。从根本上讲,它的意思是有可能出现可访问性错误。
The value of the local variable Intent is not used
这告诉您,尽管您已经为变量分配了一个值,但是您从未在代码中的任何地方使用过它。除非您计划使用它,否则您可以安全地删除它。因为它是Intent
,所以我想您正在计划启动其他的Activity
https://stackoverflow.com/questions/21499862
复制相似问题