在我的应用程序中,我需要将我的arraylist转换为数组的字符串.但是,我收到一个错误:
ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[] android
Run Code Online (Sandbox Code Playgroud)
在listofurls我收到错误的行:listofurls = (String[])image_urls.toArray();
这是完整的代码:
public class Test2 extends AsyncTask<Void, Void, Void>
{
String[] listofurls ;
private static final String url = "http://www.tts.com/album_pro/array_to_encode";
JSONParser jParser = new JSONParser();
ArrayList<String> image_urls = new ArrayList<String>();
protected void onPreExecute() {
//Log.e(LOG_CLASS, "in side assyntask");
}
protected Void doInBackground(Void... voids) {
Log.v("Async","Async");
JSONObject json = jParser.getJSONFromUrl(url);
try {
JSONObject seo = json.getJSONObject("SEO");
JSONArray folio = seo.getJSONArray("Folio");
// JSONArray image_urls1 = new JSONArray();
//String …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我正在显示来自图库的图像,一旦我选择一个图像,图像应该被发送到新活动,其中所选图像将被设置为背景.但是,我能够获取图像从图库,但一旦我选择一个应用程序崩溃.谢谢提前
活动-1(图像显示在图库中,所选图像将发送到新活动)
public class Gallery extends Activity {
private static int RESULT_LOAD_IMAGE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri …Run Code Online (Sandbox Code Playgroud)