我收到以下異常,同時試圖從解析數列中檢索號碼 - NumberFormatException異常:無效INTNumberFormatException異常:無效INT - 字符串
我想找回號碼,然後顯示TextView的數量。我已經能夠通過字符串來實現這一點,但在編號方面存在困難。
下面是logcat的消息:
09-02 10:00:27.881: E/AndroidRuntime(1267): FATAL EXCEPTION: main
09-02 10:00:27.881: E/AndroidRuntime(1267): Process: com.dooba.beta, PID: 1267
09-02 10:00:27.881: E/AndroidRuntime(1267): java.lang.NumberFormatException: Invalid int: "UserAge"
09-02 10:00:27.881: E/AndroidRuntime(1267): at java.lang.Integer.invalidInt(Integer.java:137)
09-02 10:00:27.881: E/AndroidRuntime(1267): at java.lang.Integer.parse(Integer.java:374)
09-02 10:00:27.881: E/AndroidRuntime(1267): at java.lang.Integer.parseInt(Integer.java:365)
09-02 10:00:27.881: E/AndroidRuntime(1267): at java.lang.Integer.parseInt(Integer.java:331)
09-02 10:00:27.881: E/AndroidRuntime(1267): at com.dooba.beta.Fragment1$6.done(Fragment1.java:371)
09-02 10:00:27.881: E/AndroidRuntime(1267): at com.parse.FindCallback.internalDone(FindCallback.java:45)
09-02 10:00:27.881: E/AndroidRuntime(1267): at com.parse.FindCallback.internalDone(FindCallback.java:31)
09-02 10:00:27.881: E/AndroidRuntime(1267): at com.parse.Parse$5$1.run(Parse.java:891)
09-02 10:00:27.881: E/AndroidRuntime(1267): at android.os.Handler.handleCallback(Handler.java:733)
09-02 10:00:27.881: E/AndroidRuntime(1267): at android.os.Handler.dispatchMessage(Handler.java:95)
09-02 10:00:27.881: E/AndroidRuntime(1267): at android.os.Looper.loop(Looper.java:136)
09-02 10:00:27.881: E/AndroidRuntime(1267): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-02 10:00:27.881: E/AndroidRuntime(1267): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 10:00:27.881: E/AndroidRuntime(1267): at java.lang.reflect.Method.invoke(Method.java:515)
09-02 10:00:27.881: E/AndroidRuntime(1267): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-02 10:00:27.881: E/AndroidRuntime(1267): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-02 10:00:27.881: E/AndroidRuntime(1267): at dalvik.system.NativeStart.main(Native Method)
下面是代碼
query5.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> objects,ParseException e) {
for(int i=0;i<objects.size();i++){
// Do whatever you need to extract object from "users"
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
query.whereGreaterThanOrEqualTo("UserAge", minimumAge);
query.whereLessThanOrEqualTo("UserAge", maximumAge);
mUserAgeRetrieved = (TextView) getActivity().findViewById(R.id.userlistage);
String str = "UserAge";
int iage = Integer.parseInt(str);
mUserAgeRetrieved.setText(iage);
}
}//for loop
});
只是爲了對比,下面是我如何檢索字符串:
mUserNameRetrieved.setText(objects.get(i).get("Name").toString());
「UserAge」 是指解析數字列,我打電話來檢索它中的數字。
在此先感謝
'字符串str = 「UserAge」; INT iage =的Integer.parseInt(STR);''== INT iage = Integer.parseInt(「UserAge」);'=='NumberFormatException'因爲'「UserAge」'不是數字!這不是一個火箭科學...... – Selvin 2014-09-02 10:27:28