Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Java应用程序每次在第三次图像上传时崩溃_Java_Android - Fatal编程技术网

Android Java应用程序每次在第三次图像上传时崩溃

Android Java应用程序每次在第三次图像上传时崩溃,java,android,Java,Android,我有一个小应用程序,它允许用户上传一些基本数据(姓名、学年、级别),然后上传一张w/e的图片。 因此,在上传第三张图像之前,一切都按预期进行,应用程序重新启动,我甚至没有收到错误消息 所以我有一个主活动,它使用一个对话框来允许某些数据输入,并且在对话框中数据被保存到主活动中。当用户上传完数据后,他们可以保存所有数据并继续进行最后的活动,其中会出现一个列表视图,显示所有已输入的数据 因此,问题特别是在上传第二个映像之后,当用户上传第三个映像,然后继续进行最后的活动时,它只是重新启动,没有错误消息或

我有一个小应用程序,它允许用户上传一些基本数据(姓名、学年、级别),然后上传一张w/e的图片。 因此,在上传第三张图像之前,一切都按预期进行,应用程序重新启动,我甚至没有收到错误消息

所以我有一个主活动,它使用一个对话框来允许某些数据输入,并且在对话框中数据被保存到主活动中。当用户上传完数据后,他们可以保存所有数据并继续进行最后的活动,其中会出现一个列表视图,显示所有已输入的数据

因此,问题特别是在上传第二个映像之后,当用户上传第三个映像,然后继续进行最后的活动时,它只是重新启动,没有错误消息或任何东西。但是如果你上传了一堆没有图片的东西,你可以随意添加和查看

因此,我为我的学生对象和数组适配器以及我的活动创建了一个类。我将在下面发布所有相关代码。我已经研究了阵列适配器的问题,但我不认为它是特别的,因为它在没有图像时工作良好,并且在添加图像时工作到两个图像。所以我真的不明白问题是什么,特别是因为我没有收到任何错误的MSG

代码如下

主要活动


public class MainActivity extends AppCompatActivity  {
    static final int REQUEST_IMAGE_CAPTURE = 1;
    ImageView myImage;
    Student myself;
    ArrayList<Student> studentArrayList;
    EditText myName;
    Bitmap imageBitmap;
    static Bitmap img;
    Button finalSave;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myImage = (ImageView) findViewById(R.id.personalImageID);
        myName = (EditText) findViewById(R.id.studentName);
        finalSave = (Button)findViewById(R.id.finalSave);
        myself = new Student();
        studentArrayList = new ArrayList<Student>(0);
        finalSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                endMainActivity();
            }
        });

    }
    private void endMainActivity()
    {
        Intent studentListIntent =  new Intent(this, ReportActivity.class);
        System.out.println("Main Activity Student List size : " + studentArrayList.size());
        studentListIntent.putParcelableArrayListExtra("students", studentArrayList);
        startActivity(studentListIntent);
    }
    @Override
    protected void onResume() {
        super.onResume();
        myself = new Student();
    }

    public void upload(View view) {
        Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if(pictureIntent.resolveActivity(getPackageManager()) != null)
            startActivityForResult(pictureIntent, REQUEST_IMAGE_CAPTURE);
    }


    public void addYearAndLevel(View view) {
        myself.studentName =  myName.getText().toString();
        AddYearAndLevelDialog dialog = new AddYearAndLevelDialog();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        dialog.show(transaction, "fragment");
    }

    public void addToList()
    {
        myself.imageData = img;
        studentArrayList.add(myself);
        System.out.println(myself.studentName + " " + myself.level + " " + myself.year + " " + myself.imageData );
        myName.setText("");
        myself = new Student();
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            imageBitmap = (Bitmap) extras.get("data");
            myImage.setImageBitmap(imageBitmap);
            img = imageBitmap;
        }
    }

}


公共类MainActivity扩展了AppCompatActivity{
静态最终整数请求\图像\捕获=1;
图像查看我的图像;
学生本人;
ArrayList学生ArrayList;
编辑文本myName;
位图图像位图;
静态位图图像;
按钮最终保存;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myImage=(ImageView)findViewById(R.id.personalImageID);
myName=(EditText)findViewById(R.id.studentName);
finalSave=(按钮)findViewById(R.id.finalSave);
我自己=新学生();
studentArrayList=新ArrayList(0);
finalSave.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
endmain活动();
}
});
}
私有void endmain活动()
{
Intent studentListIntent=新的意图(此,ReportActivity.class);
System.out.println(“主要活动学生列表大小:+studentArrayList.size());
studentListIntent.putParcelableArrayListExtra(“学生”,studentArrayList);
startActivity(studentListIntent);
}
@凌驾
受保护的void onResume(){
super.onResume();
我自己=新学生();
}
公共作废上传(查看){
意向图片内容=新意向(MediaStore.ACTION\u IMAGE\u CAPTURE);
if(PictureContent.resolveActivity(getPackageManager())!=null)
startActivityForResult(图片内容、请求图像捕获);
}
公共void addYearAndLevel(视图){
my.studentName=myName.getText().toString();
AddYearAndLevelDialog=新建AddYearAndLevelDialog();
FragmentTransaction=getFragmentManager().beginTransaction();
显示(事务,“片段”);
}
公共无效地址列表()
{
imf.imageData=img;
学生列表。添加(我自己);
System.out.println(imf.studentName+“”+imf.level+“”+imf.year+“”+imf.imageData);
myName.setText(“”);
我自己=新学生();
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
if(requestCode==REQUEST\u IMAGE\u CAPTURE&&resultCode==RESULT\u OK){
Bundle extras=data.getExtras();
imageBitmap=(位图)extras.get(“数据”);
设置图像位图(图像位图);
img=图像位图;
}
}
}
视图控制器


public class ReportActivity extends AppCompatActivity {
    ListView list;
    ArrayList<Student> students;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report);
        students = getIntent().getParcelableArrayListExtra("students");
        System.out.println("Student List Size : " + students.size());
        list = findViewById(R.id.studentList);
        StudentAdapter adapter = new StudentAdapter(getApplicationContext(), students);
        list.setAdapter(adapter);

    }

}


公共类ReportActivity扩展了AppCompatActivity{
列表视图列表;
ArrayList学生;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_报告);
学生=getIntent().getParcelableArrayListExtra(“学生”);
System.out.println(“学生列表大小:+students.Size());
列表=findViewById(R.id.studentList);
StudentAdapter=新的StudentAdapter(getApplicationContext(),students);
list.setAdapter(适配器);
}
}
用于查看的xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:orientation="vertical"
    android:gravity="center"
    tools:context=".ReportActivity">

    <ListView
        android:id="@+id/studentList"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </ListView>

</LinearLayout>

适配器


public class StudentAdapter extends BaseAdapter {
    Context context;
    ArrayList<Student> students;
    LayoutInflater inflater;
    View view;

    public StudentAdapter(Context appContext, ArrayList<Student>students)
    {
        this.context = appContext;
        this.students = students;
        inflater = LayoutInflater.from(this.context);
    }
    @Override
    public int getCount() {
        return students.size();
    }

    @Override
    public Object getItem(int position) {
        return students.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        view =  inflater.inflate(R.layout.list_item, null);

        ImageView image = (ImageView) view.findViewById(R.id.imageUploaded);
        TextView studentName = (TextView) view.findViewById(R.id.studName);
        TextView studYearLvl = (TextView) view.findViewById(R.id.lvlAndYear);
        image.setImageBitmap(students.get(position).imageData);
        studentName.setText(students.get(position).studentName);
        studYearLvl.setText("Level: " + students.get(position).level + "  " + "Year: " + " " + students.get(position).year);

        return view;
    }
}


公共类StudentAdapter扩展BaseAdapter{
语境;
ArrayList学生;
充气机;
视图;
公共学生适配器(上下文appContext,ArrayListstudents)
{
this.context=appContext;
这个。学生=学生;
充气器=从(此上下文)开始的充气器;
}
@凌驾
public int getCount(){
返回学生。大小();
}
@凌驾
公共对象getItem(int位置){
返回学生。获得(职位);
}
@凌驾
公共长getItemId(int位置){
返回0;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图=充气机。充气(R.layout.list_项,空);
ImageView image=(ImageView)view.findViewById(R.id.ImageUpload);
TextView studentName=(TextView)view.findViewById(R.id.studName);
TextView studYearLvl=(TextView)view.findViewById(R.id.lvlAndYear);
image.setImageBitmap(students.get(position.imageData));
studentName.setText(students.get(position.studentName));
studYearLvl.setText(“Level:+students.get(position)。Level++”Year:“++”students.get(position)。Year”);
返回视图;
}
}
列表视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/imageUploaded"
        android:layout_width="100dp"
        android:layout_height="100dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
            <TextView
                android:id="@+id/studName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                />
        <TextView
            android:id="@+id/lvlAndYear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>


</LinearLayout>