I'm trying to populate my listview so
historicos=banco.getAllH();
ArrayAdapter<HistoricoObjeto> itens = new ArrayAdapter<HistoricoObjeto>(this,
android.R.layout.simple_list_item_1, historicos);
this.lista.setAdapter(itens);
this.lista.setClickable(true);
registerForContextMenu(lista);
More is giving null pointer exception error in this line
this.lista.setAdapter(itens);
I'm going to put the HistoticoObjeto class to be clearer what and the object I use
public class HistoricoObjeto implements Serializable{
private String id;
public String datahora;
public String mensagem;
public HistoricoObjeto() {
}
public HistoricoObjeto(String id, String datahora, String mensagem) {
super();
this.setId(id);
this.setDatahora(datahora);
this.setMensagem(mensagem);
}
}
Can anyone tell me where I'm going wrong?
11-25 12:22:02.809: E/AndroidRuntime(11457): FATAL EXCEPTION: main
11-25 12:22:02.809: E/AndroidRuntime(11457): java.lang.RuntimeException: Unable to resume activity {com.ilgner.chegouahora/com.ilgner.chegouahora.Historico}: java.lang.NullPointerException
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2124)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.os.Looper.loop(Looper.java:130)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-25 12:22:02.809: E/AndroidRuntime(11457): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 12:22:02.809: E/AndroidRuntime(11457): at java.lang.reflect.Method.invoke(Method.java:507)
11-25 12:22:02.809: E/AndroidRuntime(11457): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-25 12:22:02.809: E/AndroidRuntime(11457): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-25 12:22:02.809: E/AndroidRuntime(11457): at dalvik.system.NativeStart.main(Native Method)
11-25 12:22:02.809: E/AndroidRuntime(11457): Caused by: java.lang.NullPointerException
11-25 12:22:02.809: E/AndroidRuntime(11457): at com.ilgner.chegouahora.Historico.onResume(Historico.java:62)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.Activity.performResume(Activity.java:3832)
11-25 12:22:02.809: E/AndroidRuntime(11457): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)
11-25 12:22:02.809: E/AndroidRuntime(11457): ... 12 more
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_historico);
this.lista = (ListView)findViewById(R.id.lvContatos);
this.banco = new Banco(getApplicationContext());
HistoricoObjeto historico = new HistoricoObjeto();
brCollator = Collator.getInstance(new Locale("pt", "BR"));
}
@Override
protected void onResume() {
super.onResume();
historicos=banco.getAllH();
historicos=ordena(brCollator, historicos);
ArrayAdapter<HistoricoObjeto> itens = new ArrayAdapter<HistoricoObjeto>(this,
android.R.layout.simple_list_item_1, historicos){
@Override
public View getView (int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
// Como o simple_list_item_1 retorna um TextView, esse cast pode ser feito sem problemas
((TextView) view).setTextColor(Color.BLACK);
return view;
}};
Log.e("", ""+itens.getCount());
this.lista.setAdapter(itens);
this.lista.setClickable(true);
registerForContextMenu(lista);
}
Strange stopped this error there, and I did not do anything, but I used this code there in another list, but it was with Historico it was with a class Person that had a name, and phone there in the list, but now I'm not sure how to make one of the variables appear in the list, the history class has a date and time and a message I wanted to make the two or one