I have this problem when I follow
http://www.androidhive.info/2014/08/android-building-free-wallpapers-app-part-2/
and got to the point where I add a splash screen and start a Volley request.
The code, which, as stated in the tutorial, is used when creating the JSONObjectRequest,
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET, url, null, new Response.Listener<JSONObject>()
but when I type this, he asks me to import the Volley library, which then changes it to
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>()
Performing this procedure results in an error that is unable to resolve the constructor.
The code that I have in my SplashActivity.java:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class SplashActivity extends Activity {
private static final String TAG = SplashActivity.class.getSimpleName();
private static final String TAG_FEED = "feed", TAG_ENTRY = "entry",
TAG_GPHOTO_ID = "gphoto$id", TAG_T = "$t",
TAG_ALBUM_TITLE = "title";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.activity_splash);
String url = AppConst.URL_PICASA_ALBUMS
.replace("_PICASA_USER_", AppController.getInstance()
.getPrefManager().getGoogleUserName());
Log.d(TAG, "Albums request url: " + url);
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url,
null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "Albums Response: " + response.toString());
List<Category> albums = new ArrayList<Category>();
try {
JSONArray entry = response.getJSONObject(TAG_FEED)
.getJSONArray(TAG_ENTRY);
for (int i = 0; i < entry.length(); i++) {
JSONObject albumObj = (JSONObject) entry.get(i);
String albumId = albumObj.getJSONObject(
TAG_GPHOTO_ID).getString(TAG_T);
String albumTitle = albumObj.getJSONObject(
TAG_ALBUM_TITLE).getString(TAG_T);
Category album = new Category();
album.setId(albumId);
album.setTitle(albumTitle);
albums.add(album);
Log.d(TAG, "Album Id: " + albumId
+ ", Album Title: " + albumTitle);
}
AppController.getInstance().getPrefManager()
.storeCategories(albums);
Intent intent = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(intent);
finish();
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
getString(R.string.msg_unknown_error),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Volley Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
getString(R.string.splash_error),
Toast.LENGTH_LONG).show();
if (AppController.getInstance().getPrefManager()
.getCategories() != null && AppController.getInstance().getPrefManager()
.getCategories().size() > 0) {
Intent intent = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(intent);
finish();
} else {
Intent i = new Intent(SplashActivity.this,
SettingsActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}
}
});
jsonObjReq.setShouldCache(false);
AppController.getInstance().addToRequestQueue(jsonObjReq);
}
}
I'm not sure what to do to fix this?