Formatting errors - issues with code formation - java

I have experienced various minor errors with forming my code, and is having difficulty resolving them.
In particular, I have the following line underline with the following message
query.findInBackground(new FindCallback<ParseObject>() {
The method findInBackground(FindCallback<ParseUser>) in the type ParseQuery<ParseUser> is not applicable for the arguments (new FindCallback<ParseObject>(){})
As well as errors closing my statements.
and finally
Below is the complete code
Any help would be greatly appreciated. Thanks in advance
Update:
Updated code
public class Fragment1 extends Fragment {
public interface Constants {
String LOG = "com.dooba.beta";
}
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ArrayList<String> age;
private ArrayList<String> headline;
private ArrayList<String> activityname;
private ArrayList<Images> alProfilePicture;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber(
"Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString(
"Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container,
false);
return view;
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
age = new ArrayList<String>();
headline = new ArrayList<String>();
activityname = new ArrayList<String>();
alProfilePicture = new ArrayList<Images>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
Log.d(Constants.LOG, "");
ParseQuery<ParseObject> queryo = ParseQuery.getQuery("User");
queryo.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
queryo.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
queryo.whereEqualTo("Looking_Gender", userGender);
queryo.setLimit(1);
queryo.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
queryo.orderByDescending("Name");
queryo.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> object, ParseException e) {
// TODO Auto-generated method stub
ParseFile image = object.getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView()
.findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to
// be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(
R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length
+ ", or exception: " + e.getMessage());
}
}};
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistname, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistname.size(); i++) {
names.add(userlistname.get(i).get("Name").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
names);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done1(List<ParseUser> userlistheadline, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistheadline.size(); i++) {
headline.add(userlistheadline.get(i).get("Headline")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistheadline);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_all,
headline);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done2(List<ParseUser> userlistage, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistage.size(); i++) {
age.add(userlistage.get(i).get("Age").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistage);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
age);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done3(List<ParseUser> userlistactivity, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistactivity.size(); i++) {
activityname.add(userlistactivity.get(i)
.get("ActivityName").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistactivityname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
activityname);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity()
.getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user", Toast.LENGTH_SHORT)
.show();
}
}
});
}
}
Update 2
a few formating issues such as
1) object cannot be resolved
public class Fragment1 extends Fragment {
public interface Constants {
String LOG = "com.dooba.beta";
}
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ArrayList<String> age;
private ArrayList<String> headline;
private ArrayList<String> activityname;
private ArrayList<Images> alProfilePicture;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber(
"Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString(
"Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container,
false);
return view;
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
age = new ArrayList<String>();
headline = new ArrayList<String>();
activityname = new ArrayList<String>();
alProfilePicture = new ArrayList<Images>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
Log.d(Constants.LOG, "");
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> users,ParseException e) {
// Do whatever you need to extract object from "users"
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
ParseFile image = object.getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView().findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
}
});
}
});
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistname, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistname.size(); i++) {
names.add(userlistname.get(i).get("Name").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
names);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistheadline, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistheadline.size(); i++) {
headline.add(userlistheadline.get(i).get("Headline")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistheadline);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_all,
headline);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done2(List<ParseUser> userlistage, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistage.size(); i++) {
age.add(userlistage.get(i).get("Age").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistage);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
age);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done3(List<ParseUser> userlistactivity, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistactivity.size(); i++) {
activityname.add(userlistactivity.get(i)
.get("ActivityName").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistactivityname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
activityname);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity()
.getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user", Toast.LENGTH_SHORT)
.show();
}
}
});
}
}

This should be a start:
public class Fragment1 extends Fragment
{
public interface Constants
{
String LOG = "com.dooba.beta";
}
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ArrayList<String> age;
private ArrayList<String> headline;
private ArrayList<String> activityname;
private ArrayList<Images> alProfilePicture;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser()
.getString("Gender");
String activityName = ParseUser.getCurrentUser()
.getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser()
.getNumber("Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser()
.getString("Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser()
.getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser()
.getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser()
.getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment1_layout, container,
false);
return view;
}
private void setConversationsList()
{
currentUserId = ParseUser.getCurrentUser()
.getObjectId();
names = new ArrayList<String>();
age = new ArrayList<String>();
headline = new ArrayList<String>();
activityname = new ArrayList<String>();
alProfilePicture = new ArrayList<Images>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
Log.d(Constants.LOG, "");
ParseQuery<ParseObject> queryo = ParseQuery.getQuery("User");
queryo.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
queryo.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
queryo.whereEqualTo("Looking_Gender", userGender);
queryo.setLimit(1);
queryo.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
queryo.orderByDescending("Name");
queryo.findInBackground(new FindCallback<ParseObject>()
{
#Override
public void done(List<ParseObject> object, ParseException e)
{
// TODO Auto-generated method stub
ParseFile image = object.getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView()
.findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to
// be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(
R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback()
{
#Override
public void done(byte[] data, ParseException e)
{
Log.i("ParseImageView",
"Fetched! Data length: " + data.length
+ ", or exception: " + e.getMessage());
}
});
}
query.findInBackground(new FindCallback<ParseUser>()
{
public void done (List < ParseUser > userlistname, ParseException e)
{
if(e == null)
{
for(int i = 0; i < userlistname.size(); i++)
{
names.add(userlistname.get(i)
.get("Name")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
names);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l)
{
openConversation(names, i);
}
});
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
public void done1(List<ParseUser> userlistheadline, ParseException e)
{
if(e == null)
{
for(int i = 0; i < userlistheadline.size(); i++)
{
headline.add(userlistheadline.get(i)
.get("Headline")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistheadline);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_all,
headline);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l)
{
openConversation(names, i);
}
});
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done2(List<ParseUser> userlistage, ParseException e)
{
if(e == null)
{
for(int i = 0; i < userlistage.size(); i++)
{
age.add(userlistage.get(i)
.get("Age")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistage);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
age);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l)
{
openConversation(names, i);
}
});
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done3(List<ParseUser> userlistactivity, ParseException e)
{
if(e == null)
{
for(int i = 0; i < userlistactivity.size(); i++)
{
activityname.add(userlistactivity.get(i)
.get("ActivityName")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistactivityname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
activityname);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l)
{
openConversation(names, i);
}
});
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos)
{
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>()
{
public void done(List<ParseUser> user, ParseException e)
{
if(e == null)
{
Intent intent = new Intent(getActivity()
.getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0)
.getObjectId());
startActivity(intent);
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user", Toast.LENGTH_SHORT)
.show();
}
}
});
}
}

Related

Attempt to invoke interface method 'int org.ksoap2.serialization.KvmSerializable.getPropertyCount()' on a null object reference

i have a school project. It was built by some previous developer. I am trying to run it. But i am getting NullPointerException. Here is my code:
private boolean isNetworkAvailable()
{
ConnectivityManager connectivityManager=(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo=connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo !=null && activeNetworkInfo.isConnected();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
setToolbar();
new AsyncTask<Void,Void,Void>(){
#Override
protected void onPreExecute() {
super.onPreExecute();
dialog=new ProgressDialog(RegistrationActivity.this);
dialog.setMessage("Loading...");
dialog.show();
}
#Override
protected Void doInBackground(Void... params) {
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE1,OPERATION_NAME1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS1);
httpTransport.debug=true;
try {
httpTransport.call(SOAP_ACTION1, envelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
try {
response= envelope.getResponse();
Log.e("response: ", response.toString() + "");
} catch (SoapFault soapFault) {
soapFault.printStackTrace();
Log.e("response: ", response.toString() + "");
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
dialog.dismiss();
try {
Log.e("response: ", response.toString() + "");
}catch(Exception e){
e.printStackTrace();
Toast.makeText(RegistrationActivity.this,response.toString()+"",Toast.LENGTH_LONG).show();
}
StringTokenizer tokens = new StringTokenizer(response.toString(), "=");
List<String> mylist=new ArrayList<String>();
for(int i=0;tokens.hasMoreTokens();i++){
StringTokenizer tokens1 = new StringTokenizer(tokens.nextToken(), ";");
mylist.add(tokens1.nextToken());
}
mylist.remove(0);
int partitionSize =1;
List<List<String>> partitions = new LinkedList<List<String>>();
for (int i = 0; i < mylist.size(); i += partitionSize) {
partitions.add(mylist.subList(i,
i + Math.min(partitionSize, mylist.size() - i)));
}
city=new ArrayList<String>();
for(int k=0;k<partitions.size();k++){
city.add(partitions.get(k).get(0));
}
callGetArea();
}
}.execute();
spcity= (Spinner) findViewById(R.id.spcity);
spcity.setOnItemSelectedListener(this);
sparea = (Spinner) findViewById(R.id.sparea);
sparea.setOnItemSelectedListener(this);
dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
rg = (RadioGroup) findViewById(R.id.gendergroup);
name= (EditText) findViewById(R.id.fname);
address=(EditText)findViewById(R.id.address);
contact= (EditText) findViewById(R.id.contact);
email= (EditText) findViewById(R.id.email);
weight= (EditText) findViewById(R.id.weight);
password= (EditText) findViewById(R.id.password);
cpass= (EditText) findViewById(R.id.cpassword);
earea= (Spinner) findViewById(R.id.sparea);
ecity= (Spinner) findViewById(R.id.spcity);
btnContinue= (TextView)findViewById(R.id.btncont);
bdate = (EditText) findViewById(R.id.bdate);
bdate.setInputType(InputType.TYPE_NULL);
bdate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDateTimeField();
fromDatePickerDialog.show();
}
});
btnContinue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (isEmptyField(name)) {
Toast.makeText(RegistrationActivity.this, "Please Enter Name", Toast.LENGTH_LONG).show();
} else if (isEmptyField(bdate)) {
Toast.makeText(RegistrationActivity.this, "Please Select Birthdate", Toast.LENGTH_LONG).show();
} else if (isEmptyField(address)) {
Toast.makeText(RegistrationActivity.this, "Please Enter Address", Toast.LENGTH_LONG).show();
} else if (isEmptyField(weight)) {
Toast.makeText(RegistrationActivity.this, "Please Enter Weight", Toast.LENGTH_LONG).show();
} else if (isEmptyField(contact)) {
Toast.makeText(RegistrationActivity.this, "Please Enter Contact", Toast.LENGTH_LONG).show();
} else if (isEmptyField(email)) {
Toast.makeText(RegistrationActivity.this, "Please Enter E-Mail", Toast.LENGTH_LONG).show();
}else if (!isEmailPattern(email)) {
Toast.makeText(RegistrationActivity.this, "Please Enter Valid E-Mail", Toast.LENGTH_LONG).show();
}else if (isEmptyField(password)) {
Toast.makeText(RegistrationActivity.this, "Please Enter Password", Toast.LENGTH_LONG).show();
} else if (isEmptyField(cpass)) {
Toast.makeText(RegistrationActivity.this, "Please Confirm Password", Toast.LENGTH_LONG).show();
} else if (!isPasswordMatch(cpass,password)) {
Toast.makeText(RegistrationActivity.this, "Password doesn't match", Toast.LENGTH_LONG).show();
}
else {
if(isNetworkAvailable()) {
new AsyncTask<Void, Void, Void>() {
#Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(RegistrationActivity.this);
dialog.setMessage("Loading...");
dialog.show();
}
#Override
protected Void doInBackground(Void... params) {
resp = loginCall(email.getText().toString().trim());
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Log.e("Response", resp + "");
dialog.dismiss();
if (resp == 1) {
UserClass userClass = new UserClass();
userClass.name = name.getText().toString();
userClass.dob = bdate.getText().toString();
int selectedId = rg.getCheckedRadioButtonId();
RadioButton radioButton = (RadioButton) findViewById(selectedId);
userClass.gender = radioButton.getText().toString();
userClass.address = address.getText().toString();
userClass.city = city.get(ecity.getSelectedItemPosition());
userClass.area = area.get(earea.getSelectedItemPosition()).city;
userClass.weight = weight.getText().toString();
userClass.contact = contact.getText().toString();
userClass.email = email.getText().toString();
userClass.password = password.getText().toString();
Log.e("name", userClass.name + "");
Log.e("dob", userClass.dob + "");
Log.e("gender", userClass.gender + "");
Log.e("address", userClass.address + "");
Log.e("city", userClass.city + "");
Log.e("area", userClass.area + "");
Log.e("weight", userClass.weight + "");
Log.e("contact", userClass.contact + "");
Log.e("email", userClass.email + "");
Log.e("password", userClass.password + "");
PrefUtils.setCurrentUser(userClass, RegistrationActivity.this);
Intent intent = new Intent(RegistrationActivity.this, RegistrationActivity2.class);
startActivity(intent);
finish();
} else {
Toast.makeText(getApplicationContext(), "Email Already Exist", Toast.LENGTH_LONG).show();
}
}
}.execute();
}
else
{
Toast.makeText(RegistrationActivity.this, "Check Your Internet Connection", Toast.LENGTH_LONG).show();
}
}
}
});
}
public void onDateSet(DatePicker view, int year, int month, int day) {
Calendar userAge = new GregorianCalendar(year,month,day);
Calendar minAdultAge = new GregorianCalendar();
minAdultAge.add(Calendar.YEAR, -18);
if (minAdultAge.before(userAge))
{
Toast.makeText(RegistrationActivity.this,"Please enter valid date",Toast.LENGTH_LONG).show();
}
}
private void callGetArea() {
new AsyncTask<Void,Void,Void>(){
#Override
protected void onPreExecute() {
super.onPreExecute();
dialog=new ProgressDialog(RegistrationActivity.this);
dialog.setMessage("Loading...");
dialog.show();
}
#Override
protected Void doInBackground(Void... params) {
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE2,OPERATION_NAME2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS2);
httpTransport.debug=true;
try {
httpTransport.call(SOAP_ACTION2, envelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
try {
response= envelope.getResponse();
Log.e("response: ", response.toString() + "");
} catch (SoapFault soapFault) {
soapFault.printStackTrace();
Log.e("response: ", response.toString() + "");
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
dialog.dismiss();
try {
Log.e("response: ", response.toString() + "");
}catch(Exception e){
e.printStackTrace();
Toast.makeText(RegistrationActivity.this,response.toString()+"",Toast.LENGTH_LONG).show();
}
StringTokenizer tokens = new StringTokenizer(response.toString(), "=");
List<String> mylist=new ArrayList<String>();
for(int i=0;tokens.hasMoreTokens();i++){
StringTokenizer tokens1 = new StringTokenizer(tokens.nextToken(), ";");
mylist.add(tokens1.nextToken());
}
mylist.remove(0);
final int partitionSize =2;
List<List<String>> partitions = new LinkedList<List<String>>();
for (int i = 0; i < mylist.size(); i += partitionSize) {
partitions.add(mylist.subList(i,
i + Math.min(partitionSize, mylist.size() - i)));
}
area=new ArrayList<Area>();
for(int k=0;k<partitions.size();k++){
area.add(new Area(partitions.get(k).get(0),partitions.get(k).get(1)));
}
TimeSpinnerAdapter1 tspcity=new TimeSpinnerAdapter1(RegistrationActivity.this,city);
spcity.setAdapter(tspcity);
spcity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
ArrayList<Area> tempList=new ArrayList<Area>();
for(int i=0;i<area.size();i++){
Log.e("city............",area.get(i).area+"");
if(area.get(i).area.equalsIgnoreCase(city.get(position))){
tempList.add(area.get(i));
}
}
TimeSpinnerAdapter tsparea = new TimeSpinnerAdapter(RegistrationActivity.this, tempList);
sparea.setAdapter(tsparea);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}.execute();
}
private void setDateTimeField() {
Calendar newCalendar = Calendar.getInstance();
fromDatePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar userAge = new GregorianCalendar(year,monthOfYear,dayOfMonth);
Calendar minAdultAge = new GregorianCalendar();
minAdultAge.add(Calendar.YEAR, -18);
if (minAdultAge.before(userAge))
{
Toast.makeText(RegistrationActivity.this,"Please Enter Valid Date",Toast.LENGTH_LONG).show();
} else {
bdate.setText(dateFormatter.format(userAge.getTime()));
}
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
}
public boolean isEmptyField(EditText param1) {
boolean isEmpty = false;
if (param1.getText() == null || param1.getText().toString().equalsIgnoreCase("")) {
isEmpty = true;
}
return isEmpty;
}
private void setToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setTitle("Register");
setSupportActionBar(toolbar);
}
}
#Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
public class TimeSpinnerAdapter extends BaseAdapter implements SpinnerAdapter {
private final Context activity;
private ArrayList<Area> asr;
public TimeSpinnerAdapter(Context context,ArrayList<Area> asr) {
this.asr=asr;
activity = context;
}
public int getCount()
{
return asr.size();
}
public Object getItem(int i)
{
return asr.get(i);
}
public long getItemId(int i)
{
return (long)i;
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView txt = new TextView(RegistrationActivity.this);
txt.setPadding(16,16,16,16);
txt.setTextSize(16);
txt.setGravity(Gravity.CENTER_VERTICAL);
txt.setText(asr.get(position).city);
txt.setTextColor(Color.parseColor("#494949"));
return txt;
}
public View getView(int i, View view, ViewGroup viewgroup) {
TextView txt = new TextView(RegistrationActivity.this);
txt.setGravity(Gravity.CENTER_VERTICAL);
txt.setPadding(16,16,16,16);
txt.setTextSize(16);
txt.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_spinner, 0);
txt.setText(asr.get(i).city);
txt.setTextColor(Color.parseColor("#ffffff"));
return txt;
}
}
public static boolean isEmailPattern(EditText param1) {
Pattern pattern = Patterns.EMAIL_ADDRESS;
return pattern.matcher(param1.getText().toString()).matches();
}
public static boolean isPasswordMatch(EditText param1, EditText param2) {
boolean isMatch = false;
if (param1.getText().toString().equals(param2.getText().toString())) {
isMatch = true;
}
return isMatch;
}
public class TimeSpinnerAdapter1 extends BaseAdapter implements SpinnerAdapter {
private final Context activity;
private ArrayList<String> asr;
public TimeSpinnerAdapter1(Context context,ArrayList<String> asr) {
this.asr=asr;
activity = context;
}
public int getCount()
{
return asr.size();
}
public Object getItem(int i)
{
return asr.get(i);
}
public long getItemId(int i)
{
return (long)i;
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView txt = new TextView(RegistrationActivity.this);
txt.setPadding(16,16,16,16);
txt.setTextSize(16);
txt.setGravity(Gravity.CENTER_VERTICAL);
txt.setText(asr.get(position));
txt.setTextColor(Color.parseColor("#494949"));
return txt;
}
public View getView(int i, View view, ViewGroup viewgroup) {
TextView txt = new TextView(RegistrationActivity.this);
txt.setGravity(Gravity.CENTER_VERTICAL);
txt.setPadding(16,16,16,16);
txt.setTextSize(16);
txt.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_spinner, 0);
txt.setText(asr.get(i));
txt.setTextColor(Color.parseColor("#ffffff"));
return txt;
}
}
public int loginCall(String c1)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo p1=new PropertyInfo();
p1.setName("email");
p1.setValue(c1);
p1.setType(String.class);
request.addProperty(p1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.debug=true;
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception ex)
{
// ex.printStackTrace();
Toast.makeText(getApplicationContext(),"error",Toast.LENGTH_LONG).show();
//displayExceptionMessage(ex.getMessage());
//System.out.println(exception.getMessage());
}
return Integer.parseInt(response.toString());
}
I am getting NullPointerException on response= envelope.getResponse();
My error is following:
Process: com.nkdroid.blooddonation, PID: 16820
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int org.ksoap2.serialization.KvmSerializable.getPropertyCount()' on a null object reference
at org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerializationEnvelope.java:513)
at com.nkdroid.blooddonation.RegistrationActivity$1.doInBackground(RegistrationActivity.java:146)
at com.nkdroid.blooddonation.RegistrationActivity$1.doInBackground(RegistrationActivity.java:120)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
Can anyone help me with that?
I know code is a mess. But any help will be appreciated.
Thanks! :)
Make sure you have the same name as property in your service and android parameters, for example request.addProperty("name",name) in the WebService public class Login(String name)

How can I connect to a specific wifi network?

I have devlope project to list out all wifi connection available near to my device.Now, I want to connect any one specific network connection.
SO what can I do? I have got all networks in listview.
If any example available then post comment link.
private void getWifiNetworksList() {
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
final WifiManager wifiManager = (WifiManager) getApplicationContext()
.getSystemService(Context.WIFI_SERVICE);
;
registerReceiver(new BroadcastReceiver() {
#SuppressLint("UseValueOf")
#Override
public void onReceive(Context context, Intent intent) {
sb = new StringBuilder();
scanList = wifiManager.getScanResults();
sb.append("\n Number Of Wifi connections :" + " "
+ scanList.size() + "\n\n");
adapter = new ArrayAdapter<String>(DraginoActivity.this,
android.R.layout.simple_list_item_1, list);
adapter.clear();
for (int i = 0; i < scanList.size(); i++) {
listWifiDevice.setAdapter(adapter);
// list.add(new Integer(i + 1).toString() + ". ");
list.add((new Integer(i + 1).toString() + ". ")
+ (scanList.get(i)).toString().substring(5,
(scanList.get(i)).toString().indexOf(",")));
// list.add("\n\n");
listWifiDevice.setAdapter(adapter);
adapter.notifyDataSetChanged();
listWifiDevice
.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
TextView tv = (TextView) arg1;
// TODO Auto-generated method stub
Toast.makeText(DraginoActivity.this,
"" + tv.getText().toString(), 1000)
.show();
}
});
}
// listWifiDevice.setAdapter(adapter);
}
}, filter);
wifiManager.startScan();
}
private void setNetworksList() {
networksList = (ListView) findViewById(R.id.networkList);
networksList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position,
long id) {
final int chosenPosition = position;
WiFiItem wifiItem = new WiFiItem();
wifiItem = (WiFiItem) parent.getItemAtPosition(position);
networkSSID = wifiItem.getSSID();
networkPass = "";
showPasswordDialog(ConnectActivity.this);
setPasswordListener(new PasswordTypedListener() {
#Override
public void onPasswordTyped() {
connectHelper = new ConnectHelper();
if(scanResult.get(chosenPosition).capabilities.contains("WEP")) {
connectHelper.setupConnection(networkSSID, networkPass, "WEP");
}
//jezeli siec WPA
else if(scanResult.get(chosenPosition).capabilities.contains("WPA")) {
connectHelper.setupConnection(networkSSID, networkPass, "WPA");
}
//inne przypadki (open network)
else {
connectHelper.setupConnection(networkSSID, networkPass, "ELSE");
}
wifiManager.addNetwork(connectHelper.getConfiguration());
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
if(wifiManager.reconnect()) {
for(int j=0;j<listWifi.size();j++){
listWifi.get(j).setConnected(false);
}
runnableCounter=0;
handler.postDelayed(ifConnected,1000);
}
break;
}
}
}
});
}
});
}
and also dialog
private void showPasswordDialog(Context context) {
final EditText input = new EditText(context);
input.setSingleLine();
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("PASSWORD");
alert.setView(input);
alert.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
networkPass = input.getText().toString();
if(ConnectActivity.this.passwordListener != null)
ConnectActivity.this.passwordListener.onPasswordTyped();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
alert.show();
}
and in onCreate but you could skip creating WifiItems and just store SSIDs
ArrayList<WiFiItem> listWifi = new ArrayList<WiFiItem>();
wifiManager.startScan();
scanResult = wifiManager.getScanResults();
for(ScanResult sc : scanResult) {
WiFiItem wifiItem = new WiFiItem();
wifiItem.setSSID(sc.SSID);
wifiItem.setBSSID(sc.BSSID);
listWifi.add(wifiItem);
}

Issue working with parse - object cannot be resolved

I am trying to populate a page with information about user such name, age and profile picture from parse. In attempting so, I have encountered some issues such as:
Along with formatting errors such as
, I am encountering the following issue:
1) object cannot be resolved
public class Fragment1 extends Fragment {
public interface Constants {
String LOG = "com.dooba.beta";
}
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ArrayList<String> age;
private ArrayList<String> headline;
private ArrayList<String> activityname;
private ArrayList<Images> alProfilePicture;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber(
"Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString(
"Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container,
false);
return view;
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
age = new ArrayList<String>();
headline = new ArrayList<String>();
activityname = new ArrayList<String>();
alProfilePicture = new ArrayList<Images>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
Log.d(Constants.LOG, "");
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> users,ParseException e) {
// Do whatever you need to extract object from "users"
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
ParseFile image = object.getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView().findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
}
});
}
});
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistname, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistname.size(); i++) {
names.add(userlistname.get(i).get("Name").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
names);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistheadline, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistheadline.size(); i++) {
headline.add(userlistheadline.get(i).get("Headline")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistheadline);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_all,
headline);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done2(List<ParseUser> userlistage, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistage.size(); i++) {
age.add(userlistage.get(i).get("Age").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistage);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
age);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done3(List<ParseUser> userlistactivity, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistactivity.size(); i++) {
activityname.add(userlistactivity.get(i)
.get("ActivityName").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistactivityname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
activityname);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity()
.getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user", Toast.LENGTH_SHORT)
.show();
}
}
});
}
}
Update
I have added another picture
You didn't post enough code to show where the missing or extra bracket is. Just go through your code carefully, work your way outward, collapsing methods etc as you go.
I think you should have something like below to iterate over the list:
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseObject> objects,ParseException e) {
for(int i=0;i<objects.size();i++){
// Do whatever you need to extract object from "users"
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
ParseFile image = objects.get(i).getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView().findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
}
});
}
}//for loop
});

Retrieving files on Parse - Images

I have already managed to store image files into parse. My question lies in retrieving it. In the sense that in the registration process users are asked to upload a profile picture, and where the image is later stored into parse as an image. My issue lies in retrieving it, where along with pulling information like name, headline, age for a potential match, I also want to be able to retrieve the picture.
Below is the code, where I retrieve string information, but where I would want to retrieve files as well.
public class MatchingActivity extends Activity {
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber("Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString("Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matching);
logoutButton = (Button) findViewById(R.id.logoutButton);
logoutButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ParseUser.logOut();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
}
});
setConversationsList();
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
query.whereGreaterThanOrEqualTo("Minimum_Age", minimumAge).whereGreaterThanOrEqualTo("Age", userage);
query.whereLessThanOrEqualTo("Maximum_Age", maximumAge).whereLessThanOrEqualTo("Age", userage);
// query.whereWithinKilometers("Maximum_Distance", point, maxDistance)
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).get("Name").toString());
names.add(userList.get(i).get("Headline").toString());
names.add(userList.get(i).get("Age").toString());
// names.add(userList.get(i).getParseObject("ProfilePicture").;
}
usersListView = (ListView)findViewById(R.id.usersListView);
namesArrayAdapter =
new ArrayAdapter<String>(getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);
usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
If you have any question, if like it.
Update
Image code
ParseFile image = (ParseFile) userData.getParseFile("ProfilePicture");
//call the function
displayImage(image, image_expert);
//and here is the function
private void displayImage(ParseFile thumbnail, final ImageView img) {
if (thumbnail != null) {
thumbnail.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
data.length);
if (bmp != null) {
Log.e("parse file ok", " null");
img.setImageBitmap(Bitmap.createScaledBitmap(bmp,
(display.getWidth() / 5),
(display.getWidth() /50), false));
img.setImageBitmap(getRoundedCornerBitmap(bmp, 10));
img.setPadding(10, 10, 0, 0);
}
} else {
Log.e("paser after downloade", " null");
}
}
});
} else {
Log.e("parse file", " null");
// img.setImageResource(R.drawable.ic_launcher);
img.setPadding(10, 10, 10, 10);
}
}
names.add(userList.get(i).get("Age").toString());
names.add(userList.get(i).get("ActivityName").toString());
// names.add(userList.get(i).getParseObject("ProfilePicture").;
}
activity code
public class Fragment1 extends Fragment {
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber("Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString("Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container, false);
return view;
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
//query.whereGreaterThanOrEqualTo("Age", minimumAge);
//query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).get("Name").toString());
names.add(userList.get(i).get("Headline").toString());
ParseFile image = (ParseFile) userData.getParseFile("ProfilePicture");
//call the function
displayImage(image, image_expert);
//and here is the function
private void displayImage(ParseFile thumbnail, final ImageView img) {
if (thumbnail != null) {
thumbnail.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
data.length);
if (bmp != null) {
Log.e("parse file ok", " null");
img.setImageBitmap(Bitmap.createScaledBitmap(bmp,
(display.getWidth() / 5),
(display.getWidth() /50), false));
img.setImageBitmap(getRoundedCornerBitmap(bmp, 10));
img.setPadding(10, 10, 0, 0);
}
} else {
Log.e("paser after downloade", " null");
}
}
});
} else {
Log.e("parse file", " null");
// img.setImageResource(R.drawable.ic_launcher);
img.setPadding(10, 10, 10, 10);
}
}
names.add(userList.get(i).get("Age").toString());
names.add(userList.get(i).get("ActivityName").toString());
// names.add(userList.get(i).getParseObject("ProfilePicture").;
}
usersListView = (ListView)getActivity().findViewById(R.id.userlistview);
namesArrayAdapter =
new ArrayAdapter<String>(getActivity().getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);
usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity().getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Issues on the following line
private void displayImage(ParseFile thumbnail, final ImageView img) {
Multiple markers at this line
- Syntax error on token ",", ;
expected
- Syntax error on token "(", ;
expected
- Syntax error on token ")", ;
expected
see if something like below would help:
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.fetchInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
ParseFile file = (ParseFile)object.get("image");
if(file != null){
file.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
if(bitmap != null){
imageAccount.setImageBitmap(bitmap);
}else{
Log.d(TAG, "file null?");
}
} else {
Log.d(TAG, "ParseFile ParseException: " + e.toString());
}
}
});
}else{
Log.d(TAG, "ParseFile is null");
}
} else {
Log.d(TAG, "ParseException: " + e.toString());
}
}
});
When you store a pointer to type 'file' in parse, u get a URL and a name .
Anytime you have reference to the file, you should be able to also get the URL.
Use the URL to do an async get and to generate a local bitmap for using the photo in a view.

Parse whereEqualTo

I am trying to retrieve information from parse. In particular, I have added a condition where it would only return the list of users that have selected the same activity.
I have tried the below code, but it does seem to work, as that condition returns an empty list.
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo("objectId", currentUserId);
query.whereEqualTo("ActivityName","");
It would essentially see which users have selected that particular activity name and return
Below is the entire code
public class MatchingActivity extends Activity {
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matching);
logoutButton = (Button) findViewById(R.id.logoutButton);
logoutButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ParseUser.logOut();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
}
});
setConversationsList();
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo("objectId", currentUserId);
query.whereEqualTo("ActivityName",userActivitySelectionName);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).getUsername().toString());
}
usersListView = (ListView)findViewById(R.id.usersListView);
namesArrayAdapter =
new ArrayAdapter<String>(getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);
usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Thanks in advance.
Double-check in the Data Browser, but I'm guessing that the column has "undefined" instead of an empty string.
In this case you'll need to use the following:
query.whereDoesNotExist("ActivityName");
The whereDoesNotExist() and whereExists() functions are for checking if there is any value set on a column.

Categories

Resources