The goal of the Android app is as follows;
I statically loaded a list of people into the Person entity, so the class screen_activity would identify if the list would come empty or filled, if it were empty it would call main.xml screen if it were filled would load cadastro_activity.xml
I tried to do this but when I ran the application it returned me this error;
04-30 16:07:34.836 4729-4729/br.com.wlady.personalfinan E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.wlady.personalfinan, PID: 4729
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.wlady.personalfinan/br.com.wlady.personalfinan.tela_activity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
at android.app.ListActivity.onContentChanged(ListActivity.java:243)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:398)
at android.app.Activity.setContentView(Activity.java:2166)
at br.com.wlady.personalfinan.tela_activity.onCreate(tela_activity.java:22)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-30 16:07:41.259 4729-4729/br.com.wlady.personalfinan I/Process: Sending signal. PID: 4729 SIG: 9
I do not just want to understand the error I wanted to help me with how to fix this problem.
Person Entity
public class Pessoa {
private String login;
private String senha;
private String email;
public Pessoa(String login, String senha, String email) {
this.login = login;
this.senha = senha;
this.email = email;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public static List<Pessoa> getPessoa(){
List<Pessoa> pessoas = new ArrayList<>();
pessoas.add((new Pessoa("wlady","1234","[email protected]")));
return pessoas;
}
}
Home Screen
<?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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Dados Pessoais"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txt_nome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/edit_nome"
android:text="Login" />
<EditText
android:id="@+id/edit_nome"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txt_email"
android:layout_margin="40dp"
android:layout_toRightOf="@id/txt_nome" />
<TextView
android:id="@+id/txt_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/edit_email"
android:text="E-mail" />
<EditText
android:id="@+id/edit_email"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_nome"
android:layout_toRightOf="@+id/txt_email"
android:inputType="textWebEmailAddress" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/txt_email"
android:layout_marginTop="40dp"
android:text="Resistrar" />
</RelativeLayout>
Registration form
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</LinearLayout>
Activity calling screens
public class tela_activity extends ListActivity {
private PessoaAdapter adapter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new PessoaAdapter(this, Pessoa.getPessoa());
setListAdapter(adapter);
if (!adapter.isEmpty()) {
setContentView(R.layout.tela_principal);
} else {
setContentView(R.layout.cadastro_activity);
}
}
}
===========================================
public class cadastro_activity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cadastro_activity);
}
}
===============================================
Additional code
public class PessoaAdapter extends BaseAdapter {
private List<Pessoa> pessoas;
private LayoutInflater innflater;
public PessoaAdapter(Context context, List<Pessoa> pessoas){
this.pessoas = pessoas;
innflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return pessoas.size();
}
@Override
public Object getItem(int position) {
return pessoas.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return null;
}
}
AndroidManisfest File
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.wlady.personalfinan">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".tela_activity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>