他の (Google) アクティビティにインテントを作成する行でヌル ポインター例外が発生します。startActivity(go)
内部クラス MyEventHandler の onclick メソッドで呼び出されます。どこが間違っているのか教えてください。私はアンドロイドが初めてです。
**package pack.Assignment;**
public class Landing extends Activity {
// url to make request
private static String url = "http://playup-jo.s3.amazonaws.com/dev/config.json";
private ProgressDialog pDialog;
ImageView img;
// tiles JSONArray
JSONArray tiles=null;
private String server;
Intent go = new Intent(getApplicationContext(), Google.class);
// JSON Node names
private static final String TAG_SERVER = "server";
private static final String TAG_TILES = "tiles";
private static final String TAG_IMAGE = "image";
private static final String TAG_URL = "url";
private static final String TAG_MDPI = "mdpi";
private static final String TAG_NAME = "name";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.landing);
// Loading JSON in Background Thread
new LoadJSON().execute();
}
/**
* Background Async Task to Load all INBOX messages by making HTTP Request
* */
class LoadJSON extends AsyncTask<String, String, Bitmap> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Landing.this);
pDialog.setMessage("Loading ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting JSON
* */
protected Bitmap doInBackground(String... args) {
// getting JSON string from URL
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url);
Bitmap bitmap=null;
try {
server = json.getString("server");
// Getting Array of Tiles
tiles = json.getJSONArray(TAG_TILES);
// looping through All Tiles
for(int i = 0; i < tiles.length(); i++){
JSONObject c = tiles.getJSONObject(i);
// Storing json item in variable
String name = c.getString(TAG_NAME);
System.out.println("name :"+name);
// mdpi is again JSONObject
JSONObject mdpi= c.getJSONObject(TAG_MDPI);
String image=mdpi.getString(TAG_IMAGE);
String image_url = server+image;
String url=mdpi.getString(TAG_URL);
// Using the variable to get the bitmap
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(image_url).getContent());
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
catch (JSONException e) {
e.printStackTrace();
}
return bitmap;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(final Bitmap result) {
// dismiss the dialog after getting all products
pDialog.dismiss();
img = (ImageView)findViewById(R.id.image);
img.setImageBitmap(result);
MyEventHandler myEvHandler = new MyEventHandler();
// making the downloaded image clickable
img.setOnClickListener(myEvHandler);
}
}
class MyEventHandler implements OnClickListener
{
public void onClick(View v)
{
if (v instanceof ImageView)
{
startActivity(go);
}
}
}
}