0
ここでは見つからないArray Listのプロパティについて何かありますか?2回目のアレイリストの印刷が正しくないのはなぜですか?
カスタムオブジェクトのリストをリストに追加しています。リストにはそれぞれ固有の名前が付けられています。
リストに2度アクセスすると、リスト内のすべてのオブジェクトが同じになります。私はこれをテストしたときにアクセス間にコードはありません。
// Add all the Tastr Items to the Array list using the list of restaurants found by yelp.
for (int i = 0; i < yelp.getRestaurants().size(); i++){
TastrItem temp = new TastrItem();
temp.setRestaurant(yelp.getRestaurants().get(i));
itemList.add(temp);
System.out.println("First Time Accessing the list --- > " + itemList.get(i).getRestaurant());
}
for (int i = 0; i < yelp.getRestaurants().size(); i++) {
System.err.println("Second time Accessing the list --- > " + itemList.get(i).getRestaurant());
}
出力:
I/System.out: First Time Accessing the list --- > Stanton's City Bites
I/System.out: First Time Accessing the list --- > Aladdin Mediterranean Cuisine
I/System.out: First Time Accessing the list --- > The Breakfast Klub
I/System.out: First Time Accessing the list --- > M&M Grill
I/System.out: First Time Accessing the list --- > Big & Juicy Juice Bar
I/System.out: First Time Accessing the list --- > Eddie V's Prime Seafood
I/System.out: First Time Accessing the list --- > Baby Barnaby's Café
I/System.out: First Time Accessing the list --- > Pappas Bros Steakhouse
I/System.out: First Time Accessing the list --- > Just Dinner
I/System.out: First Time Accessing the list --- > Green Seed Vegan
I/System.out: First Time Accessing the list --- > Local Foods
I/System.out: First Time Accessing the list --- > Salad Extraveganza
I/System.out: First Time Accessing the list --- > Luigi's Pizzeria
I/System.out: First Time Accessing the list --- > Houston's Restaurant
I/System.out: First Time Accessing the list --- > Hugo's
I/System.out: First Time Accessing the list --- > Huynh Restaurant
I/System.out: First Time Accessing the list --- > MKT BAR
I/System.out: First Time Accessing the list --- > Reef
I/System.out: First Time Accessing the list --- > Mockingbird Bistro
I/System.out: First Time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
W/System.err: Second time Accessing the list --- > Pho Saigon Vietnamese
編集:答えはレストラン変数がTastrのアイテム・クラスの静的だったということです。
'yelp.getRestaurants()。get(i)'とは何ですか? 'List'インターフェースやカスタムメソッドの' get() 'ですか? – Emmanuel
ArrayListからのgetメソッド。それは大きさを返します、IEのレストランの量が見つかりました。 – Remixt
'TastrItem'のコードを投稿する必要があります。私はそこに静的変数があると思う。 – lionscribe