Vonage / vonage-java-sdk

Vonage Server SDK for Java. API support for SMS, Messages, Voice, Text-to-Speech, Numbers, Verify (2FA), Video and more.
https://developer.vonage.com/en/home
Apache License 2.0
96 stars 121 forks source link

java.lang.ClassNotFoundException #129

Closed stevdza-san closed 6 years ago

stevdza-san commented 6 years ago

I'm trying to make an android application which will implement nexmo API in order to use the nexmo service from my android phone. But I'm getting ClassNotFoundException, and I don't know what is the problem exactly?

Here is my error log:

11-06 20:01:36.404 21709-21709/? E/OpenGLRenderer: GL_INVALID_OPERATION 11-06 20:01:47.250 467-4530/? E/QC-time-services: Daemon:Update to modem bit set 11-06 20:01:47.250 4515-4515/? E/QC-time-services: Receive Passed == base = 2, unit = 1, operation = 0, result = 0 11-06 20:01:47.250 467-950/? E/QC-time-services: Daemon:tod_update_ind_cb: Got Update from modem msg_id 40 11-06 20:01:47.250 467-952/? E/QC-time-services: Daemon: Time-services: Waiting to acceptconnection 11-06 20:01:47.350 4531-4531/? E/dalvikvm: Could not find class 'android.app.NotificationChannel', referenced from method on.a 11-06 20:01:47.460 4531-4531/? E/dalvikvm: Could not find class 'android.support.v4.app.JobIntentService$JobServiceEngineImpl', referenced from method android.support.v4.app.JobIntentService.onCreate 11-06 20:01:47.900 305-420/? E/cutils: Failed to mkdirat(/storage/sdcard1/Android): Read-only file system 11-06 20:01:48.029 4557-4557/? E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.sony.nfx.app.sfrc.notification.DailyNotificationController.c 11-06 20:01:48.399 4580-4580/? E/dalvikvm: Could not find class 'android.app.AlarmManager$AlarmClockInfo', referenced from method com.android.deskclock.alarms.b.b 11-06 20:01:49.149 4580-4615/? E/ActivityThread: Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider 11-06 20:01:49.159 4580-4613/? E/ActivityThread: Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider 11-06 20:02:04.669 4680-4680/? E/memtrack: Couldn't load memtrack module (No such file or directory) 11-06 20:02:04.669 4680-4680/? E/android.os.Debug: failed to load memtrack module: -2 11-06 20:02:11.089 4740-4740/? E/memtrack: Couldn't load memtrack module (No such file or directory) 11-06 20:02:11.089 4740-4740/? E/android.os.Debug: failed to load memtrack module: -2 11-06 20:02:11.269 4758-4758/com.nexmodemo E/AndroidRuntime: FATAL EXCEPTION: main Process: com.nexmodemo, PID: 4758 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.nexmodemo/com.nexmodemo.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.nexmodemo.MainActivity" on path: DexPathList[[zip file "/data/app/com.nexmodemo-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.nexmodemo-2, /vendor/lib, /system/lib]] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2174) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2298) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:212) at android.app.ActivityThread.main(ActivityThread.java:5151) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.nexmodemo.MainActivity" on path: DexPathList[[zip file "/data/app/com.nexmodemo-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.nexmodemo-2, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at android.app.Instrumentation.newActivity(Instrumentation.java:1061) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2165) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2298)  at android.app.ActivityThread.access$800(ActivityThread.java:144)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:212)  at android.app.ActivityThread.main(ActivityThread.java:5151)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)  at dalvik.system.NativeStart.main(Native Method)  11-06 20:02:11.389 15867-351/? E/NetworkScheduler: Unrecognised action provided: android.intent.action.PACKAGE_REMOVED 11-06 20:02:11.999 4787-4787/? E/memtrack: Couldn't load memtrack module (No such file or directory) 11-06 20:02:11.999 4787-4787/? E/android.os.Debug: failed to load memtrack module: -2 11-06 20:02:12.449 4854-4854/? E/GoogleTagManager: Invalid macro: _gtm.loadEventEnabled 11-06 20:02:12.489 4854-4876/? E/GoogleTagManager: Invalid macro: _gtm.loadEventEnabled 11-06 20:02:12.699 21355-21355/? E/Finsky: [1] com.google.android.finsky.wear.bl.a(3): onConnectionFailed: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null} 11-06 20:02:17.239 4997-4997/? E/dalvikvm: Could not find class 'com.facebook.sonar.android.SonarPlatformImpl', referenced from method com.instagram.process.InstagramApplicationForMainProcess.initializeSonar 11-06 20:02:17.429 4997-4997/? E/dalvikvm: Could not find class 'android.app.job.JobScheduler', referenced from method com.instagram.pendingmedia.service.ah.a 11-06 20:02:17.429 4997-4997/? E/dalvikvm: Could not find class 'android.app.job.JobScheduler', referenced from method com.instagram.pendingmedia.service.ah.a

AND here is my Main Activity:

package com.nexmodemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.nexmo.client.NexmoClient;
import com.nexmo.client.NexmoClientException;
import com.nexmo.client.auth.AuthMethod;
import com.nexmo.client.auth.TokenAuthMethod;
import com.nexmo.client.sms.SmsSubmissionResult;
import com.nexmo.client.sms.messages.TextMessage;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

//I removed my api keys and phone numbers...
    public static final String API_KEY = "myKey";
    public static final String API_SECRET = "mySecretKey";

    public static final String SMS_FROM = "number1";
    public static final String SMS_TO = "number2";
    public static final String SMS_TEXT = "Hello World!";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
        NexmoClient client = new NexmoClient(auth);

        SmsSubmissionResult[] responses = new SmsSubmissionResult[0];
        try {
            responses = client.getSmsClient().submitMessage(new TextMessage(
                    SMS_FROM,
                    SMS_TO,
                    SMS_TEXT));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NexmoClientException e) {
            e.printStackTrace();
        }
        for (SmsSubmissionResult response : responses) {
            System.out.println(response);
        }

    }
}
ChrisGuzman commented 6 years ago

Hey there.

I tried to make a small Android app with our library over the weekend and ran into a lot of the same issues. The issues stems from the fact that this library isn't really made for Android apps. It hasn't been optimized for that use case. If you'd like to use the java library I suggest checking out our quickstarts for the java library: https://github.com/nexmo-community/nexmo-java-quickstart We're always adding new examples to it and you can run the examples straight from the folder.

stevdza-san commented 6 years ago

@ChrisGuzman Chris thank you for your time, I really appreciate all your answers. I will check all the other examples on the website. Cheers!