GetIdeas example - ApiException not instance of Throwable?

323 views
Skip to first unread message

p9g...@gmail.com

unread,
May 11, 2015, 12:57:34 PM5/11/15
to adwor...@googlegroups.com
Hi all,

I have a compilation problem while trying to execute this example https://github.com/googleads/googleads-java-lib/blob/master/examples/adwords_axis/src/main/java/adwords/axis/v201502/optimization/GetKeywordIdeas.java

The line 118

TargetingIdeaPage page = targetingIdeaService.get(selector);

gives me this error

Unhandled exception type ApiException

If I try to add this in the method declaration (even if there is already throws Exception ) it tells me

No exception of type ApiException can be thrown; an exception type must be a subclass of Throwable

Also, in the example there is no import of the ApiException class, so I added

import com.google.api.ads.adwords.axis.v201502.cm.ApiException;

Any help is really appreciated! Thank you in advance.


Josh Radcliff (AdWords API Team)

unread,
May 12, 2015, 9:47:23 AM5/12/15
to adwor...@googlegroups.com, p9g...@gmail.com
Hi,

That error suggests that your classpath is not configured correctly. Please check out the section of our README on configuring dependencies and let me know if you still have questions.

Thanks,
Josh, AdWords API Team

Greg Snider

unread,
Jun 13, 2016, 1:12:25 PM6/13/16
to AdWords API Forum, p9g...@gmail.com
Josh,

I'm having the issue as OP.  I have tried troubleshooting my classpath, but have been unsuccessful.  I am using Android Studio and the line I am using which generates an unhandled exception is straight from the GetCampaigns.java sample code:

"page = campaignService.get(selector);"

I am stuck and any further help or suggestions is greatly appreciated.  I am also curious to how the OP solved their problem.  

Thank you in advance.

P G

unread,
Jun 13, 2016, 1:13:01 PM6/13/16
to Greg Snider, AdWords API Forum
Hello,

I'll try to answer, hoping to remember correctly from one year ago.
As for me, it was a problem of importing packages. I was trying to import only a subset of the packages in adwords.axis.(etc.) to create a smaller project.
When I included the whole jar. (with all sub-jar), it worked.

I hope you can solve your issue,

Kind regards
Pietro

goldenmaza

unread,
Mar 4, 2018, 5:03:59 PM3/4/18
to AdWords API Forum
Hello Josh

I know you answered this a while ago but I have the same problem. I've read https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html and even if this page explains
what a classpath is, it was not written for Google AdWords API. So what do I need to do regarding this classpath issue? What file(s)? I also sit with Android Studio.

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 5, 2018, 9:06:46 AM3/5/18
to AdWords API Forum
Hi Richard,

Could you share the error you're getting from the compiler? I want to make sure this is the same issue as mentioned below, so it would be helpful to have more details for your particular case.

Thanks,
Josh, AdWords API Team

goldenmaza

unread,
Mar 5, 2018, 9:41:33 AM3/5/18
to AdWords API Forum
Hi Josh

Thank you for your time! :)

Code and errors are as follows:

try {
    adWordsHandler
= new AdWordsHandler(context);
    adWordsHandler
.callAdWordsAPI();
    sales
= adWordsHandler.getEntries();
    resourceHandler
.addResources(Sale.class.getName(), sales);
} catch (RemoteException e) {
    e
.printStackTrace();
} catch (ApiException e) {
    e
.printStackTrace();
} catch (Exception e) {
    e
.printStackTrace();
}

public void callAdWordsAPI() throws Exception, ApiException {
...
AdGroupAdPage entries = adService.get(selector);
...
}

Error:(104, 9) error: cannot access RemoteException
class file for java.rmi.RemoteException not found

Error:(61, 52) error: incompatible types: ApiException cannot be converted to Throwable

Error:(89, 46) error: cannot access Remote
class file for java.rmi.Remote not found

Take care! :)

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 5, 2018, 11:57:57 AM3/5/18
to AdWords API Forum
Hi Richard,

Thanks - that definitely helps! Could you let me know how you're managing your dependencies? For example, are you using Maven, Gradle, or just setting your classpath manually (e.g., by copying dependencies to a lib folder)?

I ask because the error that java.rmi.RemoteException is not in your classpath indicates that you are missing some key dependencies. If it helps, you can see the list of dependencies to add for Maven here in the README. If you aren't using Maven, you can download the adwords-axis-jars-and-examples archive on the releases page, which contains a lib folder with all required dependencies.

Thanks,
Josh, AdWords API Team

goldenmaza

unread,
Mar 6, 2018, 3:26:52 AM3/6/18
to AdWords API Forum
Hi Josh

As I currently sit with Android Studio/Gradle, I would prefer continuing using these, I can skip Gradle for the next project but for now I would like to learn how to solve this Gradle issue.

Oh, by placing the files under the libs folder you set the classpath(s) manually?

The part about the archive I have done already (my other forum post with Dhanya Sundararaju (AdWords API Team) as he suggested the same). But that does not solve the issue I got
as a result of this inclusion of jar files.


Thank you for your time! :)

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 6, 2018, 4:36:16 PM3/6/18
to AdWords API Forum
Hi Richard,

Would you mind sharing your Gradle config so I can see how you're bringing in the library dependencies? Also, just to rule certain things out, could you let me know which version of Java you're using?

Thanks,
Josh, AdWords API Team

goldenmaza

unread,
Mar 7, 2018, 3:07:15 AM3/7/18
to AdWords API Forum
Hi Josh

According to the controlpanel I have Java 8 Update 162.

build.gradle under app folder:
apply plugin: 'com.android.application'

android
{
    compileSdkVersion
26
    buildToolsVersion
"26.0.2"
    defaultConfig
{
        applicationId
"yada.yada"
        minSdkVersion
23
        targetSdkVersion
26
        versionCode
1
        versionName
"1.0"
        testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
   
}
    buildTypes
{
        debug
{
            minifyEnabled
false
            proguardFiles getDefaultProguardFile
('proguard-android.txt'), 'proguard-rules.pro'
       
}
        release
{
            minifyEnabled
false
            proguardFiles getDefaultProguardFile
('proguard-android.txt'), 'proguard-rules.pro'
       
}
   
}
}

repositories
{
    jcenter
()
    google
()
}


dependencies
{
    implementation fileTree
(include: ['*.jar'], dir: 'libs')
    implementation
'com.android.support:design:26.0.2'
    implementation
'com.android.support:appcompat-v7:26.0.2'
    implementation
'com.google.android.gms:play-services-maps:11.8.0'
   
//implementation 'com.google.api-ads:ads-lib:3.10.0'
   
//implementation 'com.google.api-ads:adwords-axis:1.38.0'
    implementation
'com.android.support:appcompat-v7:26.0.2'
    implementation
'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation
'junit:junit:4.12'
}

Thank you for your time! :)

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 7, 2018, 9:10:42 AM3/7/18
to AdWords API Forum
Hi Richard,

Thanks for sending over that info. I noticed two things about your dependencies section:

1. The dependencies for the Google Ads APIs Client Library for Java are commented out:

    //implementation 'com.google.api-ads:ads-lib:3.10.0'
    //implementation 'com.google.api-ads:adwords-axis:1.38.0'

Was that intentional, and was that the state of the config when you tried to run the example? With those two lines commented out, none of the library's classes will be on the classpath.

2. The versions specified for the two Google Ads APIs Client Library for Java do not match. For example, if you're using 3.10.0 for ads-lib, you should also use 3.10.0 for adwords-axis. Although Maven requires separate versions for each dependency, in practice we always keep all of our Maven artifacts on the same version. The latest version for the library is 3.12.0.

Thanks,
Josh, AdWords API Team

goldenmaza

unread,
Mar 7, 2018, 1:15:57 PM3/7/18
to AdWords API Forum
Hi Josh

1) Yes, it is intentional as I first believed that by placing the jar files under the libs folder that they would get their respective classpath automatically.

2) I've updated the build file as follows:

implementation 'com.google.api-ads:ads-lib:3.12.0'
implementation
'com.google.api-ads:adwords-axis:3.12.0'

I still have the RemoteException problem..

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 7, 2018, 3:26:10 PM3/7/18
to AdWords API Forum
Hi Richard,

My knowledge of Gradle is pretty limited, I'm afraid, but did you try adding mavenCentral() to your list of repositories as shown here?

Thanks,
Josh, AdWords API Team

goldenmaza

unread,
Mar 8, 2018, 3:23:26 AM3/8/18
to AdWords API Forum
Hi Josh

Wasn't jcenter replacing mavenCentral?

But why do I still get RemoteException and why is the ApiException still a problem (underlined red and something about Throwable)?

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 8, 2018, 9:28:34 AM3/8/18
to AdWords API Forum
Hi Richard,

This StackOverflow post suggests that RMI may not be packaged with Android. Are you developing an Android application, or are you just using Android Developer Studio as your IDE?

Regarding jCenter, you're absolutely correct. :)

Thanks,
Josh, AdWords API Team

goldenmaza

unread,
Mar 8, 2018, 4:39:14 PM3/8/18
to AdWords API Forum
Hi Josh

Wonderful, that would set me back alittle...

Yes, I'm using Android Studio for my first Android app. It uses not only Google AdWords API but also Google Maps API. I felt like Android Studio would
be a good starting point. Do I need to get Eclipse with Maven just for AdWords and develop everything else in Android Studio? Currently, my problem to make
my code run is this ApiException class that seem to need RemoteException. If there is no default way of getting RMI for Android Studio, then I don't have
much options left.

Why is it needed for ApiException with AdWords?

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 9, 2018, 10:42:08 AM3/9/18
to AdWords API Forum
Hi Richard,

The RMI package is needed because the objects generated for the Axis SOAP toolkit are all based on that package. For example, ApiException in the library ultimately extends java.rmi.RemoteException via the inheritance hierarchy of ApiException -> ApplicationException -> AxisFault -> RemoteException.

One thing you could try would be to use the JAX-WS (AppEngine) modules instead of the Axis modules. Those would be:

    <dependency>
      <groupId>com.google.api-ads</groupId>
      <artifactId>ads-lib</artifactId>
      <version>RELEASE</version>
    </dependency>
    <dependency>
      <groupId>com.google.api-ads</groupId>
      <artifactId>adwords-appengine</artifactId>
      <version>RELEASE</version>
    </dependency>

I suspect you'll run into similar RMI dependencies there, but it's worth a shot. :)

Cheers,
Josh, AdWords API Team

goldenmaza

unread,
Mar 12, 2018, 3:52:24 AM3/12/18
to AdWords API Forum
Hi Josh

By having the following in the build.gradle file:

implementation 'com.google.api-ads:ads-lib:3.12.0'
implementation
'com.google.api-ads:adwords-axis:3.12.0'

implementation
'com.google.api-ads:adwords-appengine:3.12.0'

I get the classpath errors:

Error:Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.api-ads:adwords-appengine:3.12.0.

I even have the adwords-appengine-3.12.0.jar file under the app/libs folder...

I have even invalided cache and done a restart, no luck...

I miss the day of front-end development where I didn't have these problems...

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 12, 2018, 12:37:46 PM3/12/18
to AdWords API Forum
Hi Richard,

Could you try removing the line for adwords-axis? The idea is that you'll either use adwords-axis or adwords-appengine, but not both.

Thanks,
Josh, AdWords API Team

goldenmaza

unread,
Mar 13, 2018, 3:58:56 AM3/13/18
to AdWords API Forum
Hi Josh

I tried both, no change. I'm trying to configure Eclipse to use my old project files but the problems with dependencies are even worse in this
environment. There is no convert project from Gradle/Android to Maven/Eclipse functionality in Eclipse?

Kind regards
Richard

Josh Radcliff (AdWords API Team)

unread,
Mar 14, 2018, 10:17:10 AM3/14/18
to AdWords API Forum
Hi,

The Gradle Maven Plugin will generate a pom.xml for your project based on your Gradle configuration. Could you give that a try?

Another option is to use a Gradle plugin for Eclipse, such as Eclipse Buildship.

Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages