【发布时间】:2016-01-24 20:59:32
【问题描述】:
我正在尝试为一个大学项目创建一个简单的应用程序,这变得令人沮丧。每次我更正一个错误时,都会弹出 6 个错误。谁能帮帮我。
此框要求提供更多信息...所以基本上我想创建 4 个活动,主要、age4to10、age11to15、age15to18。我需要能够单击一个按钮并从Main.class 调用相关活动。但是每次调试时我都会遇到错误,我根本不明白如何修复。
每个活动都将托管一个微调器,其中包含从用户选择的类别中选择的玩具。 (甚至不要让我开始使用微调器)
感谢用户不要编辑我的帖子,因为我认为此处的所有信息都与我遇到的问题相关。顺便说一句....我几乎没有接受过 Java 培训,因此我需要您可能需要提供的更正示例。
谢谢。
package com.example.android.skillsdemoVT;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button button1;
Button button2;
Button button3;
@Override
/* button1 */
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View viewById;
viewById = findViewById(R.id.button1);
button1.setOnClickListener(this);
}
@Override
public void onClick1(View v)
{
{
button1click1();
}
}
public void button1click1()
{
startActivity(new Intent(MainActivity.this, age4to10.class));
}
/* Button2 */
public void onClick2(View v)
{
setContentView(R.layout.activity_main);
View viewById;
viewById = findViewById(R.id.button2);
button2.setOnClickListener(this);
}
public void button2click1()
{
{
button2click1();
}
}
public void()
{
{
startActivity(new Intent(MainActivity.this, age11to15.class));
}
}
/* button3 */
public void onClick3(View v)
{
setContentView(R.layout.activity_main);
View viewById;
viewById = findViewById(R.id.button3);
button3.setOnClickListener(this);
}
@Override
public void onClick(View v) {
{
button3click1();
}
}
public void button3click1()
{
startActivity(new Intent(MainActivity.this, age15to18.class));
}
}
MY XML
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">
<ImageView
android:id="@+id/tree1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tree1"/>
<TextView
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="85dp" android:text="Welcome to Santa's workshop."
android:textColor="#ffffff"
android:textSize="25sp"/>
<TextView
android:id="@+id/instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please let Santa know how old you are!"
android:textColor="#ffffff"
android:textSize="25sp"
android:layout_marginTop="43dp"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/welcome"
android:layout_alignEnd="@+id/welcome" />
<Button
android:id="@+id/button1"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#b12b2b"
android:textColor="#ffffff"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="Age 4-10"
android:textSize="30sp"
android:onClick="age4to10"/>
<Button
android:id="@+id/button2"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#b12b2b"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/button1"
android:text="Age 11-14"
android:textSize="30sp"
android:onClick="age11to15"/>
<Button
android:id="@+id/button3"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#b12b2b"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/button2"
android:text="Age 15-17"
android:textSize="30sp"
android:onClick="age15to18"
/>
/>
</RelativeLayout>
【问题讨论】:
-
人们投反对票是因为您的问题不符合此处列出的准则:stackoverflow.com/help/how-to-ask
-
没关系..我没有意识到提问有规则.....
-
只是一点建议,在您提出有关您的代码为什么不工作的问题之前,请尝试将其压缩为仍然存在错误的最小形式。这通常会自行调试问题。
-
好的,下次有问题时我会这样做,谢谢您的建议!关于调试器中实际发生的任何想法?
-
您没有发布任何错误。如果没有一些错误的迹象,我不会阅读那堵代码墙......