我的Android应用程序强制停止

时间:2016-07-13 12:56:57

标签: java android android-layout android-studio runtime-error

你好我的Android应用程序遇到问题当我点击按钮它停止按钮的功能是使用PutExtra从Edittexts获取数据并将数据和用户移动到另一个名为 Check_inf的类

这是Main类的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.anew.employee.App"
    tools:showIn="@layout/app_layout"
    android:background="@drawable/bg"

    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/txt"
        android:textSize="30dp"
        android:textStyle="bold"
        android:textColor="@color/white"
        android:layout_marginTop="29dp"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true">



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_toRightOf="@+id/scrollView"
        android:layout_toEndOf="@+id/scrollView">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/first_name"
        android:textColorHint="@color/white"
        android:id="@+id/first_name"
        android:layout_marginTop="31dp"
        android:layout_below="@+id/textView"
        android:textColor="@color/white"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:hint="@string/last_name"
        android:textColorHint="@color/white"
        android:id="@+id/last_name"
        android:layout_marginTop="45dp"
        android:layout_below="@+id/first_name"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/phone"
        android:textColor="@color/white"
        android:textColorHint="@color/white"
        android:id="@+id/phone"
        android:layout_below="@+id/email"
        android:inputType="numberSigned"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="41dp" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/email"
        android:textColorHint="@color/white"
        android:id="@+id/email"
        android:textColor="@color/white"
        android:layout_below="@+id/last_name"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="49dp" />

    </LinearLayout>
</ScrollView>

</RelativeLayout>

这是主类的Java代码:

package com.anew.employee;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;

import java.util.ArrayList;
import java.util.List;

/**
 * Author : @Java-dude
 * Date : 12/7/2016
 * Page : Main page
 */

public class App extends AppCompatActivity {

    final static String key = "mostafaabobakr.com.anew.employee.key";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_layout);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }
    //fab (Floating Action Button) onClick method
    public void save(View view)
    {
      EditText first_name = (EditText) findViewById(R.id.first_name);
        String firstname = first_name.getText().toString();
        EditText last_name = (EditText) findViewById(R.id.last_name);
        String lastname =  last_name.getText().toString();
        EditText phone =  (EditText) findViewById(R.id.phone);
        String _phone = phone.getText().toString();
        int phone2 = Integer.parseInt(_phone);
        EditText email = (EditText) findViewById(R.id.email);
        String _email = email.getText().toString();

        ArrayList<String> list  =  new ArrayList<String>();
        list.add(firstname);
        list.add(lastname);
        list.add(_email);

        Intent intent = new Intent(this , Check_inf.class);
        intent.putExtra(key,list);
        intent.putExtra(key,phone2);
        startActivity(intent);


    }
}

这是 Check_info

的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="com.anew.employee.Check_inf"
    android:background="@drawable/bg">

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/check_inf"
    android:textColor="@color/white"
    android:textSize="30dp"
    android:textStyle="bold"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
        android:id="@+id/textView2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/check_Fname"
        android:textColor="@color/white"
        android:textSize="19dp"
        android:textStyle="bold"
        android:id="@+id/check_Fname"
        android:layout_marginTop="43dp"
        android:layout_below="@+id/textView2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/check_Lname"
        android:textColor="@color/white"
        android:textSize="19dp"
        android:textStyle="bold"
        android:id="@+id/check_Lname"
        android:layout_above="@+id/check_phone"
        android:layout_alignRight="@+id/check_Fname"
        android:layout_alignEnd="@+id/check_Fname"
        android:layout_marginBottom="52dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/check_phone"
        android:textColor="@color/white"
        android:textSize="19dp"
        android:textStyle="bold"
        android:id="@+id/check_phone"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/check_email"
        android:textColor="@color/white"
        android:textSize="19dp"
        android:textStyle="bold"
        android:id="@+id/check_email"
        android:layout_marginBottom="55dp"
        android:layout_above="@+id/yes"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/yes"
        android:textSize="20dp"
        android:textColor="@color/white"
        android:background="@color/colorPrimary"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="46dp"
        android:onClick="yes"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/yes" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/no"
        android:textSize="20dp"
        android:textColor="@color/white"
        android:background="@color/gray"
        android:id="@+id/noBack"
        android:onClick="exit"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


</RelativeLayout>

这是 Check_info

的java代码
package com.anew.employee;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;

public class Check_inf extends AppCompatActivity {
    final static String key = "mostafaabobakr.com.anew.employee.key";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.check_inf_layout);
        TextView check_Fname= (TextView) findViewById(R.id.check_Fname);
        TextView check_Lname= (TextView) findViewById(R.id.check_Lname);
        TextView check_phone= (TextView) findViewById(R.id.check_phone);
        TextView check_email= (TextView) findViewById(R.id.check_email);
        Intent intent = getIntent();
        ArrayList<String> data = intent.getStringArrayListExtra(key);
        String first_name = data.get(0).toString();
        String last_name = data.get(1).toString();
        String email= data.get(2).toString();
        String phone = intent.getStringExtra(key).toString();
        int phone2 = Integer.getInteger(phone);

        check_Fname.setText(first_name);
        check_Lname.setText(last_name);
        check_email.setText(email);
        check_phone.setText(phone2);

        }

      public void yes(View view)
      {
          Intent intent = new Intent(this , Finish.class);
          startActivity(intent);
      }

    public void exit(View view)
    {
        finish();
        System.exit(0);
    }
        }

** Log cat **输出

这是错误输出

07-13 15:43:59.989 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.989 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.anew.employee.Welcome.access$super
07-13 15:43:59.999 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:36.069 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.069 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.069 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.069 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.079 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.079 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.079 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.079 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.129 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.139 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.anew.employee.App.access$super
07-13 15:45:36.149 3290-3290/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.App.access$super
07-13 15:45:38.229 3290-3290/com.anew.employee E/AndroidRuntime: in writeCrashedAppName, pkgName :com.anew.employee
07-13 15:45:40.149 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.149 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.149 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.149 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.179 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.179 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.179 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.209 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.209 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.229 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.anew.employee.App.access$super
07-13 15:45:40.229 4117-4117/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.App.access$super
07-13 15:45:52.309 4117-4117/com.anew.employee E/AndroidRuntime: in writeCrashedAppName, pkgName :com.anew.employee
07-13 15:45:52.509 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.509 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.509 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.509 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.509 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.529 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.529 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.529 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.529 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.529 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.anew.employee.Welcome.access$super
07-13 15:45:52.599 4364-4364/com.anew.employee E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.anew.employee.Welcome.access$super

2 个答案:

答案 0 :(得分:0)

请编辑如下代码并重新提交logcat

EditText phone =  (EditText) findViewById(R.id.phone);
String _phone = phone.getText().toString();
Log.i("Before", _phone);
int phone2 = Integer.parseInt(_phone);
Log.i("After", String.ValueOf(phone2));

答案 1 :(得分:0)

我建议你将它转换为JSON而不是ArrayList,以便更容易使用,这是你应该做什么

String json = new Gson().toJson(list);

然后将其添加到意图

intent.putExtra(key,json);

现在在第二个活动中执行以下操作以返回原始arrayList

ArrayList<String> listdata = new ArrayList<String>();     
JSONArray jArray = (JSONArray)getIntent.getExtra().getString(key).toString(); 
if (jArray != null) { 
   for (int i=0;i<jArray.length();i++){ 
    listdata.add(jArray.get(i).toString());
   } 
} 

现在只需读取arrayList并返回代码