Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6822341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:39:07+00:00 2026-05-26T21:39:07+00:00

I’ve been basing this code off the Bluetooth Chat example. It worked when it

  • 0

I’ve been basing this code off the Bluetooth Chat example. It worked when it was listview and now am trying to display this as textview and doesn’t work at all now.

I’ve only made minor changes to the code just to display the message recevied and not been able to send message back. These are getting rid of all write methods.

This is the orignal code

private void setupChat() {
    Log.d(TAG, "setupChat()");

    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
    mConversationView = (ListView) findViewById(R.id.in);
    mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    mOutEditText = (EditText) findViewById(R.id.edit_text_out);
    mOutEditText.setOnEditorActionListener(mWriteListener);

    // Initialize the send button with a listener that for click events
    mSendButton = (Button) findViewById(R.id.button_send);
    mSendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            TextView view = (TextView) findViewById(R.id.edit_text_out);
            String message = view.getText().toString();
            sendMessage(message);
        }
    });

    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(this, mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}

This is what I changed it to.

 private void setupChat() 
{
    Log.d(TAG, "setupChat()");

    mIn = (TextView) findViewById(R.id.in);
    // Initialize the array adapter for the conversation thread
    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(this, mHandler);

This is the logcat output.

    11-06 15:35:52.047: E/AndroidRuntime(19780): FATAL EXCEPTION: main

11-06 15:35:52.047: E/AndroidRuntime(19780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.BluetoothChat/com.example.android.BluetoothChat.BluetoothChat}: java.lang.ClassCastException: android.widget.ListView
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.os.Looper.loop(Looper.java:143)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.app.ActivityThread.main(ActivityThread.java:4914)
11-06 15:35:52.047: E/AndroidRuntime(19780): at java.lang.reflect.Method.invokeNative(Native Method)
11-06 15:35:52.047: E/AndroidRuntime(19780): at java.lang.reflect.Method.invoke(Method.java:521)
11-06 15:35:52.047: E/AndroidRuntime(19780): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-06 15:35:52.047: E/AndroidRuntime(19780): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-06 15:35:52.047: E/AndroidRuntime(19780): at dalvik.system.NativeStart.main(Native Method)
11-06 15:35:52.047: E/AndroidRuntime(19780): Caused by: java.lang.ClassCastException: android.widget.ListView
11-06 15:35:52.047: E/AndroidRuntime(19780): at com.example.android.BluetoothChat.BluetoothChat.setupChat(BluetoothChat.java:141)
11-06 15:35:52.047: E/AndroidRuntime(19780): at com.example.android.BluetoothChat.BluetoothChat.onStart(BluetoothChat.java:116)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1197)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.app.Activity.performStart(Activity.java:3822)
11-06 15:35:52.047: E/AndroidRuntime(19780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2754)

Other changes made was to remove the sendMessage() method and the MESSAGE_WRITE case in the handleMessage() method.

Also removed the write the two write(buffer[] byte) methods from BluetoothChatServices class

I’ve been looking at this for few days and really can’t figure out whats wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:39:07+00:00Added an answer on May 26, 2026 at 9:39 pm

    Looking at your code it shows that in your original code you have R.id.in being cast as a ListView.. in your new code you have the same resource (R.id.in) being cast to a TextView. Likely what’s happening is that you haven’t changed R.id.in to be a TextView in your layout file and you are trying to cast a ListView to a TextView which will cause this error.

    The error

     java.lang.ClassCastException: android.widget.ListView
    

    Should give you a good hint of what you’re looking for. ClassCastException means that you tried to cast an object into a type that it cannot be cast to. So your best bet would be to look for where you are casting things, along with the line number the logcat output gave you. If you are casting something there (the TextView) you should verify that both the type you are casting from and casting to are correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.