我合并了两个项目并得到以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.game4/com.firstandroidapp.Hackbook}: java.lang.ClassCastException: android.widget.TextView
这是我的代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (APP_ID == null) {
Util.showAlert(this, "Warning", "Facebook Applicaton ID must be "
+ "specified before running this example: see FbAPIs.java");
return;
}
setContentView(R.layout.main);
mHandler = new Handler();
mText = (TextView) Hackbook.this.findViewById(R.id.txt);
mUserPic = (ImageView) Hackbook.this.findViewById(R.id.user_pic);
// Create the Facebook Object using the app id.
Utility.mFacebook = new Facebook(APP_ID);
// Instantiate the asynrunner object for asynchronous api calls.
Utility.mAsyncRunner = new AsyncFacebookRunner(Utility.mFacebook);
mLoginButton = (LoginButton) findViewById(R.id.login);
// restore session if one exists
SessionStore.restore(Utility.mFacebook, this);
SessionEvents.addAuthListener(new FbAPIsAuthListener());
SessionEvents.addLogoutListener(new FbAPIsLogoutListener());
/*
* Source Tag: login_tag
*/
mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions);
if (Utility.mFacebook.isSessionValid()) {
requestUserData();
}
list = (ListView) findViewById(R.id.main_list);
list.setOnItemClickListener(this);
list.setAdapter(new ArrayAdapter<String>(this, R.layout.main_list_item, main_items));
}
这里是logcat错误
03-29 18:35:35.617: E/AndroidRuntime(411): FATAL EXCEPTION: main
03-29 18:35:35.617: E/AndroidRuntime(411): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.game4/com.firstandroidapp.Hackbook}: java.lang.ClassCastException: android.widget.TextView
03-29 18:35:35.617: E/AndroidRuntime(411): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-29 18:35:35.617: E/AndroidRuntime(411): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-29 18:35:35.617: E/AndroidRuntime(411): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-29 18:35:35.617: E/AndroidRuntime(411): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-29 18:35:35.617: E/AndroidRuntime(411): at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 18:35:35.617: E/AndroidRuntime(411): at android.os.Looper.loop(Looper.java:123)
03-29 18:35:35.617: E/AndroidRuntime(411): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-29 18:35:35.617: E/AndroidRuntime(411): at java.lang.reflect.Method.invokeNative(Native Method)
03-29 18:35:35.617: E/AndroidRuntime(411): at java.lang.reflect.Method.invoke(Method.java:507)
03-29 18:35:35.617: E/AndroidRuntime(411): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-29 18:35:35.617: E/AndroidRuntime(411): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-29 18:35:35.617: E/AndroidRuntime(411): at dalvik.system.NativeStart.main(Native Method)
03-29 18:35:35.617: E/AndroidRuntime(411): Caused by: java.lang.ClassCastException: android.widget.TextView
03-29 18:35:35.617: E/AndroidRuntime(411): at com.firstandroidapp.Hackbook.onCreate(Hackbook.java:95)
03-29 18:35:35.617: E/AndroidRuntime(411): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-29 18:35:35.617: E/AndroidRuntime(411): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-29 18:35:35.617: E/AndroidRuntime(411): ... 11 more
03-29 18:35:37.376: I/Process(411): Sending signal. PID: 411 SIG: 9
答案 0 :(得分:0)
这一行中的某些内容可能不是TextView我打赌:R.id.txt
mText = (TextView) Hackbook.this.findViewById(R.id.txt);
检查你的R文件是否有可以在txt下用作TextView的东西,如果是,重新编译重启并查看是否有帮助。