朋友您好我正在开发一个应用程序,我必须集成Authorize.net,我成功集成它但在运行应用程序时遇到错误Like =>抱歉 - 应用程序(app_name)意外停止。请再试一次 。你能否回顾一下谢谢
来源: - http://developer.authorize.net/integration/fifteenminutes/android/
main.xml =>
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main" />
=&GT; Example.Activity
package net.authorize;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.HashMap;
import net.authorize.android.AuthNet;
import net.authorize.android.AuthNetActivityBase;
import net.authorize.android.SimpleActivity;
import net.authorize.android.button.AuthNetButton;
import net.authorize.data.Address;
import net.authorize.data.Customer;
import net.authorize.data.EmailReceipt;
import net.authorize.data.Order;
import net.authorize.data.ShippingCharges;
import net.authorize.data.creditcard.CreditCard;
import net.authorize.xml.MessageType;
import net.authorize.xml.Result;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
public class ExampleActiviy extends SimpleActivity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// load merchant info
setContentView(R.layout.main);
authNetObj = AuthNet.getInstance(Environment.SANDBOX,
R.layout.authnet_credentials_dialog, R.id.authnet_loginid_edit,
R.id.authnet_password_edit, R.id.authnet_auth_cancel_button,
R.id.authnet_auth_login_button);
// prepare the authCapture button
AuthNetButton authCaptureButton = authNetObj.getButton(this,
"Authorize and Capture");
authCaptureButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
launchAuthCaptureIntent();
}
});
LinearLayout layout = (LinearLayout) findViewById(R.id.main);
layout.addView(authCaptureButton);
}
/**
* Activity launcher for authCapture transactions.
*/
private void launchAuthCaptureIntent() {
String refId = Long.toString(System.currentTimeMillis());
BigDecimal totalAmount = new BigDecimal(19.99);
/*
* listing these out only to show the required
* 'parameter set' that should be passed into
* the create Intent method.
*/
CreditCard creditCard = CreditCard.createCreditCard();
creditCard.setCreditCardNumber("4111111111111111");
Calendar expCal = Calendar.getInstance();
expCal.add(Calendar.YEAR, 4);
creditCard.setExpirationDate(expCal.getTime());
Order order = Order.createOrder();
order.setTotalAmount(new BigDecimal(19.95));
order.setDescription("Android Test Order");
Customer customer = null;
Address shippingAddress = null;
ShippingCharges shippingCharges = null;
EmailReceipt emailReceipt = null;
HashMap<String, String> merchantDefinedFields = new HashMap<String, String>();
merchantDefinedFields.put("notes", "sent from SampleActivity");
Intent authNetIntent = authNetObj.createAIMAuthCaptureIntent(this, refId,totalAmount,
creditCard, order, customer, shippingAddress,shippingCharges, emailReceipt,
merchantDefinedFields);
/*
* final launch command to spawn the Activity and provide a
* callback where the result data can be processed
*/
authNetIntent.putExtra(
AuthNetActivityBase.EXTRA_DUPLICATE_TXN_WINDOW_SECS,
5);
launchSubActivity(authNetIntent,
createPaymentIntentResultCallback());
}
/**
* Creates a payment Intent ResultCallback.
*
* @return ResultCallback
*/
private ResultCallback createPaymentIntentResultCallback() {
return new SimpleActivity.ResultCallback() {
public void resultTransactionCanceled(Enum<?> txnType) {
showAlert((TransactionType) txnType + " canceled",
"");
}
public void resultTransactionFailed(Enum<?> txnType,
Result result) {
MessageType msgType = MessageType.E00000;
StringBuilder errorBuilder = new StringBuilder(msgType.getValue())
.append(": ").append(msgType.getText());
net.authorize.aim.Result aimResult = (net.authorize.aim.Result) result;
errorBuilder = new StringBuilder();
if (aimResult.getTransactionResponseErrors().size() > 0) {
for (ResponseReasonCode respReasonCode : aimResult
.getTransactionResponseErrors()) {
errorBuilder.append(respReasonCode.getResponseReasonCode())
.append(": ").append(respReasonCode.getReasonText()).append("\n");
}
} else if (aimResult.getMessages().size() > 0) {
for (MessageType msgType1 :
aimResult.getMessages()) {
errorBuilder.append(msgType1.getValue()).append(": ")
.append(msgType1.getText()).append("\n");
}
}
showAlert((TransactionType) txnType + " failed",
errorBuilder.toString());
}
public void resultTransactionSucceeded(Enum<?> txnType, Result result) {
net.authorize.aim.Result aimResult = (net.authorize.aim.Result) result;
showAlert((TransactionType) txnType + " success",
"authCode: " + aimResult.getAuthCode() + "\n" + "refTransId: " +
aimResult.getTransId());
}
};
}
/**
* Create a simple alert dialog.
*
* @param title
* @param message
*/
private void showAlert(String title, String message) {
// Show an error to the user
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message).setTitle(title)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
AndroidManifest.xml =&gt;
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.authorize"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- ** Security Activities - REQUIRED ** -->
<activity android:name=
"net.authorize.android.security.MobileMerchantAuthActivity"
android:configChanges="keyboardHidden|orientation" />
<activity android:name=
"net.authorize.android.security.LoginBaseActivity"
android:configChanges="keyboardHidden|orientation" />
<!-- AIM Activity -->
<activity android:name=
"net.authorize.android.aim.AuthCaptureActivity"
android:configChanges="keyboardHidden|orientation" />
<activity
android:name="net.authorize.ExampleActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
LogCat =&gt;
04-22 14:58:17.999: D/AndroidRuntime(480): Shutting down VM
04-22 14:58:17.999: W/dalvikvm(480): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-22 14:58:18.028: E/AndroidRuntime(480): FATAL EXCEPTION: main
04-22 14:58:18.028: E/AndroidRuntime(480): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.authorize/net.authorize.ExampleActivity}: java.lang.ClassNotFoundException: net.authorize.ExampleActivity in loader dalvik.system.PathClassLoader[/data/app/net.authorize-1.apk]
04-22 14:58:18.028: E/AndroidRuntime(480): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-22 14:58:18.028: E/AndroidRuntime(480): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-22 14:58:18.028: E/AndroidRuntime(480): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-22 14:58:18.028: E/AndroidRuntime(480): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-22 14:58:18.028: E/AndroidRuntime(480): at android.os.Handler.dispatchMessage(Handler.java:99)
04-22 14:58:18.028: E/AndroidRuntime(480): at android.os.Looper.loop(Looper.java:123)
04-22 14:58:18.028: E/AndroidRuntime(480): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-22 14:58:18.028: E/AndroidRuntime(480): at java.lang.reflect.Method.invokeNative(Native Method)
04-22 14:58:18.028: E/AndroidRuntime(480): at java.lang.reflect.Method.invoke(Method.java:521)
04-22 14:58:18.028: E/AndroidRuntime(480): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-22 14:58:18.028: E/AndroidRuntime(480): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-22 14:58:18.028: E/AndroidRuntime(480): at dalvik.system.NativeStart.main(Native Method)
04-22 14:58:18.028: E/AndroidRuntime(480): Caused by: java.lang.ClassNotFoundException: net.authorize.ExampleActivity in loader dalvik.system.PathClassLoader[/data/app/net.authorize-1.apk]
04-22 14:58:18.028: E/AndroidRuntime(480): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-22 14:58:18.028: E/AndroidRuntime(480): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-22 14:58:18.028: E/AndroidRuntime(480): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-22 14:58:18.028: E/AndroidRuntime(480): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-22 14:58:18.028: E/AndroidRuntime(480): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-22 14:58:18.028: E/AndroidRuntime(480): ... 11 more
04-22 14:58:44.428: D/AndroidRuntime(503): Shutting down VM
04-22 14:58:44.428: W/dalvikvm(503): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-22 14:58:44.458: E/AndroidRuntime(503): FATAL EXCEPTION: main
04-22 14:58:44.458: E/AndroidRuntime(503): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.authorize/net.authorize.ExampleActivity}: java.lang.ClassNotFoundException: net.authorize.ExampleActivity in loader dalvik.system.PathClassLoader[/data/app/net.authorize-2.apk]
04-22 14:58:44.458: E/AndroidRuntime(503): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-22 14:58:44.458: E/AndroidRuntime(503): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-22 14:58:44.458: E/AndroidRuntime(503): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-22 14:58:44.458: E/AndroidRuntime(503): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-22 14:58:44.458: E/AndroidRuntime(503): at android.os.Handler.dispatchMessage(Handler.java:99)
04-22 14:58:44.458: E/AndroidRuntime(503): at android.os.Looper.loop(Looper.java:123)
04-22 14:58:44.458: E/AndroidRuntime(503): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-22 14:58:44.458: E/AndroidRuntime(503): at java.lang.reflect.Method.invokeNative(Native Method)
04-22 14:58:44.458: E/AndroidRuntime(503): at java.lang.reflect.Method.invoke(Method.java:521)
04-22 14:58:44.458: E/AndroidRuntime(503): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-22 14:58:44.458: E/AndroidRuntime(503): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-22 14:58:44.458: E/AndroidRuntime(503): at dalvik.system.NativeStart.main(Native Method)
04-22 14:58:44.458: E/AndroidRuntime(503): Caused by: java.lang.ClassNotFoundException: net.authorize.ExampleActivity in loader dalvik.system.PathClassLoader[/data/app/net.authorize-2.apk]
04-22 14:58:44.458: E/AndroidRuntime(503): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-22 14:58:44.458: E/AndroidRuntime(503): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-22 14:58:44.458: E/AndroidRuntime(503): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-22 14:58:44.458: E/AndroidRuntime(503): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-22 14:58:44.458: E/AndroidRuntime(503): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-22 14:58:44.458: E/AndroidRuntime(503): ... 11 more
04-22 14:59:24.908: I/Process(503): Sending signal. PID: 503 SIG: 9