【发布时间】:2020-02-12 03:02:23
【问题描述】:
我正在 android studio 中构建一个联系人应用程序。 所有其他的东西,比如登录,注册都在应用程序中工作。 我没有从 android studio 的列表视图中的后端数据库中获取我的数据。 但我的活动正在运行,并且应用程序内有崩溃。谁能帮忙?
view_contacts.java
package com.example.testapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.backendless.Backendless;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.persistence.DataQueryBuilder;
import java.util.List;
public class view_contact extends AppCompatActivity {
ListView lvlist;
ContactAdapter adapter;
TextView contacts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_contact);
contacts=findViewById(R.id.tvcontacts);
lvlist=findViewById(R.id.list_view);
String whereClause="userEmail = '" + TestApplication.user.getEmail() +"'";
DataQueryBuilder queryBuilder=DataQueryBuilder.create();
queryBuilder.setWhereClause(whereClause);
queryBuilder.setGroupBy("name");
Backendless.Persistence.of(Contact.class).find(queryBuilder, new AsyncCallback<List<Contact>>() {
@Override
public void handleResponse(List<Contact> response) {
TestApplication.contacts = response;
adapter=new ContactAdapter(view_contact.this,TestApplication.contacts);
lvlist.setAdapter(adapter);
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(view_contact.this, "Error : "+fault.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
ContactsAdapter.java
package com.example.testapp;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.List;
public class ContactAdapter extends ArrayAdapter<Contact> {
private Context context;
private List<Contact> contacts;
public ContactAdapter(@NonNull Context context, List<Contact> contacts) {
super(context,R.layout.row_layout);
this.context = context;
this.contacts = contacts;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView= inflater.inflate(R.layout.row_layout,parent,false);
TextView tvchar=convertView.findViewById(R.id.tvchar);
TextView tvname=convertView.findViewById(R.id.tvname);
TextView tvmail=convertView.findViewById(R.id.tvmail);
tvchar.setText(contacts.get(position).getName().toUpperCase().charAt(0));
tvname.setText(contacts.get(position).getName());
tvmail.setText(contacts.get(position).getEmail());
return convertView;
}
}
TestApplication.java
// I have set up my backendless database code above and my list is declared public below
public static List<Contact> contacts;
logcat:-
2020-02-12 18:27:55.078 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:58.118 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:58.138 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:58.152 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:58.170 13205-13229/com.example.testapp I/chatty: uid=10090(com.example.testapp) RenderThread identical 1 line
2020-02-12 18:27:58.178 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:59.649 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
【问题讨论】:
-
请详细说明问题并将日志粘贴到此处,以便我们为您提供帮助。谢谢
-
我现在已经添加了 logcat 所以现在请给我建议解决方案
标签: java android-studio arraylist backendless