How can i deal with this error need help. i have asked the question before and did all the suggested things but still getting the same error, please anyone tell me that why exactly the error is coming !
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
at android.widget.AbsListView.obtainView(AbsListView.java:2045)
at android.widget.ListView.makeAndAddView(ListView.java:1772)
at android.widget.ListView.fillDown(ListView.java:672)
at android.widget.ListView.fillFromTop(ListView.java:732)
at android.widget.ListView.layoutChildren(ListView.java:1625)
at android.widget.AbsListView.onLayout(AbsListView.java:1875)
at android.view.View.layout(View.java:11390)
at android.view.ViewGroup.layout(ViewGroup.java:4332)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:930)
at android.view.View.layout(View.java:11390)
at android.view.ViewGroup.layout(ViewGroup.java:4332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:444)
at android.view.View.layout(View.java:11390)
at android.view.ViewGroup.layout(ViewGroup.java:4332)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1653)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1511)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1416)
at android.view.View.layout(View.java:11390)
at android.view.ViewGroup.layout(ViewGroup.java:4332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:444)
here is the code
public class Donar_Acceptor_list extends Activity {
// Declare Variables
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ArrayAdapter<String> adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from listview_main.xml
setContentView(R.layout.donar_acceptor_list);
// Execute RemoteDataTask AsyncTask
new RemoteDataTask().execute();
}
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(Donar_Acceptor_list.this);
// Set progressdialog title
mProgressDialog.setTitle("Parse.com Simple ListView Tutorial");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Locate the class table named "Data" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Data");
query.orderByDescending("_created_at");
query.whereEqualTo("DonAcc", "donar");
try {
ob = query.find();
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.list);
// Pass the results into an ArrayAdapter
//adapter = new ArrayAdapter<String>(this,
// android.R.layout.activity_list_item, android.R.id.text1,username);
// Correct one
adapter = new ArrayAdapter<String>(Donar_Acceptor_list.this,
R.layout.donar_aceptor_discription);
// adapter= new ArrayAdapter<String>(this, R.layout.donar_aceptor_discription);
// Retrieve object "name" from Parse.com database
for (ParseObject names : ob) {
adapter.add((String) names.get("username"));
}
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
// Capture button clicks on ListView items
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Send single item click data to SingleItemView Class
Intent i = new Intent(Donar_Acceptor_list.this,
Donar_Acceptor_Discription.class);
// Pass data "name" followed by the position
i.putExtra("username", ob.get(position).getString("username")
.toString());
// Open SingleItemView.java Activity
startActivity(i);
}
}); } } }
for description
public class Donar_Acceptor_Discription extends Activity {
// Declare Variables
TextView txtname;
String username;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from singleitemview.xml
setContentView(R.layout.single_item_view);
// txtname=(TextView) findViewById(R.id.text);
// Retrieve data from MainActivity on item click event
Intent i = getIntent();
// Get the name
username = i.getStringExtra("username");
// Locate the TextView in singleitemview.xml
txtname = (TextView) findViewById(R.id.name);
// Load the text into the TextView
txtname.setText(username);}
}
// layout for donar acceptor description
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5sp"
android:textSize="25sp" >
</TextView>