首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ClassCastException

ClassCastException
EN

Stack Overflow用户
提问于 2013-04-11 19:29:47
回答 1查看 139关注 0票数 0

我已经合并了两个项目,并得到以下错误:

代码语言:javascript
复制
 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.game4/com.firstandroidapp.Hackbook}: java.lang.ClassCastException: android.widget.TextView

以下是我的代码

代码语言:javascript
复制
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错误

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2013-04-11 19:37:39

我敢打赌,这一行中的某些东西可能不是TextView:R.id.txt

代码语言:javascript
复制
 mText = (TextView) Hackbook.this.findViewById(R.id.txt);

检查你的R文件是否有可以在txt下用作TextView的东西,如果有,重新编译重启,看看是否有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15947630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档