Hallo Leute
wir entwickeln zur Zeit mit Eclipse eine App für unsere Schule. Hier bin ich für die Facebook-Integration zuständig. Dabei habe ich folgenden Guide benutzt: Android Probleme bei Facebook Integration - java-forum.org
Leider zeigt mir Eclipse nach kopieren der Codes verschiedene Fehler an.
Hier erstmal der gesamte Code der relevanten Klasse:
package pu.app;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.facebook.android.*;
import com.facebook.android.Facebook.*;
public class GymTriStart extends Activity{
Facebook facebook = new Facebook("pu.app");
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:string']String[/url] FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url] kalender;
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url] vertretung;
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url] anfahrt;
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url] raumplan;
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url] kalender = ([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url])findViewById(R.id.kalender);
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url] vertretung = ([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url])findViewById(R.id.vertretung);
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url] anfahrt = ([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url])findViewById(R.id.anfahrt);
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url] raumplan = ([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:button']Button[/url])findViewById(R.id.raumplan);
kalender.setOnClickListener(menu);
vertretung.setOnClickListener(menu);
anfahrt.setOnClickListener(menu);
raumplan.setOnClickListener(menu);
facebook.authorize(this, new DialogListener() {
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onComplete(Bundle values) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onFacebookError(FacebookError error) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onError(DialogError e) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onCancel() {}
});
facebook.authorize(this, new [url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:string']String[/url][] { "email", "publish_checkins" },
new DialogListener() {
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onComplete(Bundle values) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onFacebookError(FacebookError error) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onError(DialogError e) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onCancel() {}
}
);}
mPrefs = getPreferences(MODE_PRIVATE);
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:string']String[/url] access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null) {
facebook.setAccessToken(access_token);
}
if(expires != 0) {
facebook.setAccessExpires(expires);
}
/*
* Only call authorize if the access_token has expired.
*/
if(!facebook.isSessionValid()) {
facebook.authorize(this, new [url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:string']String[/url][] {}, new DialogListener() {
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onFacebookError(FacebookError error) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onError(DialogError e) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onCancel() {}
});
}
};
public OnClickListener menu = new OnClickListener()
{
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onClick([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:view']View[/url] v)
{
Intent intent;
switch (v.getId())
{
case R.id.kalender: intent = new Intent(GymTriStart.this, kalender.class); break;
case R.id.vertretung: intent = new Intent(GymTriStart.this, vertretung.class); break;
case R.id.anfahrt: intent = new Intent(GymTriStart.this, anfahrt.class); break;
case R.id.raumplan: intent = new Intent(GymTriStart.this, raumplan.class); break;
default: intent = new Intent (GymTriStart.this, GymTriStart.class);
}
startActivity(intent);
}
};
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
mAsyncRunner.logout(getContext(), new RequestListener() {
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onComplete([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:string']String[/url] response, [url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:object']Object[/url] state) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onIOException([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:ioexception']IOException[/url] e, [url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:object']Object[/url] state) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onFileNotFoundException([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:filenotfoundexception']FileNotFoundException[/url] e,
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:object']Object[/url] state) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onMalformedURLException([url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:malformedurlexception']MalformedURLException[/url] e,
[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:object']Object[/url] state) {}
@[url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:override']Override[/url]
public void onFacebookError(FacebookError e, [url='http://www.google.de/search?btnI&q=site:docs.oracle.com/javase/7/docs/api/%20inurl:object']Object[/url] state) {}
});
}
Alles anzeigen
Wie man sieht sind auch Teile unserer App enthalten, die aber alle funktionieren. Im Facebook Code markiert er folgende Fehler:
1.)Bei Schritt 6.6 soll man wieder einiges an Code einfügen. Ich habe alles eingefügt, allerdings meldet Eclipse Fehler in der Codezeile mPrefs = getPreferences(MODE_PRIVATE); .
Bei "getPreferences" sagt Eclipse "Return type for the method is missing"
Als Fixes bietet er "set method return type to void" und "change to constructor", wobei beides nicht geholfen hat.
Bei "MODE_PRIVATE" kommt der Fehler "MODE_PRIVATE cannot be resolved to a type".
Als Fixes schlägt er hier beispielsweise "create class/interface/enum" und "add type parameter MODE_PRIVATE to 'Name meiner Klasse'" vor.
2.) Bei Schritt 7 bekomme ich in der Zeile mAsyncRunner.logout(getContext(), new RequestListener() { ebenfalls den Fehler "Return type for the method is missing".
Ich hoffe Ihr könnt mir helfen und freue mich über schnelle Lösungsvorschläge, da wir nicht mehr lange Zeit haben.