CopperChimneyPhotos.java
public class CopperChimneyPhotos extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.copper_chimney_photos);
Button btn=(Button) findViewById(R.id.PhotoButton);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent pt=new Intent(CopperChimneyPhotos.this,CopperChimneyDesc.class);
startActivity(pt);
}
});
}
}
CopperChimneyDesc.java
public class CopperChimneyDesc extends Activity{
private static String url = "http://url:7002/xxxx/";
private static String url1 = "http://url:7002/xxxx/";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.copperchimney_desc_screen);
//getting info from listview to display the name in TopNavigationBarCopperChimneyDescActivityName
TextView topdisp=(TextView) findViewById(R.id.TopNavigationBarCopperChimneyDescActivityName);
topdisp.setText(getIntent().getExtras().getString("CC_RES"));
// Creating JSON Parser instance
JSONObjParser jParser = new JSONObjParser();
// getting JSON string from URL
JSONArray json = jParser.getJSONFromUrl(url);
// getting JSON string from URL
JSONArray json1 = jParser.getJSONFromUrl(url1);
try {
for (int i = 0; i < json1.length(); i++) {
JSONObject c = json1.getJSONObject(i);
// Storing each json item in variable
int id = c.getInt("_id");
String TIME = c.getString("RestaurantTime");
TimeMap.put(id, TIME);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
for (int i = 0; i < json.length(); i++) {
JSONObject c = json.getJSONObject(i);
// remaining code
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Button BACKBUTTON=(Button) findViewById(R.id.TopNavigationBarCopperChimneyDescActivityBackButton);
BACKBUTTON.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent emp1=new Intent(CopperChimneyDesc.this,MainActivity.class);
startActivity(emp1);
}
});
Button PHOTOBUTTON=(Button) findViewById(R.id.CopperChimneyPhotosButton);
答案 0 :(得分:2)
您尚未在此处添加任何其他内容
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent pt=new Intent(CopperChimneyPhotos.this,CopperChimneyDesc.class);
startActivity(pt);
CopperChimneyPhotos
中的因此getIntent().getExtras().getString("CC_RES"));
将返回null
。
我不确定您希望该值来自何处,但需要将Intent
添加到Activity
这样的内容,例如
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent pt=new Intent(CopperChimneyPhotos.this,CopperChimneyDesc.class);
pt.putExtra("CC_RES", stringToAdd);
startActivity(pt);
您还可能需要检查getIntent()
和getExtras()
在第二节课中没有返回null
,然后再将值分配给某些内容。当您从extras
转到MainActivity
时,您有Desc
,但从Photos
转到Desc
则没有。
答案 1 :(得分:0)
由于CopperChimneyDesc.java第37行中的错误,您收到错误:
08-16 22:28:56.293: E/AndroidRuntime(360): Caused by: java.lang.NullPointerException
08-16 22:28:56.293: E/AndroidRuntime(360): at com.project.findmybuffet.CopperChimneyDesc.onCreate(CopperChimneyDesc.java:37)
无论您在粘贴的资源中使用哪一行,都会在其中获得NullPointerException
(又名NPE
),这通常意味着您尝试使用不再存在的值,或者某些元素未初始化。