有人可以告訴我爲什麼這導致我的應用程序崩潰?這同樣的代碼適用於我的其他應用程序,這就是爲什麼我很困惑。Android:使用從*字符拆分從php頁面檢索字符串
我想要做的是告訴我的應用程序去http://omarcomputerservices.com/cartoons/cartoons.php?getCartoon&ID=1,然後從'*'字符拆分分析的字符串。然後將其添加到數組中。
我已經添加了互聯網權限。
package com.omarreyes.youtubechannels;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
public class StartingPoint extends Activity
{
ArrayList<String> images = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starting_point);
Button get = (Button) findViewById(R.id.button1);
get.setOnClickListener(listener);
}
private OnClickListener listener = new OnClickListener()
{
public void onClick(View v)
{
getImages();
}
};
private void getImages()
{
try
{
// Create a URL object
URL url = new URL("http://omarcomputerservices.com/cartoons/cartoons.php?getCartoon&ID=1");
// Read all of the text returned by the HTTP server
BufferedReader in = new BufferedReader
(new InputStreamReader(url.openStream()));
String htmlText;
while ((htmlText = in.readLine()) != null)
{
// Keep in mind that readLine() strips the newline characters
String[] data = htmlText.split("\\*");
images.add(data[0].toString());
}
in.close();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
請發佈您的完整logcat請! – Gridtestmail