I am trying to integrate facebook to my Android application. When i added internet permission in the project and have generated App_ID but when I put facebook files in to my project it gives these errors as shown in pic.
Now should I remove #Override or am I missing something.
If I put this code into my OnCreate method it also gives errors to remove #Override.
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() {}
});
Should I include facebook.apk if yes then Where to add this? please help
I followed many tutorials but could not resolve these errors.
This is most likely because you are switching between Java 1.5 and Java 1.6. In 1.5 you couldn't mark interface implementations with #Override, but you can in 1.6.
#Override annotation error (android prefs)
Bug with Override annotations in Eclipse
Related
I'm trying to integrate DynamoDB into a mobile app I'm developing using Android Studio and Kotlin. I've been following the AWS instructions for Android SDK 2.0 outlined here: https://aws-amplify.github.io/docs/sdk/android/start
The instructions are in Java, which I'm not very familiar with. I've been able to get things to work until step 5, which involves integrating the AWS AppSync client into the onCreate() method in my application. I tried to copy and paste the code into Android Studio, which then tries to convert the Java code to Kotlin, but I'm getting a lot of errors. Are there any Java/Kotlin experts out there that might be able to convert the following code to Kotlin for me?
private AWSAppSyncClient mAWSAppSyncClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAWSAppSyncClient = AWSAppSyncClient.builder()
.context(getApplicationContext())
.awsConfiguration(new AWSConfiguration(getApplicationContext()))
.build();
}
And
public void runMutation(){
CreateTodoInput createTodoInput = CreateTodoInput.builder().
name("Use AppSync").
description("Realtime and Offline").
build();
mAWSAppSyncClient.mutate(CreateTodoMutation.builder().input(createTodoInput).build())
.enqueue(mutationCallback);
}
private GraphQLCall.Callback<CreateTodoMutation.Data> mutationCallback = new GraphQLCall.Callback<CreateTodoMutation.Data>() {
#Override
public void onResponse(#Nonnull Response<CreateTodoMutation.Data> response) {
Log.i("Results", "Added Todo");
}
#Override
public void onFailure(#Nonnull ApolloException e) {
Log.e("Error", e.toString());
}
};
I haven't found many resources on integrating DynamoDB in an AndroidStudio Kotlin project, so if there are better ways of doing this, I'd love to hear them.
I am trying to (at least partially) determine when an application gets closed by the user to release some connections, etc. To do this, I am using the ProcessLifecycleOwner with my application class implementing LifecycleObserver. Despite taking the starting code from tutorials and other helpful articles, it does not seem to detect any lifecycle events.
Most of the code came from this example.
My application class:
public class App extends Application implements LifecycleObserver {
#Override
public void onCreate() {
super.onCreate();
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
}
#OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
public void created() {
Log.d("SampleLifeCycle", "ON_CREATE");
}
#OnLifecycleEvent(Lifecycle.Event.ON_START)
public void started() {
Log.d("SampleLifeCycle", "ON_START");
}
#OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void resumed() {
Log.d("SampleLifeCycle", "ON_RESUME");
}
#OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void paused() {
Log.d("SampleLifeCycle", "ON_PAUSE");
}
#OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void stopped() {
Log.d("SampleLifeCycle", "ON_STOP");
}
}
The dependency in Gradle
dependencies {
//...
implementation 'android.arch.lifecycle:extensions:1.1.1'
}
So far, this code has not logged a single event of any sort, whether the app is entering the foreground or the background.
EDIT
Note: You NEED to declare your application in the Manifest for anything to work in your custom application class.
You need the corresponding annotation processor to pay attention to those annotations:
annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'
Or, enable Java 8 support, and switch to DefaultLifecycleObserver.
MainActivity cannot be converted to LifecycleOwner
I used this as LiveCycle Owner, but it is rejected and I got an error as you see in the picture.
I work on Api 25 and I this the problem may be related to this version
This is info about my sdk
compileSdkVersion 25
buildToolsVersion '25.0.2'
This is my code:
private void retrieveTasks() {
Log.d(TAG, "Actively retrieving the tasks from the DataBase");
// Extract all this logic outside the Executor and remove the Executor
// Fix compile issue by wrapping the return type with LiveData
LiveData<List<TaskEntry>> tasks = mDb.taskDao().loadAllTasks();
// Observe tasks and move the logic from runOnUiThread to onChanged
tasks.observe(this, new Observer<List<TaskEntry>>() {
#Override
public void onChanged(#Nullable List<TaskEntry> taskEntries) {
Log.d(TAG, "Receiving database update from LiveData");
mAdapter.setTasks(taskEntries);
}
});
}
I put LiveData dependencies in my Gradle
compile "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
If anyone knows the reason for the problem, let me know please
Fragments and Activities in Support Library 26.1.0 and later already implement the LifecycleOwner interface by default
but in version 25 you need to implement LifecycleOwner interface
for example
public class MyActivity extends Activity implements LifecycleOwner {
private LifecycleRegistry mLifecycleRegistry;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLifecycleRegistry = new LifecycleRegistry(this);
mLifecycleRegistry.markState(Lifecycle.State.CREATED);
}
#Override
public void onStart() {
super.onStart();
mLifecycleRegistry.markState(Lifecycle.State.STARTED);
}
#NonNull
#Override
public Lifecycle getLifecycle() {
return mLifecycleRegistry;
}
}
Source : Handling lifecycles with lifecycle-aware components
As you can read here the LifecycleOwner was added in support library 26.1.0. Easiest way to fix your issue would be upgrading your support library version.
Had the same error. Upgrading to androidx support libraries fixed the issue.
Choose inside Android Studio: Refactor -> Migrate to android x
I wrote some code to get data from Firebase, but it shows some errors. I will explain the errors below and attach a picture.
First error when I put the mouse on it, message show:
'onStart()' in 'com.abdullrahman.eng.myapp.FriendsFragment' clashes with 'onStart()' in 'android.app.Fragment'; attempting to assign weaker access privileges ('protected'); was 'public'
Second error when I put the mouse on it, message show:
Method does not override method from its superclass
Can anyone solve these problems and help me?
The code:
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Friends, FriendsViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Friends, FriendsViewHolder>(
Friends.class,
R.layout.users_single_layout,
FriendsViewHolder.class,
mUsersDatabase
) {
#Override
protected void populateViewHolder(FriendsViewHolder friendsViewHolder, Friends friends, int position) {
friendsViewHolder.setDisplayName(friends.getName());
friendsViewHolder.setUserStatus(friends.getStatus());
friendsViewHolder.setUserImage(friends.getThumb_image(), mMainView.getContext());
final String user_id = getRef(position).getKey();
friendsViewHolder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent profileIntent = new Intent(getActivity(), UserProfile.class);
profileIntent.putExtra("user_id", user_id);
startActivity(profileIntent);
}
});
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}
Errors do say a lot about the problem you have.
The first error is caused by protected access modifier on the onStart() method, while it should be public.
It should be
#Override
public void onStart() {
super.onStart();
// rest of the code
}
instead of
#Override
protected void onStart() {
super.onStart();
// rest of the code
}
You can find some more information about the error reason in docs available on Oracle site.
The second problem is related to the definition of FirebaseRecyclerAdapter. Looks like there is no method like
protected void populateViewHolder(FriendsViewHolder friendsViewHolder, Friends friends, int position).
I'd suggest checking docs/sources of this class to get info about how the override method should look for the version of Firebase you are using in your project.
Also, as I can see you are using IntelliJ IDEA or some similar IDE, so you can use built-in feature to implement/override the correct method.
Change your protected modifier to public and it'll go away.
In Java, the overriding method can have the same or weaker access compared to the parent method... Here the parent class declares the method as public so you have no other choice but to override it with a public access modifier as it's the weakest access possible.
Error:
Class 'Anonymous class derived from AdListener' must either be declared abstract or implement abstract method 'onLoggingImpressionMethod(Ad)' in 'AdListener'
Here is my code:
private void setUpFacebookAD() {
//AdSettings.addTestDevice("ae869b4a0e40ebbea07dafaabd9690aa");
mFBNativeAd = new NativeAd(context, "xxxxxxxxxxxxxxx_xxxxxxxxxxxxxxx");
mFBNativeAd.setAdListener(new com.facebook.ads.AdListener() {
#Override
public void onError(Ad ad, AdError error) {
// Ad error callback
Log.i("fb native ad","on Error" + " "+ error.getErrorMessage());
}
#Override
public void onAdLoaded(Ad ad) {
// Ad loaded callback
Log.i("FB native ad ", "On Ad loaded");
notifyDataSetChanged();
}
#Override
public void onAdClicked(Ad ad) {
// Ad clicked callback
Log.i("FB natvie Ad" , "onAd clicked");
}
});
mFBNativeAd.loadAd(NativeAd.MediaCacheFlag.ALL);
}
The com.facebook.ads.AdListener is red color underlined. I tried reduced it to AdListener only but still getting error. It only happened after I upgraded the jdk version and the location of JDK. Before the upgrade the code is working. How can I get it to work?
The error message tells you exactly what you must do to fix the problem: implement a method with the signature 'onLoggingImpressionMethod(Ad). If you move the caret to the line that says new com.facebook.ads.AdListener(), you can press Alt-Enter and select from the popup menu to automatically insert this method for you.