我有一堆EditTexts
,我想使用Intents
將從EditTexts
獲得的數據傳遞給另一個Activity
。每當我運行該應用程序,它會得到一個運行時錯誤或類似的東西和崩潰。 Logcat說我的應用程序在線程上做了太多工作。有沒有辦法解決?可以進入意圖的最大附加數量是多少?
這裏是我的代碼:
@Override
public void onClick(View v) {
final Intent a = new Intent (getApplicationContext(), Cooling.class);
a.putExtra("value15", 15f * Double.valueOf(edit15watt.getText().toString()));
a.putExtra("value20", 20f * Double.valueOf(edit20watt.getText().toString()));
a.putExtra("value40", 40f * Double.valueOf(edit40watt.getText().toString()));
a.putExtra("value60", 60f * Double.valueOf(edit60watt.getText().toString()));
a.putExtra("value75", 75f * Double.valueOf(edit75watt.getText().toString()));
a.putExtra("value100", 100f * Double.valueOf(edit100watt.getText().toString()));
a.putExtra("value11", 11f * Double.valueOf(edit11watt.getText().toString()));
a.putExtra("value18", 18f * Double.valueOf(edit18watt.getText().toString()));
a.putExtra("value23", 23f * Double.valueOf(edit23watt.getText().toString()));
a.putExtra("value50", 50f * Double.valueOf(edit50watt.getText().toString()));
a.putExtra("value90", 90f * Double.valueOf(edit90watt.getText().toString()));
a.putExtra("value200", 200f * Double.valueOf(edit200watt.getText().toString()));
a.putExtra("value250", 250f * Double.valueOf(edit250watt.getText().toString()));
startActivity(a);
}
這是logcat的說什麼
04-17 08:20:57.197: E/AndroidRuntime(1102): FATAL EXCEPTION: main
04-17 08:20:57.197: E/AndroidRuntime(1102): Process: com.emma.finalyearproject, PID: 1102
04-17 08:20:57.197: E/AndroidRuntime(1102): java.lang.NumberFormatException: Invalid double: ""
04-17 08:20:57.197: E/AndroidRuntime(1102): at java.lang.StringToReal.invalidReal(StringToReal.java:63)
04-17 08:20:57.197: E/AndroidRuntime(1102): at java.lang.StringToReal.parseDouble(StringToReal.java:248)
04-17 08:20:57.197: E/AndroidRuntime(1102): at java.lang.Double.parseDouble(Double.java:295)
04-17 08:20:57.197: E/AndroidRuntime(1102): at java.lang.Double.valueOf(Double.java:332)
04-17 08:20:57.197: E/AndroidRuntime(1102): at com.emma.finalyearproject.Lighting$1.onClick(Lighting.java:43)
04-17 08:20:57.197: E/AndroidRuntime(1102): at android.view.View.performClick(View.java:4424)
04-17 08:20:57.197: E/AndroidRuntime(1102): at android.view.View$PerformClick.run(View.java:18383)
04-17 08:20:57.197: E/AndroidRuntime(1102): at android.os.Handler.handleCallback(Handler.java:733)
04-17 08:20:57.197: E/AndroidRuntime(1102): at android.os.Handler.dispatchMessage(Handler.java:95)
04-17 08:20:57.197: E/AndroidRuntime(1102): at android.os.Looper.loop(Looper.java:137)
04-17 08:20:57.197: E/AndroidRuntime(1102): at android.app.ActivityThread.main(ActivityThread.java:4998)
04-17 08:20:57.197: E/AndroidRuntime(1102): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 08:20:57.197: E/AndroidRuntime(1102): at java.lang.reflect.Method.invoke(Method.java:515)
04-17 08:20:57.197: E/AndroidRuntime(1102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
04-17 08:20:57.197: E/AndroidRuntime(1102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
04-17 08:20:57.197: E/AndroidRuntime(1102): at dalvik.system.NativeStart.main(Native Method)
這是不是您要添加額外的號碼,但是工作,你正在做的UI線程。 OnClick()在UI線程上運行,如果需要執行長時間運行操作,則必須在單獨的線程中執行相同操作! –
檢查此鏈接:http://stackoverflow.com/questions/12496700/maximum-length-of-intent-putextra-method-force-close – prakash
請顯示LogCat的內容 – Manu