Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 6th, 2007, 1:26 AM   #1
amitabha
Newbie
 
Join Date: Jan 2007
Posts: 3
Rep Power: 0 amitabha is on a distinguished road
Compiler error...why?

Byte b=new Byte(1); //<-here
amitabha is offline   Reply With Quote
Old Feb 6th, 2007, 1:36 AM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
The constructor for a Byte does not take an integer value but a String value instead. See below.
Byte b = new Byte("1");
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Feb 22nd, 2007, 3:25 PM   #3
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Actually there are two constructors:

1.  Byte(byte value) 
2.  Byte(String s)

Example of each:

public class ByteTest {
    public static void main(String[] args) {
	byte aByte = 1;
        Byte byte1 = new Byte( aByte );
        System.out.println( byte1 );

	String strByte = "1";
        Byte byte2 = new Byte( strByte);
        System.out.println( byte2 );
    }
}

So to answer your question, you could create a Byte from an integer with a simple cast like so:
Byte b = new Byte( (byte)1 ) );
hoffmandirt is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I take a square root? Fall Back Son C 26 Oct 23rd, 2006 12:24 PM
programming outside the compiler TwilightProgrammers C++ 9 Jun 4th, 2006 5:21 PM
[tutorial] Simple G++ compiler tutorial coldDeath C++ 7 Nov 27th, 2005 12:33 PM
DOS Compiler! Starter C++ 11 Apr 15th, 2005 10:14 PM
Newbie : need help with Dev-C++ compiler gemini_shooter C++ 16 Apr 12th, 2005 3:09 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:36 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC