Why can't I instantiate class ApiContext?
I've downloaded Google Checkout SDK JAR file (checkout-sdk-2.5.1.jar), moved it into project /libs dir [*1], added the library into the project's path. After this I've created a test class that makes test order to sandbox server. Here's the code
import android.widget.TextView;
import com.google.checkout.sdk.commands.ApiContext;
import com.google.checkout.sdk.commands.Environment;
import com.google.checkout.sdk.commands.EnvironmentInterface;
public class Main extends Activity {
final String MERCHANT_ID = "XXXXXX";
final String MERCHANT_KEY = "YYYYY";
final String CURRENCY = "GBP";
ApiContext API_CONTEXT;
TextView output;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
API_CONTEXT = new ApiContext(
Environment.SANDBOX,
MERCHANT_ID,
MERCHANT_KEY,
CURRENCY);
String result = API_CONTEXT.postCommand
(EnvironmentInterface.CommandType.ORDER_PROCESSING,
"<hello xmlns=\"http://checkout.google.com/schema/2\"/>");
output = (TextView) findViewById(R.id.output);
output.setText(result);
}
}
The main XML has only one element - TextView
- that was supposed to display returning XML (which basically contains redirect-url
).
However, the app breaks on start with an error:
06-11 18:31:02.372: ERROR/dalvikvm(372): Could not find class 'com.google.checkout.sdk.commands.ApiContext', referenced from method com.example.gc.Main.onCreate 06-11 18:31:02.701: ERROR/AndroidRuntime(372): FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.checkout.sdk.commands.ApiContext
Can this .jar file be used in an Android project? Or I am doing something wrong?
[1]
PS. 开发者_开发百科/libs dir is AFAIK default IntelliJ's dir for external libraries. don't be confused with it.Could the problem be because .jar file is not meant to be used within Android project? Is there a way to know this?
精彩评论