在此处输入代码我在清单中有android:configChanges="orientation"
但由于某种原因在旋转视图后转到下一个活动并NullPointerException
12-03 17:28:42.673: ERROR/AndroidRuntime(10537): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.is.mbank/com.is.mbank.ui.mobileBanking.TransactionConfirmation}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3740)
at android.app.ActivityThread.access$700(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.is.mbank.ui.mobileBanking.TransactionConfirmation.onCreate(TransactionConfirmation.java:45)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
... 12 more
HERE是TransactionConfirmation的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.transaction_confirmation);
paymentUtil = new PaymentUtil(this);
textViewFrom = (TextView) findViewById(R.id.from);
textViewTo = (TextView) findViewById(R.id.to);
textViewAmount = (TextView) findViewById(R.id.amount);
textViewCurrency = (TextView) findViewById(R.id.currency);
from = paymentUtil.paymentData.get(Constants.ACCOUNT_NUMBER_FROM).toString();
它在最后一行产生空指针异常
答案 0 :(得分:1)
当您旋转屏幕时,活动会被销毁并重新生成,因此您应该检查活动是否查找某些参数(可能使用意图等传递),再次生成时它们不存在。
答案 1 :(得分:1)
在清单文件中根据以下内容进行更改
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
希望这可能有用。
答案 2 :(得分:0)
问题解决了,问题是我在onCreate()中为我的意图设置了类,现在我从那里删除了它的工作正常。
感谢您的关注。
的问候,