我陷入困境并面临android中的intent-filter问题!
在我的应用中,当用户点击buy product
按钮时,用户将被重定向到互联网浏览器(Chrome等),付款后,用户应该返回应用,但NullPinterException
活动中onCreate
发生了我使用了TextView
,ImageView
。
我不知道为什么会出现这个问题,请帮忙!
ActivityPayment.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment);
Utils.toast("onCreate");
initUI();
Bundle extras = getIntent().getExtras();
if (extras != null) {
final ModelVoucher v = (ModelVoucher) extras.get("voucher");
Picasso.with(G.currentActivity)
.load(G.URL + v.imageUrl)
.placeholder(R.mipmap.img_holder)
.error(R.mipmap.img_holder)
.into(imgVoucher);
txtTitle.setText(v.title);
txtUnitPrice.setText(v.payPrice);
txtPayableAmount.setText((v.payPrice * count));
List<String> list = new ArrayList<>();
list.add("1");
list.add("2");
list.add("3");
SpinnerAdapter adapter = new SpinnerAdapter(G.context, R.layout.spinner_item, list);
spnCount.setAdapter(adapter);
spnCount.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String selected = spnCount.getSelectedItem().toString();
count = Integer.valueOf(selected.trim());
txtPayableAmount.setText(v.payPrice * count );
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
lyFinalizeBuy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new RequestPayment(new IRequest() {
@Override
public void onCompeletd(final ModelResult result) {
G.handler.post(new Runnable() {
@Override
public void run() {
if (result.success) {
Intent paymentPage = new Intent(Intent.ACTION_VIEW);
paymentPage.setData(Uri.parse(G.URL + "/payment/pay/" + result.paymentHash));
startActivity(paymentPage);
} else {
Utils.toast(result.message, true);
}
}
});
}
@Override
public void onFailed(int status) {
}
}).beforePay(v.id + "", count + "");
}
});
}
new RequestProfile(new IRequest() {
@Override
public void onCompeletd(final ModelResult result) {
G.handler.post(new Runnable() {
@Override
public void run() {
if (result.success) {
txtBalance.setText(result.user.balance);
} else {
Utils.toast(result.message);
}
}
});
}
@Override
public void onFailed(int status) {
}
}).getBaseInfo();
}
Stack Trace
> 12-04 12:56:26.507 12350-12350/ir.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.myapplication/ir.myapplication.ActivityPayment}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.access$600(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at ir.myapplication.ActivityPayment.onCreate(ActivityPayment.java:56)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.access$600(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
发生异常的56行:
Picasso.with(G.currentActivity)
.load(G.URL + v.imageUrl)
.placeholder(R.mipmap.img_holder)
.error(R.mipmap.img_holder)
.into(imgVoucher);
答案 0 :(得分:1)
您可以使用以下代码吗?
空指针存在问题。
如何发送对象:
ClassName details = new ClassName();
Intent i = new Intent(context, EditActivity.class);
i.putExtra("Editing", details);
startActivity(i);
如何接收对象:
ClassName model = (ClassName) getIntent().getSerializableExtra("Editing");
您的模型类必须已实施,因为可序列化。
Class ClassName implements Serializable {
}
我希望你的问题能够解决。