简体   繁体   English

我的Android App强制停止

[英]My Android App force stop

Hello I faced a problem with my android app when i click on the button it stops the button's function is get the data from Edittexts with PutExtra and move the data and the user to another class called Check_inf 您好,当我点击按钮时,我的Android应用程序遇到了问题,该按钮停止了按钮的功能,即使用PutExtra从Edittexts获取数据并将数据和用户移至另一个名为Check_inf的

and this is the xml code of the Main class : 这是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>

and this is the Java code to the main class : 这是主类的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);


    }
}

and this is the xml of Check_info class 这是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>

and this is the java code of Check_info 这是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 ** Output **日志猫**输出

This is the Error output 这是错误输出

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

please edit your code like follows and re-submit the logcat 请按如下所示编辑您的代码,然后重新提交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));

i recommended you to convert it to JSON instead of ArrayList to let it easier to use, here is what should you do 我建议您将其转换为JSON而不是ArrayList,以使其更易于使用,这是您应该做的

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

then add it to intent 然后将其添加到意图

intent.putExtra(key,json);

now in the second activity do the following to get back the original arrayList 现在在第二个活动中,执行以下操作以恢复原始的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());
   } 
} 

now just read the arrayList and get back to code 现在只需阅读arrayList并返回代码

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

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