有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java 安卓 studio中的ClassNotFoundException

我正在构建一个服务器客户端安卓应用程序。我的安卓应用程序连接到一个服务器,然后服务器向我的手机发送一个“streamPurpose”对象类型(我创建了这个类)

当服务器与我的手机通信时,我的应用程序抛出ClassNotFoundException

我有目标。java在我的项目和编译器中没有显示错误,因为它可以识别它

streamPurpose inStream=new streamPurpose();
try {
    providerSocket = new ServerSocket(4325, 10);

    while (true)
    {
        connection = providerSocket.accept();
        redOut = new ObjectOutputStream(connection.getOutputStream());
        redIn = new ObjectInputStream(connection.getInputStream());
        inStream=(streamPurpose)redIn.readObject(); //Expression thrown here
    }
} catch (IOException e) {
    e.printStackTrace();
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}

我必须把它包括进去吗。java文件的另一种方式,比如库

Stack Trace:
06-03 12:59:20.531 8712-9560/com.example.p3130152.afqafafafa W/System.err: java.lang.ClassNotFoundException: streamPurpose
06-03 12:59:20.571 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.lang.Class.classForName(Native Method)
06-03 12:59:20.581 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.lang.Class.forName(Class.java:204)
06-03 12:59:20.621 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2304)
06-03 12:59:20.631 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1663)
06-03 12:59:20.631 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
06-03 12:59:20.631 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1806)
06-03 12:59:20.641 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2006)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1963)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at com.example.p3130152.afqafafafa.configure$AsyncTaskRunner.doInBackground(configure.java:255)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at com.example.p3130152.afqafafafa.configure$AsyncTaskRunner.doInBackground(configure.java:91)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at 安卓.os.AsyncTask$2.call(AsyncTask.java:287)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at 安卓.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.lang.Thread.run(Thread.java:841)
06-03 12:59:20.661 8712-9560/com.example.p3130152.afqafafafa W/System.err: Caused by: java.lang.NoClassDefFoundError: streamPurpose
06-03 12:59:20.671 8712-9560/com.example.p3130152.afqafafafa W/System.err:  ... 17 more
06-03 12:59:20.671 8712-9560/com.example.p3130152.afqafafafa W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "streamPurpose" on path: DexPathList[[zip file "/data/app/com.example.p3130152.afqafafafa-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.p3130152.afqafafafa-2, /vendor/lib, /system/lib]]
06-03 12:59:20.681 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
06-03 12:59:20.681 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-03 12:59:20.681 8712-9560/com.example.p3130152.afqafafafa W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-03 12:59:20.681 8712-9560/com.example.p3130152.afqafafafa W/System.err:  ... 17 more

Gradle文件(项目)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.安卓.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Gradle文件(应用程序)

apply plugin: 'com.安卓.application'

安卓 {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.p3130152.afqafafafa"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-安卓.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.安卓.support:appcompat-v7:23.1.1'
    compile 'com.google.安卓.gms:play-services:8.4.0'
}

共 (0) 个答案