我使用DOM xml解析器并尝试更新文件" infData.xml"我上传到服务器网站上。
当我在一个单独的项目中编写代码时工作正常;但是,当我尝试使用代码到我的主项目时,我没有得到任何回应。
RootActivity.java
public class RootActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_root);
Button btn_event = (Button)findViewById(R.id.btn_event);
btn_event.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(RootActivity.this ,DataXml.class );
startActivity(intent);
finish();
}
});
}
DataXML.java
public class DataXml extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(1);
View view = this.getWindow().getDecorView();
view.setBackgroundColor(0xfff00000);
TextView name[];
TextView Date[];
TextView Description[];
// Get data From XML and show data ...
try {
URL url = new URL("http://kanoonweb.net/App_Update/infData.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("item");
name = new TextView[nodeList.getLength()];
Date = new TextView[nodeList.getLength()];
Description = new TextView[nodeList.getLength()];
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
name[i] = new TextView(this);
Date[i] = new TextView(this);
Description[i] = new TextView(this);
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("name");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
name[i].setText("Name = "
+ ((Node) nameList.item(0)).getNodeValue());
//-------------
NodeList DateList = fstElmnt.getElementsByTagName("date");
Element DateElement = (Element) DateList.item(0);
DateList = DateElement.getChildNodes();
Date[i].setText("Date = "
+ ((Node) DateList.item(0)).getNodeValue());
//-------------
NodeList desList = fstElmnt.getElementsByTagName("description");
Element deseElement = (Element) desList.item(0);
desList = deseElement.getChildNodes();
Description[i].setText("Description = "
+ ((Node) desList.item(0)).getNodeValue());
//-------------
layout.addView(name[i]);
layout.addView(Date[i]);
layout.addView(Description[i]);
}
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
setContentView(layout);
}
// End Get data From XML and show data ...
}
LogCat:
FATAL EXCEPTION: main
05-22 04:55:46.938: E/AndroidRuntime(1204): Process: com.example.artgallery, PID: 1204
05-22 04:55:46.938: E/AndroidRuntime(1204): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.artgallery/com.example.artgallery.DataXml}; have you declared this activity in your AndroidManifest.xml?
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.app.Activity.startActivityForResult(Activity.java:3424)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.app.Activity.startActivityForResult(Activity.java:3385)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.app.Activity.startActivity(Activity.java:3627)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.app.Activity.startActivity(Activity.java:3595)
05-22 04:55:46.938: E/AndroidRuntime(1204): at com.example.artgallery.RootActivity$2.onClick(RootActivity.java:38)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.view.View.performClick(View.java:4438)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.view.View$PerformClick.run(View.java:18422)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.os.Handler.handleCallback(Handler.java:733)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.os.Handler.dispatchMessage(Handler.java:95)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.os.Looper.loop(Looper.java:136)
05-22 04:55:46.938: E/AndroidRuntime(1204): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-22 04:55:46.938: E/AndroidRuntime(1204): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 04:55:46.938: E/AndroidRuntime(1204): at java.lang.reflect.Method.invoke(Method.java:515)
05-22 04:55:46.938: E/AndroidRuntime(1204): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-22 04:55:46.938: E/AndroidRuntime(1204): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-22 04:55:46.938: E/AndroidRuntime(1204): at dalvik.system.NativeStart.main(Native Method)
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.artgallery"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.artgallery.SplashScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.artgallery.DataXml"
android:label="@string/title_activity_data_xml" >
</activity>
<activity
android:name="com.example.artgallery.RootActivity"
android:label="@string/title_activity_root" >
</activity>
<activity
android:name="com.example.artgallery.Left"
android:label="@string/title_activity_left" >
</activity>
</application>
</manifest>
我是Android新手。