サーバー上にもあるxmlからデータ画像のURLを解析するスライダーを作成しました。私のアプリはエミュレーターで正常に動作しており、インターネット許可もマニフェスト ファイルに配置しています。しかし、それはAndroidデバイスでは機能せず、データを取得できません。私を助けてください!
public class SliderActivity extends Activity{
int j=0;
String imageList[];
ImageView imageview;
Button next_button, prev_button;
int no_of_slides;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageview = (ImageView) findViewById(R.id.imageView1);
next_button= (Button) findViewById(R.id.next_button);
prev_button= (Button) findViewById(R.id.prev_button);
try{
/** This section is for xml parsing */
URL url = new URL("my url");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("image");
imageList= new String[nodeList.getLength()];
no_of_slides=nodeList.getLength()-1;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("image");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
imageList[i]= ((Node) nameList.item(0)).getNodeValue();
}
next_button.setOnClickListener(new clicker());
prev_button.setOnClickListener(new clicker());
}catch(Exception e){
System.out.println("Exception appears = " + e);
}
}
class clicker implements Button.OnClickListener{
public void onClick(View v){
/** This section is for next button */
if(v==next_button){
if(j==no_of_slides)
j=0;
else
j=j+1;
try{
imageview.setImageDrawable(grabImageFromUrl(imageList[j]));
}catch(Exception e){
System.out.println("Exception appears = " + e);
}
}
else
/** This section is for prev button */
if(v==prev_button){
if(j==0)
j=no_of_slides;
else
j=j-1;
try{
imageview.setImageDrawable(grabImageFromUrl(imageList[j]));
}catch(Exception e){
System.out.println("Exception appears = " + e);
}
}
}
}
/** This function is to fetch image from URL */
private Drawable grabImageFromUrl(String url) throws Exception {
return Drawable.createFromStream((InputStream)new URL(url).getContent(), "src");
}
}
XML 構造
<images>
<image>http://www.xyz.com/1.jpeg</image>
<image>http://www.xyz.com/1.jpeg</image>
<image>http://www.xyz.com/1.jpeg</image>
</images>
エラーの主な原因
11-09 10:08:56.103: E/System(61): Failure starting core service
11-09 10:08:56.103: E/System(61): java.lang.SecurityException
11-09 10:08:56.103: E/System(61): at android.os.BinderProxy.transact(Native Method)
11-09 10:08:56.103: E/System(61): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
11-09 10:08:56.103: E/System(61): at android.os.ServiceManager.addService(ServiceManager.java:72)
11-09 10:08:56.103: E/System(61): at com.android.server.ServerThread.run(SystemServer.java:176)
これらのメッセージをlogcatで取得します.....