Getting errors while following facebook's mobile app guide - facebook

When I type this into my class:
package com.greatap;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.android.*;
import com.facebook.android.Facebook.*;
public class MyGreatActivity extends Activity {
Facebook facebook = new Facebook("YOUR_APP_ID");
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
facebook.authorize(this, new DialogListener() {
#Override
public void onComplete(Bundle values) {}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
}
I get these errors:
FacebookError cannot be resolved to a type,
Syntax error on token "*", delete this token,
The import com.facebook.android.Facebook cannot be resolved,
The method onCancel() of type new DialogListener(){} must override a superclass method,
The method onComplete(Bundle) of type new DialogListener(){} must override a superclass method,
Facebook cannot be resolved to a type,
DialogListener cannot be resolved to a type,
DialogError cannot be resolved to a type.
If anyone could please help me find out what I did wrong, I would appreciate it! Thanks in advance!

change project preference to use Java 1.6 instead of 1.5. This error is because of using Java 1.5.
link: 'Must Override a Superclass Method' Errors after importing a project into Eclipse

Related

How to inject ResourceInfo in javax.servlet.Filter

I am trying to register time metrics based on the service method but not able to inject ResourceInfo.
I want to write some generic logic to register the time based on the service.
Here is my code:
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.ws.rs.container.ResourceInfo;
#WebFilter("/*")
public class MetricsGeneraterFilter implements Filter {
#Context
private ResourceInfo resourceInfo;
#Override
public void destroy() {
}
#Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
long startTime = System.currentTimeMillis();
chain.doFilter(request, response);
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println(resourceInfo.getResourceMethod().getName() + "--->" + elapsedTime);
}
#Override
public void init(FilterConfig filterConfig) throws ServletException {
}
}
How to inject ResourceInfo in javax.servlet.Filter?
I've used ContainerRequestFilter and ContainerResponseFilter to solve for this problem.
ContainerRequestFilter:
#Provider
public class RequestContextLoggingFilter implements ContainerRequestFilter{
public static final String REQUEST_START_TIME = "REQUEST_START_TIME";
#Override
public void filter(ContainerRequestContext requestContext) throws IOException {
requestContext.setProperty(REQUEST_START_TIME, Instant.now());
}
}
ContainerResponseFilter:
#Provider
#Priority(Priorities.USER)
public class ResponseLogFilter implements ContainerResponseFilter{
private Logger logger = LoggerFactory.getLogger(ResponseLogFilter.class);
#Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
try {
Instant end = Instant.now();
Instant start = (Instant) requestContext.getProperty(RequestContextLoggingFilter.REQUEST_START_TIME);
logger.info("Done executing request with request_execution_time={} ms",
Duration.between(start, end).toMillis());
}catch (Exception e){
logger.warn("error logging response time", e);
}
}
}
You can also use Jersey's Monitoring and Diagnostics module: https://jersey.github.io/documentation/latest/monitoring_tracing.html.
I haven't used it in production applications as it is in beta as of release >2.1
Try using a JAX-RS Filter instead. These operate just like Servlet filters but better as they are within the bounds of JAX-RS and can do many things that a Servlet Filters can't.
In order to do so, just make that class implement ContainerResponseFilter and ContainerRequestContext, and add it to your JAX-RS application (I.e. add the #Provider annotation or add it to your web.xml). Then implement the two methods. You can store the startTime in the RequestContext object's parameters.
I will edit this with a link to my own filter that does exactly this when I get a chance.

How to call a class from another activity?

I want to call MainActivity class to another activity. This is my code for the MainActivity.java:
package com.blinkedup.geolocationchat;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.app.Service;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
TextView textView;
LocationManager locationManager;
MyLocationListener locationListener = new MyLocationListener();
Criteria criteria;
String bestProvider;
String listOfBestProviders;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
criteria = new Criteria();
textView = (TextView) findViewById(R.id.textView1);
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
locationManager = (LocationManager) getSystemService(Service.LOCATION_SERVICE);
//locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
bestProvider = locationManager.getBestProvider(criteria, true);
Toast.makeText(getApplicationContext(), bestProvider, 3).show();
}
protected void onPause(){
super.onPause();
locationManager.removeUpdates(locationListener);
}
private class MyLocationListener implements LocationListener{
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
textView.setText("Latitude: " + location.getLatitude() +
"Longitude: " + location.getLongitude());
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
In another activity I wanted to call the lat and long of the above code but don't want to rewrite the code to the activity. I just want to call it and display the result in another activity. please help. thanks
make your variable static and define it before onCreate() method use that variable in another activity by call like this.
YourMainActivity.yourstaticvariable

Customized itemreader throwing ReaderNotOpenException

I have a customized item reader as shown below
class MyReader implements ItemReader<MyBean>, ItemStream{
SingleItemPeekableItemReader<MyBean> myBeanPeekableReader;
public SingleItemPeekableItemReader<MyBean> getMyBeanPeekableReader() {
return myBeanPeekableReader;
}
public void setMyBeanPeekableReader(
SingleItemPeekableItemReader<MyBean> myBeanPeekableReader) {
this.myBeanPeekableReader = myBeanPeekableReader;
}
#Resource
public void caller(ItemReader<MyBean> myJdbcReader){
myBeanPeekableReader.setDelegate(myJdbcReader);
}
#Override
public void close() throws ItemStreamException {
myBeanPeekableReader.close();
}
#Override
public void open(ExecutionContext arg0) throws ItemStreamException {
myBeanPeekableReader.open(arg0);
}
#Override
public void update(ExecutionContext arg0) throws ItemStreamException {
// TODO Auto-generated method stub
}
Class extending JdbcCursorItemReader:
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.springframework.batch.item.database.JdbcCursorItemReader;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
#Component("myJdbcReader")
public class MyJdbcReader extends JdbcCursorItemReader<MyBean> {
private String sql = "Select * from mytable";
MyJdbcReader(){
super.setSql(sql);
}
#Override
#Resource
public void setDataSource(DataSource dataSource){
super.setDataSource(dataSource);
}
#Override
#Resource
public void setRowMapper(RowMapper myRowMapper){
super.setRowMapper(myRowMapper);
}
#Override
#Resource
public void setPreparedStatementSetter(PreparedStatementSetter myPrepSetter){
super.setPreparedStatementSetter(myPrepSetter);
}
}
Even after implementing ItemStream it is throwing exception ReaderNotFound..can someone suggest where I am getting wrong.

How to list all classes in autocompletion inside annotations in Intellij IDEA?

I have custom class InternalTimerServiceController in my application. I want to use it in another class inside android annotations. And it seems that autocompletion does not work correctly in this case.
I have this interface
public interface InternalTimerServiceControllerContract
{
void doWork();
}
And this class
#EBean
public class InternalTimerServiceController implements InternalTimerServiceControllerContract
{
#Override
public void doWork()
{
// do work
}
}
And this is my Activity
public class MyActivity extends Activity
{
// try uncomment line below and see if autocomplete works properly
//#Bean(Internal)
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
It's a bug, thanks for reporting. I've created a ticket for it: http://youtrack.jetbrains.com/issue/IDEA-98298

GWT - Manage a boolean method in the RPC configuration

I have make my own method in the RPC schema by using the GWT framework. Now, i need to add another method.
So, i wrote this code for each part of RPC :
package org.sinfonet.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
#RemoteServiceRelativePath("gwtservice")
public interface GWTService extends RemoteService {
public String checkLogin(String nickname, String password);
public boolean anotherFunction(String nickname);
}
#########################################################
package org.sinfonet.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface GWTServiceAsync {
public void checkLogin(String nickname, String password, AsyncCallback<String> callback);
public void anotherFunction(String nickname, AsyncCallback<java.lang.Boolean> asyncCallback);
}
#########################################################
package org.sinfonet.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.util.ArrayList;
import org.sinfonet.client.GWTService;
import org.sinfonet.mgmt.Configuration;
import org.sinfonet.mgmt.Database;
public class GWTServiceImpl extends RemoteServiceServlet implements GWTService {
public String checkLogin(String nickname, String password) {
Database mydb=Configuration.getDatabase();
mydb.connetti();
// faccio md5 ed escape
String log_check_user=nickname;
String log_check_pass=password;
// controllo che l'utente esista
ArrayList<String[]> db_result=null;
db_result=mydb.selectQuery("SELECT nickname FROM users WHERE nickname='"+log_check_user+"' AND password='"+log_check_pass+"'");
if(db_result.size()!=0) {
return "YES";
}
// sconnessione al database
mydb.disconnetti();
return "NO";
}
public boolean anotherFunction(String nickname) {
// somethings others
return true;
}
}
#########################################################
final AsyncCallback<java.lang.Boolean> callCheckLogin = new AsyncCallback<java.lang.Boolean>() {
public void onSuccess(boolean result) {
if(result) {
designLogout(menu_login_label1.getText());
} else {
menu_err.setText("Username e password non validi");
}
}
};
// Listen for the button clicks
menu_login_button.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
// Make remote call. Control flow will continue immediately and later
// 'callback' will be invoked when the RPC completes.
getService().anotherFunction(menu_login_input1.getText(), callCheckLogin);
}
});
as you can see, i added the anotherFunction() method (boolean), but Netbeans says to me that i need to implements all abracts method about allCheckLogin, but i wont do it :) How can I fix this problem?
So Netbeans complains about the missing onFailure method, right? If you don't want to implement that method every time, write yourself an abstract class like:
public abstract class BaseAsyncCallback<T> implements AsyncCallback<T> {
#Override
public void onFailure(Throwable caught) {
// Perform generic failure handling
}
}
Then you can change your code into:
final AsyncCallback<java.lang.Boolean> callCheckLogin =
new BaseAsyncCallback<java.lang.Boolean>() {
public void onSuccess(java.lang.Boolean result) {
...
}
};
Now you don't need to implement onFailure anymore, except if you need to perform additional error handling.