不幸的是,(app)已经停止了

时间:2015-03-08 04:18:07

标签: android eclipse

我有一个需要原型的课程的应用程序。我的其余代码很好,除了这个我无法切换窗口的部分。我希望你能帮助我,因为这个错误让我很生气。谢谢:))

编辑:我添加了第三节

这是我的第四个布局

package com.example.appxercise_techno;

import com.example.appxercise_techno.activity4;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Intent;

   public class activity4 extends activity3 implements OnClickListener{

  Button heart,leg,abs,chest,back;

  @Override
  public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.sub4);

  heart = (Button)findViewById(R.id.heart);
  leg = (Button)findViewById(R.id.leg);
  abs = (Button)findViewById(R.id.abs);
  chest = (Button)findViewById(R.id.chest);
  back = (Button)findViewById(R.id.back);

  back.setOnClickListener(new OnClickListener(){
      public void onClick(View v){
        Intent intent = new Intent(activity4.this, activity3.class);
        startActivity(intent);
          }
      });

  heart.setOnClickListener(new OnClickListener(){
      public void onClick(View v){
            Intent intent = new Intent(activity4.this, activity5.class);
          startActivity(intent);
          }
      });

  leg.setOnClickListener(new OnClickListener(){
      public void onClick(View v){
        Intent intent = new Intent(activity4.this, activity6.class);
        startActivity(intent);
        }
    });

  abs.setOnClickListener(new OnClickListener(){
      public void onClick(View v){
        Intent intent = new Intent(activity4.this, activity7.class);
        startActivity(intent);
        }
    });

chest.setOnClickListener(new OnClickListener(){
    public void onClick(View v){
        Intent intent = new Intent(activity4.this, activity8.class);
        startActivity(intent);
         }
     });

    }
 }


This is the layout xml

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res /android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >

  <Button
      android:id="@+id/back"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="36dp"
      android:text="Back" />

  <TextView
      android:id="@+id/large"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="25dp"
      android:text="Side Quest Trainings"
      android:textAppearance="?android:attr/textAppearanceLarge" />

  <Button
      android:id="@+id/abs"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignBaseline="@+id/heart"
      android:layout_alignBottom="@+id/heart"
      android:layout_marginLeft="14dp"
      android:layout_toRightOf="@+id/back"
      android:text="Cores" />

  <Button
      android:id="@+id/heart"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@+id/large"
      android:layout_below="@+id/large"
      android:layout_marginTop="68dp"
      android:text="Cardio" />

  <Button
      android:id="@+id/leg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignBaseline="@+id/chest"
      android:layout_alignBottom="@+id/chest"
      android:layout_alignLeft="@+id/abs"
      android:text="Lower" />

  <Button
      android:id="@+id/chest"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/back"
      android:layout_marginBottom="54dp"
      android:layout_toLeftOf="@+id/back"
      android:text="Upper" />

 </RelativeLayout>

这就是错误

03-07 23:09:21.010:E / AndroidRuntime(1192):致命异常:主要 03-07 23:09:21.010:E / AndroidRuntime(1192):进程:com.example.appxercise_techno,PID:1192 03-07 23:09:21.010:E / AndroidRuntime(1192):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.appxercise_techno / com.example.appxercise_techno.activity4}:java.lang.NullPointerException 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.app.ActivityThread.access $ 700(ActivityThread.java:135) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1397) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.os.Handler.dispatchMessage(Handler.java:102) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.os.Looper.loop(Looper.java:137) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.app.ActivityThread.main(ActivityThread.java:4998) 03-07 23:09:21.010:E / AndroidRuntime(1192):at java.lang.reflect.Method.invokeNative(Native Method) 03-07 23:09:21.010:E / AndroidRuntime(1192):at java.lang.reflect.Method.invoke(Method.java:515) 03-07 23:09:21.010:E / AndroidRuntime(1192):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:777) 03-07 23:09:21.010:E / AndroidRuntime(1192):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 03-07 23:09:21.010:E / AndroidRuntime(1192):at dalvik.system.NativeStart.main(Native Method) 03-07 23:09:21.010:E / AndroidRuntime(1192):引起:java.lang.NullPointerException 03-07 23:09:21.010:E / AndroidRuntime(1192):at com.example.appxercise_techno.activity2.onCreate(activity2.java:27) 03-07 23:09:21.010:E / AndroidRuntime(1192):at com.example.appxercise_techno.activity3.onCreate(activity3.java:19) 03-07 23:09:21.010:E / AndroidRuntime(1192):at com.example.appxercise_techno.activity4.onCreate(activity4.java:16) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.app.Activity.performCreate(Activity.java:5243) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 03-07 23:09:21.010:E / AndroidRuntime(1192):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140) 03-07 23:09:21.010:E / AndroidRuntime(1192):... 11更多

This is the third activity

package com.example.appxercise_techno;

import com.example.appxercise_techno.activity3;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.content.Intent;

public class activity3 extends activity2 implements OnClickListener{

TextView out1, out2, out3, out4, out5, out6, big;
Button quest;

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.sub3);

    out1 = (TextView)findViewById(R.id.out1);
    out2 = (TextView)findViewById(R.id.out2);
    out3 = (TextView)findViewById(R.id.out3);
    out4 = (TextView)findViewById(R.id.out4);
    out5 = (TextView)findViewById(R.id.out5);
    out6 = (TextView)findViewById(R.id.out6);
    big = (TextView)findViewById(R.id.big);
    quest = (Button)findViewById(R.id.quest);

    Bundle extras = getIntent().getExtras();
    String name = extras.getString("name1");
    Double result = extras.getDouble("result");

    big.setText("Your Routine " +name );

    if (result >= 15 && result < 16){

        out1.setText("10 Pushups");
        out2.setText("10 Situps");
        out3.setText("10 Seconds Plank");
        out4.setText("5 Squat Thrusts");
        out5.setText("10 Pullups");
        out6.setText("2 Sets. Rest between sets up to 2 mins.");
    }

    else if (result >= 16 && result < 18.5){

        out1.setText("5 Minutes Running/Walking");
        out2.setText("20 Pushups");
        out3.setText("20 Seconds Plank");
        out4.setText("20 Lunges");
        out5.setText("30 Shadowbox Punches");
        out6.setText("3 Sets. Rest between sets up to 3 mins.");
    }

    else if (result >= 18.5 && result < 25){

        out1.setText("20 Pushups");
        out2.setText("20 Seconds Plank");
        out3.setText("20 Situps");
        out4.setText("12 Flutter Kicks");
        out5.setText("15 Squats");
        out6.setText("5 Sets. Rest between sets up to 2 mins.");
    }

    else if (result >= 25 && result < 30){

        out1.setText("20 Pushups");
        out2.setText("10 Seconds Plank");
        out3.setText("50 Shadowbox Punches");
        out4.setText("60 Seconds One Leg Stand");
        out5.setText("20 Pullups");
        out6.setText("3 Sets. Rest between sets up to 2 mins.");
    }

    else if (result >= 30 && result < 35){

        out1.setText("3 Minutes Sprint");
        out2.setText("10 Jumping Jacks");
        out3.setText("10 Squats");
        out4.setText("5 Second Plank");
        out5.setText("20 Toe Reaches");
        out6.setText("3 Sets. Rest bewteen sets up to 3 mins. ");
    }

    else if (result >= 35){

        out1.setText("3 Minutes Sprint");
        out2.setText("10 Jumping Jacks");
        out3.setText("10 Knee Touches");
        out4.setText("10 Toe Reaches");
        out5.setText("10 Climbers");
        out6.setText("2 Sets. Rest bewteen sets up to 3 mins.");
    }

    quest.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            Intent intent = new Intent(activity3.this, activity4.class);
            startActivity(intent);
            }
        });
    }
}

3 个答案:

答案 0 :(得分:0)

这是错误行(应该是第27行)

Intent intent = new Intent(activity4.this, activity3.class);;

activity3由activity4扩展。你确定activity3不是抽象的吗?另外,尝试这个,而不是activty4.this,尝试getContext()。这应该没关系,只是为了以防万一。

最后,它是在所有按钮上崩溃还是刚刚回来?

答案 1 :(得分:0)

问题可能是extra为空。

请参阅此question

如果问题仍然存在,请添加sub3.xml。

答案 2 :(得分:0)

你似乎有问题

Bundle extras = getIntent().getExtras(); // extras is null since you are not setting up bundle there
String name = extras.getString("name1"); // gives NPE
Double result = extras.getDouble("result");