I'm making a simple RSS reader with NavigationDrawer. I've done a Parser class using RssParserSax and a RSS handler. My app crash when I execute the AsynTask. My logcat:
java.lang.NullPointerException
at me.apps.rss.News$LoadXMLTask.onPostExecute(CNews.java:53)
at me.apps.rss.News$LoadXMLTask.onPostExecute(CNews.java:45)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
And my View code. Note that the task only executes when I press the button.
public class News extends android.support.v4.app.Fragment {
private List<whatsnew> news;
private TextView txtresult;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.lay_news, container, false);
Button but = (Button) v.findViewById(R.id.but);
but.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LoadXMLTask task1 = new LoadXMLTask();
task1.execute("http://www.feedforall.com/sample-feed.xml");
}
});
return v;
}
private class LoadXMLTask extends AsyncTask<String, Integer, Boolean> {
protected Boolean doInBackground (String ... params){
RssParserSax saxparser= new RssParserSax(params[0]);
news = saxparser.parse();
return true;
}
protected void onPostExecute (Boolean result){
txtresult.setText("");
for(int i=0; i<news.size(); i++)
{
//nothing
}
}
}
}
txtresult.setText("");
This is the problem, reference is probably null.
Actually, this 2 lines in your stack trace tell you exactly what the problem is:
at me.apps.rss.News$LoadXMLTask.onPostExecute(CNews.java:53)
at me.apps.rss.News$LoadXMLTask.onPostExecute(CNews.java:45)
Lines 45, 53 in CNews.java are the places where Exception is thrown. If you look at this lines you'll know which reference is null.
So the solution is to add inside onCreateView:
txtresult = (TextView) v.findViewById(R.id.your_id);
At the onCreateView you forgot to initialize txtresult field, that is why txtresult.setText(""); gives you a NPE.
In addition to uninitialized txtResult this operation for(int i=0; i<news.size(); i++) is also unsafe because news is not initialized either. I think a better way to utilize your AsyncTask is:
protected Boolean doInBackground (String ... params){
RssParserSax saxparser= new RssParserSax(params[0]);
news = saxparser.parse(); //assuming this doesn't throw exception
if (news != null){
return true;
}
return false;
}
protected void onPostExecute (Boolean result){
if (result){
for (int i =0; i<news.size();i++){...}
txtresult.setText("success");
}else{
txtresult.setText("failed");
}
}
Related
I want override espresso perform(click()) for clicking on specific position. I did it in next way:
public void goToCatgory (int position){
ViewAction categoryClick = new ViewAction() {
#Override
public Matcher<View> getConstraints() {
return null;
}
#Override
public String getDescription() {
return null;
}
#Override
public void perform(UiController uiController, View view) {
RecyclerView categoriesRecycler = (RecyclerView) view;
SimpleBindableAdapter<Category> adapter = (SimpleBindableAdapter<Category>) categoriesRecycler.getAdapter();
int headersCount = adapter.getHeadersCount();
actionOnItemAtPosition(position + headersCount ,click());
}
};
categoryList.perform(categoryClick);
}
When I execute it, I get NullPointerException:
java.lang.NullPointerException
at android.support.test.espresso.core.internal.deps.guava.base.Preconditions.checkNotNull(Preconditions.java:882)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:216)
at android.support.test.espresso.ViewInteraction.access$100(ViewInteraction.java:63)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:153)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:150)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
When I run it in debug, I saw that overrided perform() method don't execute. But I don't understand what I do wrong.
Thanks.
That's because your ViewAction's constraint returns null. Before it performs an action, it checks for its constraint, which should never be null, so try to return a matcher in the constraint:
#Override
public Matcher<View> getConstraints() {
return any(View.class);
}
Maybe you should also return a string to describe the action.
If you think you have got the right position for clicking but it's not working, it's because you have not called the right function to perform:
actionOnItemAtPosition(position + headersCount ,click()).perform(uiController, view);
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I have a SQLite database with two tables: Topic table and Vocab table. I want to display the vocab images when i click on the pictureButton, but the app crashes.
Choice.java
public class Choice extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.choice);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.pictureButton: {
Intent intent = new Intent(Choice.this, Pictureandtext.class);
startActivity(intent);
break;
}
case R.id.textButton: {
break;
}
}
}
}
I get my intent from
this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent intent = new Intent(Smode.this, Choice.class);
intent.putExtra("SelectedTopicId", id);
startActivity(intent);
}
});
This is my getImage() method from the DatabaseAccess.java
public byte[] getImage(int i) {
//byte[] data = null;
String selectImage = "SELECT VocabImage FROM Vocab WHERE VocabTopic =" + i;
Cursor cursor = database.rawQuery(selectImage, null);
if (cursor == null) {
cursor.moveToFirst();
do {
cursor.getBlob(0);
} while (cursor.moveToNext());
}
cursor.close();
return null;
}
Pictureandtext.java
public class Pictureandtext extends AppCompatActivity {
DatabaseAccess databaseAccess = DatabaseAccess.getInstance(this);
protected Cursor cursor;
private ImageView imageView;
private TextView textView;
private int topicId;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pictureandtext);
imageView = (ImageView)findViewById(R.id.imageView);
textView = (TextView)findViewById(R.id.textView);
topicId = getIntent().getIntExtra("SelectedTopicId", 0);
databaseAccess.open();
byte[] data = databaseAccess.getImage(topicId);
Bitmap image = toBitmap(data);
imageView.setImageBitmap(image);
/*String name = databaseAccess.getVocabName(topicId);
textView.setText(name);*/
databaseAccess.close();
}
public static Bitmap toBitmap(byte[] image){
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
}
EDITED!!
I edited some coding and im still getting some error. Your help is much appreciated. Thank you.
FATAL EXCEPTION: main
Process: com.example.user.displayvocab, PID: 29339
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.displayvocab/com.example.user.displayvocab.Pictureandtext}: java.lang.NullPointerException: Attempt to get length of null array
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at com.example.user.displayvocab.Pictureandtext.toBitmap(Pictureandtext.java:47)
at com.example.user.displayvocab.Pictureandtext.onCreate(Pictureandtext.java:38)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
FATAL EXCEPTION: main Process: com.example.user.displayvocab, PID:
24087 java.lang.IllegalStateException: Could not execute method for
android:onClick at
Problem
case R.id.pictureButton: {
setContentView(R.layout.pictureandtext); // Remove this line
............
case R.id.textButton: {
setContentView(R.layout.menu); // Remove this line
break;
}
setContentView->Set the activity content to an explicit view. This
view is placed directly into the activity's view hierarchy.
Why you calling setContentView multiple-time ? Remove this line .You can show DIALOG there .
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to fetch an array from a database on a remote server using the Android Volley library. The problem is that the JSONobject is not returning any data in the onResponse method. When I try to show the data in JSONobject, the application crashes and logcat shows a NullPointerException.
Java code is given below:
public class AudioFragmentThree extends Fragment {
View view;
TextView text;
String url = "http://www.muftiattaullahmultani.com/android/get_all_bayan.php";
int count = 0;
int i = 0;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.audio_fragment_three, container, false);
return view;
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, url, null, new Response.Listener<JSONArray>() {
public void onResponse(JSONArray response) {
while(count<response.length())
{
JSONObject object= null;
try {
object = response.getJSONObject(count);
String s = object.getString("id") +" "+ object.getString("topic");
text.setText(s);
count++;
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
text.setText("ERROR");
}
});
MySingleton.getInstance(getActivity()).addToRequestQueue(jsonArrayRequest);
}
}
LogCat is given below:
FATAL EXCEPTION: main Process: com.example.mashood.muftiattaullahmultanicom, PID: 22596
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at
com.example.mashood.muftiattaullahmultanicom.AudioFragmentThree$1.onResponse(AudioFragmentThree.java:81)
at com.example.mashood.muftiattaullahmultanicom.AudioFragmentThree$1.onResponse(AudioFragmentThree.java:69)
at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Below is my PHP code:
<?PHP include 'database.php';
$query = 'SELECT * FROM audio_bayan ORDER BY no DESC';
$result = $conn->query($query);
$response = array();
while($row = $result->fetch_assoc()) {
array_push($response,array("id"=>$row['no'],"topic"=>$row['topic']));
}
echo json_encode($response);
?>
You have to define textview like below:
Textview text;
text = (TextView) view.findViewById(R.id.textid);
You forget the findViewById your text field add :
text = (TextView) view.findViewById(R.id.text_id);
to your onCreateView method
Looks like your TextView is null.
java.lang.NullPointerException: Attempt to invoke virtual method
'void android.widget.TextView.setText(java.lang.CharSequence)' on a
null object reference
It means you are trying to call setText on a null reference. You have to assign a reference of your TextView from xml layout to the TextView, something like this in onCreateView or onActivityCreated:
TextView text =(TextView) view.findViewById(R.id.text_view);
where, text_view is the id of your TextView in xml.
Im developing a calorie app. The problem I'm having right now is if the user decided to press save without entering anything the app should notify the user they must input something in order to save calorie. The app works when the user does input the proper values of the edit text.
Problem : App crashes when user clicks save button when they havent inputted anything.
logcat.
05-01 12:46:50.294 1810-1810/com.example.treycoco.calorietracker E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.treycoco.calorietracker, PID: 1810
java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:137)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.parseInt(Integer.java:331)
at com.example.treycoco.calorietracker.AddEntry.saveDataToDB(AddEntry.java:100)
at com.example.treycoco.calorietracker.AddEntry$1.onClick(AddEntry.java:79)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
AddEntry.java
public class AddEntry extends Fragment implements
View.OnClickListener {
EditText DescriptionET,CalorieET;
ImageButton Savebtn, Cancelbtn;
String description , calorieAmt;
//database
private DatabaseHandler dba;
public AddEntry() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View myView =
inflater.inflate(R.layout.fragment_add_entry,
container, false);
Savebtn = (ImageButton) myView.findViewById(R.id.SaveBtn);
Savebtn.setBackgroundColor(Color.TRANSPARENT);
Savebtn.setOnClickListener(this);
Cancelbtn = (ImageButton) myView.findViewById(R.id.CancelBtn);
Cancelbtn.setBackgroundColor(Color.TRANSPARENT);
Cancelbtn.setOnClickListener(this);
return myView;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
DescriptionET= (EditText)view.findViewById(R.id.foodEditText);
DescriptionET.setInputType(InputType.TYPE_CLASS_TEXT);
CalorieET=(EditText)view.findViewById(R.id.caloriesEditText);
CalorieET.setInputType(InputType.TYPE_CLASS_NUMBER);
//save to database:
dba = new DatabaseHandler(getContext());
Savebtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
saveDataToDB();
}
});
}
public void saveDataToDB (){
Food food = new Food();
String name = DescriptionET.getText().toString().trim();
String calString = CalorieET.getText().toString().trim();
//convert the claories numbers to text
int cal = Integer.parseInt(calString);
if (DescriptionET.getText().toString().equals("") ||
CalorieET.getText().toString().equals("0")){
Toast.makeText(getActivity(), "Please enter information",
Toast.LENGTH_LONG).show();
}else{
food.setFoodName(name);
food.setCalories(cal);
//call addFood method from the DatabaseHandler
dba.addFood(food);
dba.close();
//clear the editTexts
DescriptionET.setText("");
CalorieET.setText("");
//take the user to the next screen
//
((appMain) getActivity()).loadSelection(0);;
}
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.SaveBtn:
description = DescriptionET.getText().toString();
calorieAmt=CalorieET.getText().toString();
if (DescriptionET.getText().toString().equals("") ||
CalorieET.getText().toString().equals("0")){
Toast.makeText(getActivity(), "Please enter information",
Toast.LENGTH_LONG).show();
}
break;
case R.id.CancelBtn:
EditText descriptionET=
(EditText)getView().findViewById(R.id.foodEditText);
descriptionET.setText("");
EditText calorieET=
(EditText)getView().findViewById(R.id.caloriesEditText);
calorieET.setText("");
break;
}
}
}
Just add a NULL check for the calories value.
if(CalorieET.getText().toString().equals("")
{
Toast.makeText(this,"Please Enter a Value", 3000)show();
}
else
{
//code here to add it to db
}
Actually you set onClickListener of your Savebtn to something else than the function you try to check the sanity of the input, so you need to move your condition checking before you call saveDataToDB.
Change this part of your code:
Savebtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if (DescriptionET.getText().toString().equals("") ||
CalorieET.getText().toString().equals("0") ||
CalorieET.getText().toString().equals("")){
Toast.makeText(getActivity(), "Please enter information",
Toast.LENGTH_LONG).show();
}
else {
saveDataToDB();
}
}
});
if (TextUtils.isEmpty(DescriptionET.getText().toString()) || TextUtils.isEmpty(CalorieET.getText().toString())
{
Toast.makeText(getActivity(), "Please enter information",
Toast.LENGTH_LONG).show();
}
if (!calString.equals("")) {
int cal = Integer.parseInt(calString);
//code for database
;
change your line
if (DescriptionET.getText().toString().equals("") ||
cal==0){
Toast.makeText(getActivity(), "Please enter information",
Toast.LENGTH_LONG).show();
}
I'm trying to create 2 activities, in the first one I'm showing the "nome" and the "tipo_pessoa" in a listview, I want to show the "cargo" in the second activity. As you can see in my parsed Json, I'm using 2 models, my question is, do I need to use 2 adapters in order to do that? here is what I tried so far:
public void parseJson(JSONObject json) throws JSONException {
try {
JSONArray dados = json.getJSONArray("dados");
feedList = new ArrayList<ClientesModel>();
contatoList = new ArrayList<ClientesContatosModel>();
// parsing json object
for (int i = 0; i < dados.length(); i++) {
JSONObject item = dados.getJSONObject(i);
ClientesModel mClientesModel = new ClientesModel();
mClientesModel.setNome(item.optString("nome"));
mClientesModel.setTipo_pessoa(item.optString("tipo_pessoa"));
mClientesModel.setInformacoes_adicionais(item.optString("informacoes_adicionais"));
mClientesModel.setCpf(item.optString("cpf"));
mClientesModel.setCnpj(item.optString("cnpj"));
JSONArray contatos = item.getJSONArray("contatos");
for (int j = 0; j < contatos.length(); j++) {
JSONObject data = contatos.getJSONObject(j);
ClientesContatosModel mClientesContatoModel = new ClientesContatosModel();
contatoList.add(mClientesContatoModel);
mClientesContatoModel.setNomeContato(data.optString("nome"));
mClientesContatoModel.setCargo(data.optString("cargo"));
}
feedList.add(mClientesModel);
System.out.println(contatoList);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
MainActivity:
public void updateList() {
feedListView= (ListView) findViewById(R.id.custom_list);
feedListView.setVisibility(View.VISIBLE);
progressbar.setVisibility(View.GONE);
feedListView.setAdapter(new CustomListAdapter(this, feedList));
feedListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
ntent intent = new Intent(FeedListActivity.this, FeedDetailsActivity.class);
intent.putExtra("data", contatoList);
startActivity(intent);
}
});
}
the second Activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feed_details);
ListView lv = (ListView) findViewById(R.id.listViewContatos);
lv.setAdapter(new ContatosListAdapter(this, contatoList));
feed = (ClientesContatosModel) this.getIntent().getSerializableExtra("data");
TextView title = (TextView) findViewById(R.id.textView);
title.setText(feed.getNomeContato());
}
Now here is my log:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.javatechig.feedreader/com.javatechig.feedreader.FeedDetailsActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.javatechig.feedreader.ContatosListAdapter.getCount(ContatosListAdapter.java:33)
at android.widget.ListView.setAdapter(ListView.java:480)
at com.javatechig.feedreader.FeedDetailsActivity.onCreate(FeedDetailsActivity.java:33)
java line 33 is : lv.setAdapter(new ContatosListAdapter(this, contatoList));
The data from your first activity is not completely passed into the second activity. The error is from contatoList being null, which appears to be populated in the MainActivity, but only the feed data is passed using the intent.
You need to find a way to pass the contatoList data to your second activity as well. One way to do this is to pass your JSON string as an Extra in the second activity launch Intent (if it is not too large) just like you are passing "nome" and re-parse is in the second activity.
You could also store the data using Sqlite or even SharedPreferences.
And if you have two different displays, then you will need two different adapters.
I could solve it:
public void updateList() {
feedListView= (ListView) findViewById(R.id.custom_list);
feedListView.setVisibility(View.VISIBLE);
progressbar.setVisibility(View.GONE);
feedListView.setAdapter(new CustomListAdapter(this, feedList));
final ListView V = (ListView) findViewById(R.id.contato_list);
//V.setVisibility(View.VISIBLE);
V.setAdapter(new ContatosListAdapter(this, contatoList));
feedListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = V.getItemAtPosition(position);
ClientesContatosModel newsData = (ClientesContatosModel) o;
Intent intent = new Intent(FeedListActivity.this, FeedDetailsActivity.class);
intent.putExtra("feed", newsData);
startActivity(intent);
}
});
}