Results 1 to 2 of 2
  1. #1
    doobster is offline Member
    Join Date
    Dec 2014
    Rep Power

    Default Confused between object types and instances

    Hi all. I'm completely new to JAVA and have a project I'm trying to complete. Basically I am trying to rewrite the code that's here under "Other" in Coldfusion, since we already had a program that worked with version 2 of Google's API, which is now discontinued.

    The real issue I'm having is in these couple of lines:

    JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    If JSON_FACTORY is of type JsonFactory, then how is it assigned to JacksonFactory.getDefaultInstance()? This parameters gets passed later on to GoogleCalendar API via the following:


    // Initialize Calendar service with valid OAuth credentials
    Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)

    The builder for the calendar expects as the type for the second parameter, but JSON_FACTORY is an instance of JacksonFactory.

    Ultimately I have to get this code working in Coldfusion, but that's giving me the error "Unable to find a constructor for class that accepts parameters of type ( t, , eCredential$Builder )". Here's my code from Coldfusion:

    ServiceAccountEmail='xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx';
    GoogleCredential=CreateObject('java',' pi.client.googleapis.auth.oauth2.GoogleCredential' );
    GoogleNetHttpTransport=CreateObject('java','com.go ogle.api.client.googleapis.javanet.GoogleNetHttpTr ansport');
    httpTransportObj=CreateObject('java',' pi.client.http.HttpTransport');
    JacksonFactory=CreateObject('java',' .client.json.jackson2.JacksonFactory');
    httpTransport=GoogleNetHttpTransport.newTrustedTra nsport();
    credential=CreateObject('java',' ent.googleapis.auth.oauth2.GoogleCredential$Builde r');
    credential.setServiceAccountId(ServiceAccountEmail );
    objFile=CreateObject("java","").init(K eyFilename);
    credential.setServiceAccountPrivateKeyFromP12File( objFile);
    credential.setServiceAccountScopes(ListToArray('ht tps://'));;
    CalObj=CreateObject('java',' s.calendar.Calendar');
    gCal=CalObj.init(httpTransport,JSON_FACTORY,creden tial);


  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Confused between object types and instances

    Java Code:
    JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    JSON_FACTORY is declared as aninstance of JsonFactory. That's what the bit to the left of the '=' is saying.
    Since this compiles then that implies that getInstance() of JacksonFactory returns something that extends the JsonFactory abstract class.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How to get multiple instances of an object/class
    By xEthan in forum New To Java
    Replies: 3
    Last Post: 08-04-2013, 01:40 AM
  2. 2 instances of an object that draws an image
    By Bobbyloujo in forum New To Java
    Replies: 3
    Last Post: 10-26-2012, 11:46 PM
  3. Preventing duplicate instances of an object
    By monkeyhead in forum New To Java
    Replies: 2
    Last Post: 11-07-2011, 07:28 PM
  4. Object Reflection: Creating new instances
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:13 PM
  5. Naming object instances
    By oldgit in forum New To Java
    Replies: 9
    Last Post: 02-07-2008, 11:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts