i don't know what's wrong with my code. As long as i know my code is right, but i still got java.lang.null.pointer in
friendPickerFragment.loadData(false);
i already defined friendPickerFragment like this but still, i got error
friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);
Here is my whole code and i think it's the same as facebook sdk sample friendpicker
public class PickFriends extends FragmentActivity {
FriendPickerFragment friendPickerFragment;
public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar){
intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY,userId);
intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect);
intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY,showTitleBar);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pick_friends);
FragmentManager fragmentManager = getSupportFragmentManager();
if(savedInstanceState == null){
final Bundle args = getIntent().getExtras();
friendPickerFragment = new FriendPickerFragment(args);
fragmentManager.beginTransaction()
.add(R.id.friend_picker_fragment, friendPickerFragment);
//friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);
} else {
friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);
}
friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
#Override
public void onError(PickerFragment<?> fragment, FacebookException error) {
PickFriends.this.onError(error);
}
});
friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
#Override
public void onDoneButtonClicked(PickerFragment<?> fragment) {
SelectFriend application = (SelectFriend) getApplication();
application.setSelectedUsers(friendPickerFragment.getSelection());
setResult(RESULT_OK,null);
finish();
}
});
}
private void onError(Exception error){
String text = "Error Exception";
Toast toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
toast.show();
}
#Override
protected void onStart(){
super.onStart();
friendPickerFragment.loadData(false);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_pick_friends, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Please help me. Thank you
Related
I can post to Facebook using their sharDialog() pop-up. However, if I want to post a set message on a button click, without having the dialog pop up, how do I go about doing that?
public class MainActivity extends AppCompatActivity {
private ShareDialog share;
private ShareLinkContent content;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
content = new ShareLinkContent.Builder().setContentTitle("CURRENT LOCATION").build();
share = new ShareDialog(this);
ImageButton fbBut = (ImageButton) findViewById(R.id.facebook_button);
fbBut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
share.show(content);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
//Opens the settings preferences
Intent settings = new Intent(MainActivity.this, SettingsActivity.class);
MainActivity.this.startActivity(settings);
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onResume() {
super.onResume();
// Logs 'install' and 'app activate' App Events.
AppEventsLogger.activateApp(this);
}
#Override
protected void onPause() {
super.onPause();
// Logs 'app deactivate' App Event.
AppEventsLogger.deactivateApp(this);
}
}
This is the code that I have so far.
So I am new to parse and I am trying to implement a simple login feature.
I am using this code
ParseUser newUser = new ParseUser();
newUser.setUsername(userName);
newUser.setPassword(passwordFirst);
newUser.signUpInBackground(new SignUpCallback() {
#Override
public void done(com.parse.ParseException e) {
if (e == null) {
AppUtils.toast(getApplicationContext(),"SUCCESS");
finish();
} else {
AppUtils.log(e.toString());
}
}
});
This code does create the user which i can see on the browser but it does not save the password so I can never log in. What could be the problem ? any suggestions?
As I said, the user is created in the browser but the password field remains undefined(un edited) so I can not log in.
Thanks.
EDIT:
EditText editText_userName;
EditText editText_passwordFirst;
EditText editText_passwordSecond;
CheckBox checkBox_terms;
Button button_signUp;
Button button_cancel;
String userName;
String passwordFirst;
String passwordSecond;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity__sign_up);
//UI INIT
editText_userName=(EditText)findViewById(R.id.editText_username);
editText_passwordFirst=(EditText)findViewById(R.id.editText_passwordFirst);
editText_passwordSecond=(EditText)findViewById(R.id.editText_passwordSecond);
button_signUp = (Button)findViewById(R.id.button_signup);
button_cancel = (Button)findViewById(R.id.button_cancel);
checkBox_terms = (CheckBox)findViewById(R.id.checkBox_acceptTerms);
button_signUp.setOnClickListener(this);
button_cancel.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_activity__sign_up, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button_signup:
passwordFirst = editText_passwordFirst.getText().toString();
passwordSecond = editText_passwordSecond.getText().toString();
userName = editText_userName.getText().toString().trim();
if(!passwordFirst.equals(passwordSecond)){
AppUtils.toast(getApplicationContext(),"Passwords do not match");
break;
}
if(!checkBox_terms.isChecked()) {
AppUtils.toast(getApplicationContext(),"Terms have not been accepted");
break;
}
ParseUser newUser = new ParseUser();
newUser.setUsername(userName);
newUser.setPassword(passwordFirst);
newUser.signUpInBackground(new SignUpCallback() {
#Override
public void done(com.parse.ParseException e) {
if (e == null) {
AppUtils.toast(getApplicationContext(),"SUCCESS");
finish();
} else {
AppUtils.log(e.toString());
}
}
});
// this.finish();
break;
case R.id.button_cancel:
this.finish();
break;
case R.id.button_showTerms:
break;
}
}
}
I have a Fragment that interfaces OnWeekViewClickListener as such:
public interface OnWeekViewClickListener {
// TODO: Update argument type and name
public void onWeekViewClick();
}
I assign the listener during the onAttach method as such:
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = activity;
try {
mListener = (OnWeekViewClickListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
yet my Activity that implements OnWeekViewClickListener never receives a call back? Nor any errors?
Here is that activity:
public class RoomDetailsActivity extends FragmentActivity implements RoomAmenityHorizontalViewer.OnFragmentInteractionListener, DayScheduleViewer.OnWeekViewClickListener {
private RoomAmenityHorizontalViewer amenityFrag = RoomAmenityHorizontalViewer.newInstance();
private DayScheduleViewer dayFrag = DayScheduleViewer.newInstance();
private FrameLayout dayViewFrame;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(getWindow().FEATURE_NO_TITLE);
setContentView(R.layout.detail_view_info);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.room_amenity_spinner_view, amenityFrag, "amenityFrag");
transaction.replace(R.id.room_dayview_layout, dayFrag, "dayFrag");
transaction.commit();
ImageButton backButton = (ImageButton) findViewById(R.id.roomDetailsBackBtn);
backButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myBackIntent = new Intent(getBaseContext(), ProximityActivity.class);
startActivity(myBackIntent);
}
});
RoundedImageView pinOverlay = (RoundedImageView) findViewById(R.id.imageView4);
ImageView roomImage = (ImageView) findViewById(R.id.roomImageView);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_room_details, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onWeekViewClick() {
Log.v("Fragment Interaction", "Fragment item touched!");
}
#Override
public void onFragmentInteraction(Uri uri) {
}
}
Here the fragment is calling the listener:
myWeekView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mListener.onWeekViewClick();
}
});
I am enable to set one of the ActionBar menu items as an icon and show it as "showAsAction="always" all I am getting is the overflow menu and a the title of the button instead of the icon. I don't understand what I am doing wrong?
this is the code in the activity:
public class RecipientsActivity extends ListActivity {
private static final String TAG = RecipientsActivity.class.getSimpleName();
protected List<ParseUser> mFriends;
protected ParseUser mCurrentUser;
protected MenuItem mSendMenuItem;
protected ParseRelation<ParseUser> mFriendsRelation;
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipients);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public void onResume() {
super.onResume();
mCurrentUser = ParseUser.getCurrentUser();
mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
setProgressBarIndeterminateVisibility(true);
ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
query.addAscendingOrder(ParseConstants.KEY_USERNAME);
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> friends, ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
mFriends = friends;
String[] friendNames = new String[mFriends.size()];
int i = 0;
for (ParseUser friend : mFriends) {
friendNames[i] = friend.getUsername();
i++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(RecipientsActivity.this,
android.R.layout.simple_list_item_checked,
friendNames);
setListAdapter(adapter);
} else {
Log.e(TAG, e.getMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext());
//e.getMesssage = says useful information about the error
builder.setMessage(e.getMessage());
builder.setTitle(R.string.error_title);
builder.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_recipients, menu);
mSendMenuItem = menu.getItem(0);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_send) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
mSendMenuItem.setVisible(true);
}
Your activity is ListActivity. That means that you are using the native API Level 11+ implementation of the action bar, not the appcompat-v7 backport.
Hence, change app:showAsAction to android:showAsAction.
I have an activity which has an edit text which becomes visible when a button is clicked. I fill the edit text up and click another button. On clicking this button the edit text content must be sent to another activity.The first activity takes the edit text and queries a list of data from my Parse database and shows it in a ListView in the Second Activity.But whenever i click the first button(after entering the string) the app crashes.This is the first activity
public class MainActivity extends ActionBarActivity {
String name;
EditText search;
Button g;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpSpinners();
Parse.initialize(this, "AAh5US7zhbYyFBexsv07cjo34ZZiB7KNe9SuTv7e",
"eKUG1pYaV50hVyDC9d4qZc4qf1dCtOTqnX92eGJV");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation();
search = (EditText) findViewById(R.id.search);
g = (Button) findViewById(R.id.Go);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void byName(View v) {
search.setVisibility(View.VISIBLE);
search.requestFocus();
g.setVisibility(View.VISIBLE);
}
public void Go(View v) {
name = search.getText().toString();
final Intent i;
i = new Intent(MainActivity.this, ResterauntList1.class);
i.putExtra("restrauntName", name);
startActivity(i);
}
}
In the above byName is the onClick for making the EditText visible, and Go is the onClick for getting my EditText string and passing it to the next activity. The second activity is below
public class ResterauntList1 extends Activity {
String rValue;
ArrayAdapter<String> adapter;
ProgressDialog mProgressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resteraunt_list1);
Bundle bdl = getIntent().getExtras();
rValue = bdl.getString("restrauntName");
setContentView(R.layout.activity_resteraunt_list);
populateList(rValue, "name");
}
private void populateList(final String Value, final String Key) {
ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() {
#Override
#SuppressWarnings({ "unchecked", "rawtypes" })
public ParseQuery create() {
ParseQuery query = new ParseQuery("resdb");
query.whereEqualTo(Key, Value);
return query;
}
};
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(
this, factory);
adapter.setTextKey("name");
adapter.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {
#Override
public void onLoading() {
mProgressDialog = new ProgressDialog(ResterauntList1.this);
mProgressDialog.setTitle("Searching for " + Value);
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
#Override
public void onLoaded(List<ParseObject> objects, Exception e) {
mProgressDialog.dismiss();
}
});
final ListView listView = (ListView) findViewById(R.id.restListView1);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ParseObject object = (ParseObject) listView
.getItemAtPosition(position);
String Id = object.getObjectId();
Intent i = new Intent(getApplicationContext(),
SingleRestraunt.class);
i.putExtra("restId", Id);
startActivity(i);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.resteraunt_list1, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
The error as stated above occurs when I click the Go button.The error is
09-02 14:58:46.443: E/AndroidRuntime(3061): Process: com.example.gastronomaapp, PID: 3061
09-02 14:58:46.443: E/AndroidRuntime(3061): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gastronomaapp/com.example.gastronomaapp.ResterauntList1}: java.lang.NullPointerException
Any idea where I am making a mistake? The funniest thing almost the same code has worked in another part of my app. absolutely clueless whats wrong.
Bundle bdl = getIntent().getExtras();
rValue = bdl.getString("restrauntName");
change to
rValue = getIntent().getStringExtra("restrauntName");
You put the string directly on the intent, not packaged in a bundle.