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 6232481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:07:28+00:00 2026-05-24T10:07:28+00:00

I referenced the code from Android Developer. After compliling the code and fooling around

  • 0

I referenced the code from Android Developer. After compliling the code and fooling around with some of the errors, I could not figure this one out.

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.bluetooth.BluetoothSocket;
import android.os.Handler;
import junit.framework.TestCase;

public class ConnectedThread extends Thread {    
    private static final String MESSAGE_READ = null;
    private final BluetoothSocket mmSocket;    
    private final InputStream mmInStream;    
    private final OutputStream mmOutStream;
    private Handler mHandler = new Handler();
    public ConnectedThread(BluetoothSocket socket) {        
        mmSocket = socket;        
        InputStream tmpIn = null;        
        OutputStream tmpOut = null;         
        // Get the input and output streams, using temp objects because        
        // member streams are final        
        try {            
            tmpIn = socket.getInputStream();            
            tmpOut = socket.getOutputStream();        
            } 
        catch (IOException e) { }         
        mmInStream = tmpIn;        
        mmOutStream = tmpOut;    
        }     
    public void run() {        
        byte[] buffer = new byte[1024];  
        // buffer store for the stream        
        int bytes; 
        // bytes returned from read()         
        // Keep listening to the InputStream until an exception occurs        
        while (true) {            
            try {                
                // Read from the InputStream                
                bytes = mmInStream.read(buffer);                
                // Send the obtained bytes to the UI Activity                
                mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)                        
                            .sendToTarget();            
                } catch (IOException e) {                
                    break;            
                    }        
                }    
        }     
    /* Call this from the main Activity to send data to the remote device */    
    public void write(byte[] bytes) {        
        try {            
            mmOutStream.write(bytes);        
            } 
        catch (IOException e) { }    
            }     
    /* Call this from the main Activity to shutdown the connection */    
    public void cancel() {        
        try {            
            mmSocket.close();        
            } catch (IOException e) { }    


    }
}

The method obtainMessage(int, int , object) in the type Handler is not applicable for the arguments(String, int ,int, Byte[]).

Could someone that has used this code before possibly tell me what i need to ad or what i am missing. Its probably something really simple. Thank You.

  • 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-24T10:07:30+00:00Added an answer on May 24, 2026 at 10:07 am

    obtainMessage accept argumets like

    handler.obtainMessage(int)
    handler.obtainMessage(int, object)
    handler.obtainMessage(int, int, int)
    handler.obtainMessage(int, int, int, object);
    

    You have passes MESSAGE_READ variable in handler.obtainMessage() so it looks like

    handler.obtainMessage(String, int, int, object);
    

    MESSAGE_READ which is String and thats why you are getting this error
    change MESSAGE_READ variable String to Int

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

Sidebar

Related Questions

In Android 1.5 (also on 1.6) How to add an Access Point from code?
So I've been looking at code from various parts of the Android git, but
I use code from http://mobiforge.com/developing/story/sms-messaging-android as reference. I added scrollview and it show the
EDIT: Added the NSRunLoop from my code, as mentioned by Deepak below. This was
According to Android Developer Reference uptimeMillis() returns the number of milliseconds since boot, not
Pretty much as the question asks. Answers preferably in pseudo code and referenced. The
When I read the book Code Complete, the word construction is referenced frequently. What
I'm new in Android development and I have the next question/problem. I'm playing around
I'm new in Android development and I have the next question/problem. I'm playing around
I read carefully the good UI practice from the Google Dev Blog; http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html and

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.