我在这个问题上遇到了麻烦,我无法继续前进,现在卡住了将近 2 天。
这就是我想要的 照片在照片 1 下方 http://leyth.dk/upload/server/php/files/Activity%202.png 照片 1 http://leyth.dk/upload/server/php/files/picture %201.png
我有 json 列表,它工作正常。当我按下 --> ITEM NUMBER X时,它会正常启动新活动,它会显示具有给定 lat 和 long 值的地图
但我也想通过列表获取更多值到 2.activity 中。
我可以想象的是我对 XML 文件有问题,可能是膨胀或类似的东西。我放了一些代码,所以你可以看到它。
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.list_item,
new String[] { TAG_LAT, TAG_LNG, TAG_POSTAL }, new int[] {
R.id.name, R.id.email, R.id.mobile });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
String cost = ((TextView) view.findViewById(R.id.email)).getText().toString();
String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString();
--> here is fail, it cant find textview1 --> gives null pointer exception
--> its different xml file. And here is the error appers
String mandag = ((TextView) view.findViewById(R.id.textView1)).getText().toString();
String tirsdag = ((TextView) view.findViewById(R.id.textView2)).getText().toString();
String onsdag = ((TextView) view.findViewById(R.id.textView3)).getText().toString();
String torsdag = ((TextView) view.findViewById(R.id.textView4)).getText().toString();
String fredag = ((TextView) view.findViewById(R.id.textView5)).getText().toString();
String lordag = ((TextView) view.findViewById(R.id.textView6)).getText().toString();
String sondag = ((TextView) view.findViewById(R.id.textView7)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), dk.mitaffald.maps.MainActivity.class);
in.putExtra(TAG_LAT, name);
in.putExtra(TAG_LNG, cost);
in.putExtra(TAG_Company, description);
in.putExtra(TAG_MONDAY, mandag);
in.putExtra(TAG_TUESDAY, tirsdag);
in.putExtra(TAG_WEDNESDAY, onsdag);
in.putExtra(TAG_THURSDAY, torsdag);
in.putExtra(TAG_FRIDAY, fredag);
in.putExtra(TAG_SATURDAY, lordag);
in.putExtra(TAG_SUNDAY, sondag);
Log.d(TAG, "Leyth Days = Mandag : " + mandag +" Onsdag : " + fredag);
startActivity(in);
}
});
这是日志猫
02-27 10:55:28.441: E/AndroidRuntime(10980): FATAL EXCEPTION: main
02-27 10:55:28.441: E/AndroidRuntime(10980): java.lang.NullPointerException
02-27 10:55:28.441: E/AndroidRuntime(10980): at dk.mitaffald.main.LocationBased$1.onItemClick(LocationBased.java:188)
02-27 10:55:28.441: E/AndroidRuntime(10980): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-27 10:55:28.441: E/AndroidRuntime(10980): at android.widget.ListView.performItemClick(ListView.java:3763)
02-27 10:55:28.441: E/AndroidRuntime(10980): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1936)
02-27 10:55:28.441: E/AndroidRuntime(10980): at android.os.Handler.handleCallback(Handler.java:587)
02-27 10:55:28.441: E/AndroidRuntime(10980): at android.os.Handler.dispatchMessage(Handler.java:92)
02-27 10:55:28.441: E/AndroidRuntime(10980): at android.os.Looper.loop(Looper.java:123)
02-27 10:55:28.441: E/AndroidRuntime(10980): at android.app.ActivityThread.main(ActivityThread.java:3691)
02-27 10:55:28.441: E/AndroidRuntime(10980): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 10:55:28.441: E/AndroidRuntime(10980): at java.lang.reflect.Method.invoke(Method.java:507)
02-27 10:55:28.441: E/AndroidRuntime(10980): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
02-27 10:55:28.441: E/AndroidRuntime(10980): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
02-27 10:55:28.441: E/AndroidRuntime(10980): at dalvik.system.NativeStart.main(Native Method)
Textview1 的 XML 文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="300dp"
class="com.google.android.gms.maps.SupportMapFragment" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />