1

对于这个非常基本的问题,我感到很抱歉,但我真的在这里迷失了方向。我想做的是编译和运行这段代码:

package com.gc.android.market.api;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.io.InputStream;

import com.gc.android.market.api.MarketSession;

import com.gc.android.market.api.MarketSession.Callback;
import com.gc.android.market.api.model.Market.AppType;
import com.gc.android.market.api.model.Market.AppsRequest;
import com.gc.android.market.api.model.Market.AppsRequest.OrderType;
import com.gc.android.market.api.model.Market.AppsRequest.ViewType;
import com.gc.android.market.api.model.Market.AppsResponse;
import com.gc.android.market.api.model.Market.CommentsRequest;
import com.gc.android.market.api.model.Market.GetAssetResponse.InstallAsset;
import com.gc.android.market.api.model.Market.GetImageRequest;
import com.gc.android.market.api.model.Market.GetImageResponse;
import com.gc.android.market.api.model.Market.ResponseContext;
import com.gc.android.market.api.model.Market.GetImageRequest.AppImageUsage;

public class Fetcher
{
    public static void main(String[] args) {
        MarketSession session = new MarketSession(true);
        System.out.println("Login:");
    }
}

我正在按照这里的说明进行操作:https ://code.google.com/p/android-market-api/wiki/HowDownloadApps

我从这里得到的导入和打包行:https://code.google.com/p/android-market-api/source/browse/trunk/AndroidMarketApi/src/com/gc/android/market/api/Main。爪哇

我在 OS X 上执行此操作。在我的当前目录中,我有三个文件:

  • Fetcher.java(上面的代码)
  • AndroidMarketApi.jar
  • protobuf-java-2.2.0.jar

我使用这个命令编译:

$ javac -classpath ".:/Users/ephracis/fetcher/*" Fetcher.java

然后我尝试运行:

$ java Fetcher
Exception in thread "main" java.lang.NoClassDefFoundError: Fetcher (wrong name: com/gc/android/market/api/Fetcher)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
$ java com.gc.android.market.api.Fetcher
Exception in thread "main" java.lang.NoClassDefFoundError: com/gc/android/market/api/Fetcher
Caused by: java.lang.ClassNotFoundException: com.gc.android.market.api.Fetcher
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

我也尝试将类路径添加到 java 命令,但它没有改变任何东西。

4

1 回答 1

0

要执行,您需要完全限定的类名(包 + 类名)。尝试:

java -classpath ".:/Users/ephracis/fetcher/*" com.gc.android.market.api.Fetcher

此外,您仍然需要在类路径中包含适当的类/jar。

于 2013-09-07T05:49:32.703 回答