0
我不知道爲什麼它顯示「應用程序不幸停止」的錯誤。我看到了DDMS會話,它所說的是「找不到appcompat_v7.apk!」應用程序已不幸停止(Facebook登錄)
的mainactivity.java是:
包com.example.iwashere;
import java.io.IOException;
import java.net.MalformedURLException;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
public class MainActivity extends ActionBarActivity implements OnClickListener {
Facebook fb;
ImageView button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String facebook_app_id = getString (R.string.facebook_app_id);
fb = new Facebook (facebook_app_id);
button = (ImageView)findViewById(R.id.login);
button.setOnClickListener(this);
updateButtonImage();
}
private void updateButtonImage() {
// TODO Auto-generated method stub
if(fb.isSessionValid())
{
button.setImageResource(R.id.logout);
} else{
button.setImageResource(R.id.login);
}
}
@Override
public void onClick(View v)
{
if(fb.isSessionValid()){
//button close our session - logout of facebook
try {
fb.logout(getApplicationContext());
updateButtonImage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
//login to facebook
fb.authorize(this, new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
@Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
@Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
}
});
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
fb.authorizeCallback(requestCode, resultCode, data);
}
}
和xml是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.iwashere.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textColor="#FFFF"/>
<ImageView
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login" />
<ImageView
android:id="@+id/logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logout"
android:visibility="invisible"/>
</RelativeLayout>
可以請你發佈logcat嗎? – 2014-11-21 11:53:55
它停止了什麼動作?請澄清 – 2014-11-21 11:59:44
如果您在創建新項目時有新的android adtbundle,則在您使用舊版本時自動創建的android comp v7意味着它不支持嘗試更新您的版本,那麼它會自動生成 – 2014-11-21 12:43:09