3 Replies - 826 Views - Last Post: 02 February 2011 - 03:28 PM

#1 gd0929918  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-January 11

Unsure about return type

Posted 02 February 2011 - 02:51 PM

I'm trying to write a program that will pull information from a BlackBerry, but every time I try to compile, I get "invalid method declaration; return type required" on line 24 (public static DeviceId). I'm kind of new to Java...

/* WhatIsMyPIN.java
      Tensioncore Administration Services, 2011
    Confidential and proprietary.*/
package com.sample;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.system.*;
import net.rim.device.api.system.DeviceInfo.*;
//blackberry applications that provide a GUI must extend UiApplication
public class WhatIsMyIP extends UiApplication
  {
    public static void main(Strings[] args)
      {
        //create a new instance of the app and start the application on the event thread
        WhatIsMyPIN theApp = new WhatIsMyPIN();
        theApp.enterEventDispatcher();
      }
    public WhatIsMyPIN()
      {
        //displays a new screen
        pushScreen(new WhatIsMyPINScreen());
      }
    public static DeviceId()
      {
        //retrieves Device PIN
        getDeviceId DeviceId = new getDeviceId();
      }
  }
//create a new screen that extends MainScreen which provides native app appearance.
final class WhatIsMyPINScreen extends MainScreen
  {
    public WhatIsMyPINScreen()
      {
        //invoke the MainScreen constructor
        super();
        //add a title to the screen
        LabelField title = new LabelField("WhatIsMyPIN?", LabelField.ELLIPSIS);
        setTitle (title);
        //getDeviceId shows the PIN
        add(new RichTextField(DeviceId));
        return;
      }
    //override the onClose() method to display a dialog box to the user with "Goodbye" when the application closes
    public boolean onClose()
      {
        Dialog.alert("Goodbye!");
        System.exit(0);
        return true;
      }
  }


Am I simply using return incorrectly, or is there a lot more that needs to be fixed/changed?
I've tried reading documentation for "getDeviceId()" and it's telling me to use "public static int" for it, which confuses me, because BlackBerry PINs contain letters as well as numbers...

Is This A Good Question/Topic? 0
  • +

Replies To: Unsure about return type

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Unsure about return type

Posted 02 February 2011 - 02:56 PM

In Java, all methods have to have a return type (except constructors, which logically should not have one).

In your case you defined it like:
public static DeviceId()



That has no return type. "static" simply makes it a class method instead of an object method. You should return something form this method or declare it as void, because presently, even with the change, your method does nothing that changes the state of the program...
Was This Post Helpful? 0
  • +
  • -

#3 gd0929918  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-January 11

Re: Unsure about return type

Posted 02 February 2011 - 03:22 PM

Thanks for that.
If I have to return something from the method, how do I go about doing it?
I've tried

public static DeviceId()
  {
    //retrieves Device PIN
    getDeviceId DeviceId = new getDeviceId();
    return DeviceId;
  }


and I still get the same error.
I've also tried
public static DeviceId()
  {
    //retrieves Device PIN
    getDeviceId DeviceId = new getDeviceId();
    return DeviceInfo.getDeviceId;
  }


and still have the same thing.

Or am I supposed to be using it further down in the RichTextField?
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Unsure about return type

Posted 02 February 2011 - 03:28 PM

You still have not specified a return value in your method definition. You need to specify that the method will return something. It needs to be whatever type the getDeviceId() method returns (by the way, all you need is the last line).

If you look in the Blackberry API, you will see that it returns an int. Thus, your method will end up like this:
public static int DeviceId()
  {
    //retrieves Device PIN
    return DeviceInfo.getDeviceId();
  }



Notice the "public static int part? That's the return type. Also, I'll move this to the Mobile Development forum, since technically, this is Blackberry.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1