Eclipse 无法在 ASUS eee TF101 上调试
我正在尝试在我的 ASUS eee TF101 (未 root) 上调试一个应用程序,但它无法正常工作。每当我在 Esclipse 中单击“调试”时,我的华硕都会显示“应用程序......已意外停止。请重试。”错误信息。我可以在我的 EVO(已取得 root 权限)和 DroidX(未取得 root 权限)上运行此程序,没有任何问题。我已确保已应用所有适用的设置(设置用于开发的设备) 也是如此,但它仍然不起作用。奇怪的是,如果我在 onCreate 事件中的第二行代码上放置一个断点,它甚至不会在那里中断:
boolean bNetworkConnected = true;
我认为一个简单的赋值语句可以用于断点,但它不会在那里中断。
对发生的事情有什么想法吗?
更新
Maxim,我也无法在发布模式下运行它。我已确保 MainActivity 是清单文件中指定的(请记住,它在我的 evo 和 droidx 上运行)。这是我在发布模式下运行 LogCat 时的副本:
02-14 10:31:21.107: D/dalvikvm(5934): GC_FOR_ALLOC freed 43K, 4% free 6370K/6595K, paused 40ms
02-14 10:31:21.117: I/dalvikvm-heap(5934): Grow heap (frag case) to 6.767MB for 513744-byte allocation
02-14 10:31:21.157: D/dalvikvm(5934): GC_FOR_ALLOC freed <1K, 4% free 6872K/7111K, paused 25ms
02-14 10:31:21.197: E/GetStringFromWebService ERROR-(5934): java.lang.RuntimeException: android.os.NetworkOnMainThreadException
02-14 10:31:21.207: E/GetStringFromWebService ERROR-(5934): java.lang.RuntimeException: android.os.NetworkOnMainThreadException
02-14 10:31:21.207: E/GetIntFromWebService ERROR-(5934): java.lang.RuntimeException: java.lang.NumberFormatException: Invalid int: "null"
02-14 10:31:21.207: E/GetStringFromWebService ERROR-(5934): java.lang.RuntimeException: android.os.NetworkOnMainThreadException
02-14 10:31:21.207: D/AndroidRuntime(5934): Shutting down VM
02-14 10:31:21.207: W/dalvikvm(5934): threadid=1: thread exiting with uncaught exception (group=0x40221760)
02-14 10:31:21.227: D/dalvikvm(5934): GC_CONCURRENT freed 67K, 3% free 6908K/7111K, paused 2ms+4ms
02-14 10:31:21.227: E/AndroidRuntime(5934): FATAL EXCEPTION: main
02-14 10:31:21.227: E/AndroidRuntime(5934): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adacel.app/com.adacel.app.MainActivity}: java.lang.NullPointerException
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.access$500(ActivityThread.java:122)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.os.Looper.loop(Looper.java:132)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.main(ActivityThread.java:4123)
02-14 10:31:21.227: E/AndroidRuntime(5934): at java.lang.reflect.Method.invokeNative(Native Method)
02-14 10:31:21.227: E/AndroidRuntime(5934): at java.lang.reflect.Method.invoke(Method.java:491)
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-14 10:31:21.227: E/AndroidRuntime(5934): at dalvik.system.NativeStart.main(Native Method)
02-14 10:31:21.227: E/AndroidRuntime(5934): Caused by: java.lang.NullPointerException
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.adacel.app.MainActivity.GetLatestData(MainActivity.java:300)
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.adacel.app.MainActivity.LoadWithNetworkConnectivity(MainActivity.java:220)
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.adacel.app.MainActivity.onCreate(MainActivity.java:79)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.Activity.performCreate(Activity.java:4397)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
02-14 10:31:21.227: E/AndroidRuntime(5934): ... 11 more
看起来好像在方法 GetStringFromWebService 上出错了。但奇怪的是......这个调用直到 MainActivity 中才进行......我上面的赋值调用 (bNetworkConnected = true) 是第二行代码,就在 super.onCreate(savedInstance) 之后。 ..所以好像它甚至没有看到我在那里设置的断点。
MainActivity 代码
public static final String TAG = "SQLiteDebug";
private ListView mListViewIssues;
private static final String NameSpace = "RemoteWebService";
private static final String URL = "http://ws.simcare.biz/Service1.asmx";
private static final String DBVersionKey = "DBVersion";
private static final String PreferencesNotLoaded = "User Preferences could not be loaded. \n\nThis app will now close.";
private static final String CustomerCodeNotLoaded = "The Customer Code could not be loaded. \n\nThis app will now close.";
private static final String LocationShortNameNotLoaded = "The Location Short Name could not be loaded. \n\nThis app will now close.";
private static final String DBVersionNotLoaded = "The Database Version could not be loaded. \n\nThis app will now close.";
private static final String App_File = "app_file.xml";
private static final String AppNotConnectedTitle = "App Not Connected to Network";
Boolean ConnectedToNetwork = false;
TextView tvFooter;
int DBVersion = 1;
IssueInfoCreator creator;
AppPreferences appPrefs = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.footer_layout);
//For testing network connectivity only.
boolean bNetworkConnected = true;
//If there's a network connection available, get latest data.
//if(NetworkUtils.getInstance(this).isOnline(this)){
if(bNetworkConnected){
//Load data from web service and get latest data.
LoadWithNetworkConnectivity();
}
else{
InputStream isAppFile = null;
try {
isAppFile = getBaseContext().getAssets().open(App_File);
} catch (IOException e) {
ShowMessageAndClose(PreferencesNotLoaded);
return;
}
Scanner scanner = new Scanner(isAppFile);
String sScannerContents = scanner.useDelimiter("\\A").next();
Document doc = XMLfunctions.XMLfromString(sScannerContents);
try{
if(LoadPreferences(doc))
DBVersion = Integer.valueOf(appPrefs.getDBVersion());
}catch(Exception ex){
Log.e("INT PARSE ERROR", ex.getStackTrace().toString());
}
//Load data from local db only.
LoadWithoutNetworkConnectivity();
}
//Load listview control.
setContentView(R.layout.main);
//Setup Refresh button listener.
Button btn = (Button) findViewById(R.id.btnRefresh);
btn.setOnClickListener(btnRefreshClick);
final Context context = getBaseContext();
mListViewIssues = (ListView)findViewById(R.id.listIssues);
//Load Footer View.
View footerView =((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
tvFooter = (TextView)footerView.findViewById(R.id.footerText);
tvFooter.setText("DBVersion = " + String.valueOf(DBVersion));
mListViewIssues.addFooterView(footerView);
creator = new IssueInfoCreator(this, DBVersion);
creator.open();
//add data to listview through adapter.
mListViewIssues.setAdapter(new IssueInfoAdapter(this, creator.queryAll()));
creator.close();
}
LoadWithNetworkConnectivity 代码:
private void LoadWithNetworkConnectivity(){
//Set the Titlebar to the stored value in the DB.
String SoapAction = "RemoteWebService/GetApplicationTitle";
String MethodName = "GetApplicationTitle";
setTitle(GetStringFromWebService(NameSpace, MethodName, SoapAction, URL, "ApplicationName", "AndroidApp"));
//Get the DBVersion.
SoapAction = "RemoteWebService/GetDBVersion";
MethodName = "GetDBVersion";
DBVersion = GetIntFromWebService(NameSpace, MethodName, SoapAction, URL, "ApplicationName", "AndroidApp");
//Write DBVersion to Preferences.
Editor ePreferences = this.getPreferences(Context.MODE_PRIVATE).edit();
ePreferences.putInt(DBVersionKey, DBVersion);
ePreferences.commit();
//Get Issues for this Customer/Location.
SoapAction = "RemoteWebService/GetOpenIssues";
MethodName = "GetOpenIssues";
SoapPrimitive xmlData = GetDataFromWebService(NameSpace, MethodName, SoapAction, URL, "ApplicationName", "AndroidApp");
try {
GetLatestData(xmlData);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//Set flag.
ConnectedToNetwork = true;
}
GetDataFromWebService 代码:
public SoapPrimitive GetDataFromWebService(String NameSpace, String MethodName, String SoapAction, String URL, String argName, String argValue){
try {
SoapObject request = new SoapObject(NameSpace, MethodName);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
request.addProperty(argName, argValue);
if(MethodName == "GetOpenIssues")
{
request.addProperty("CustomerCode", "ABC");
request.addProperty("LocationShortName", "KBIF");
}
envelope.setOutputSoapObject(request);
androidHttpTransport.call(SoapAction, envelope);
SoapPrimitive responseData = (SoapPrimitive) envelope.getResponse();
return responseData;
}
catch (Exception e) {
Log.e("GetStringFromWebService ERROR-", new RuntimeException(e).toString());
return null;
}
}
GetLatestData 代码:
public void GetLatestData(SoapPrimitive xml)throws ParserConfigurationException, SAXException, IOException{
//get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc;
//parse using builder to get DOM representation of the XML file
InputSource is = new InputSource(new StringReader(xml.toString()));
doc = db.parse(is);
//Clear out Issues table first.
creator = new IssueInfoCreator(this, DBVersion);
creator.open();
creator.ClearIssueTable();
creator.close();
NodeList nodes = doc.getElementsByTagName("Table");
for(int i = 0; i < nodes.getLength(); i++) {
IssueInfo issue = new IssueInfo();
Element e = (Element)nodes.item(i);
issue.setIssueNumber(Long.parseLong(XMLfunctions.getValue(e, "IssueID")));
issue.setIssueSummary(XMLfunctions.getValue(e, "IssueSummary"));
issue.setDateReceived(DateFormat.format("MM/dd/yyyy hh:mm:ss", System.currentTimeMillis()).toString());
if(issue.getIssueNumber() > 0 && issue.getIssueSummary() != null){
creator = new IssueInfoCreator(this, DBVersion);
creator.open();
creator.InsertIssue(issue.getIssueNumber(), issue.getDateReceived(), issue.getIssueSummary());
creator.close();
}
}
}
这是您请求的代码......简而言之,应用程序启动,检查是否有有效的网络连接(在本例中,我只是放置了一个 bool 标志,这样我就不必不断拔掉我的电缆或断开我的 wifi 来使其工作/不工作),并且它运行适当的方法。我将标志设置为 true,因此它调用 LoadWithNetworkConnectivity() 方法...此方法会发送到我们的 .NET Web 服务并获取应用程序标题、DBVersion 和 OpenIssues。然后,在此方法中,它调用“GetLatestData”方法并将 XML 解析为我创建的 Issue 对象。再说一次,所有这些都可以在模拟器、evo 和 droidx 上找到,但不是我的华硕平板电脑。
更新 #2 - 解决方案
我跳过了尝试让我的平板电脑进行调试的工作,并为 3.2 操作系统创建了一个模拟器(我之前在 2.3.3 模拟器上运行它)。所以现在我可以调试并查看错误来自哪里。它似乎在以下行中首先出错:
setTitle(GetStringFromWebService(NameSpace, MethodName, SoapAction, URL, "ApplicationName", "AndroidApp"));
如果我将其放入字符串中,它会返回 null,而我在 LogCat 中得到的错误是:
02-14 16:01:21.177: E/GetStringFromWebService ERROR-(510): java.lang.RuntimeException: android.os.NetworkOnMainThreadException
就像 Maxim 所说,您必须将网络内容放在它自己的线程上。 Android SDK 文档也对此进行了解释NetworkOnMainThreadException。它所说的不真实...它在旧平台上允许,但在 Honeycomb 及以上平台上不允许,这就是华硕平板电脑正在运行的平台,这就是出现错误的原因。
感谢马克西姆帮助我!一旦我获得将网络事件放在它自己的线程上的代码,我将尝试更新这篇文章,以便其他人知道。
I've got an app that I'm trying to debug on my ASUS eee TF101 (not rooted) and it's not working. Whenever I click "debug" in Esclipse, my ASUS shows the "The application .... has stopped unexpectedly. Please try again." error message. I'm able to run this on my EVO (rooted) and a DroidX (non-rooted) without any issues. I've made sure all the applicable settings have been applied (Setting up a Device for Development) as well but it still doesn't work. The strange part is if I put a breakpoint on the 2nd line of code in the onCreate event, it doesn't even break there:
boolean bNetworkConnected = true;
I figured a simple assignment statement would work for a breakpoint but it doesn't break there.
Any ideas as to what's going on?
UPDATE
Maxim, I cannot run it in release mode either. I've made sure the MainActivity is the one specified in the manifest file (remember, this runs on my evo and droidx). Here's a copy of LogCat when I ran it in Release mode:
02-14 10:31:21.107: D/dalvikvm(5934): GC_FOR_ALLOC freed 43K, 4% free 6370K/6595K, paused 40ms
02-14 10:31:21.117: I/dalvikvm-heap(5934): Grow heap (frag case) to 6.767MB for 513744-byte allocation
02-14 10:31:21.157: D/dalvikvm(5934): GC_FOR_ALLOC freed <1K, 4% free 6872K/7111K, paused 25ms
02-14 10:31:21.197: E/GetStringFromWebService ERROR-(5934): java.lang.RuntimeException: android.os.NetworkOnMainThreadException
02-14 10:31:21.207: E/GetStringFromWebService ERROR-(5934): java.lang.RuntimeException: android.os.NetworkOnMainThreadException
02-14 10:31:21.207: E/GetIntFromWebService ERROR-(5934): java.lang.RuntimeException: java.lang.NumberFormatException: Invalid int: "null"
02-14 10:31:21.207: E/GetStringFromWebService ERROR-(5934): java.lang.RuntimeException: android.os.NetworkOnMainThreadException
02-14 10:31:21.207: D/AndroidRuntime(5934): Shutting down VM
02-14 10:31:21.207: W/dalvikvm(5934): threadid=1: thread exiting with uncaught exception (group=0x40221760)
02-14 10:31:21.227: D/dalvikvm(5934): GC_CONCURRENT freed 67K, 3% free 6908K/7111K, paused 2ms+4ms
02-14 10:31:21.227: E/AndroidRuntime(5934): FATAL EXCEPTION: main
02-14 10:31:21.227: E/AndroidRuntime(5934): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adacel.app/com.adacel.app.MainActivity}: java.lang.NullPointerException
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.access$500(ActivityThread.java:122)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.os.Looper.loop(Looper.java:132)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.main(ActivityThread.java:4123)
02-14 10:31:21.227: E/AndroidRuntime(5934): at java.lang.reflect.Method.invokeNative(Native Method)
02-14 10:31:21.227: E/AndroidRuntime(5934): at java.lang.reflect.Method.invoke(Method.java:491)
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-14 10:31:21.227: E/AndroidRuntime(5934): at dalvik.system.NativeStart.main(Native Method)
02-14 10:31:21.227: E/AndroidRuntime(5934): Caused by: java.lang.NullPointerException
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.adacel.app.MainActivity.GetLatestData(MainActivity.java:300)
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.adacel.app.MainActivity.LoadWithNetworkConnectivity(MainActivity.java:220)
02-14 10:31:21.227: E/AndroidRuntime(5934): at com.adacel.app.MainActivity.onCreate(MainActivity.java:79)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.Activity.performCreate(Activity.java:4397)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
02-14 10:31:21.227: E/AndroidRuntime(5934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
02-14 10:31:21.227: E/AndroidRuntime(5934): ... 11 more
It appears as if it's erroring out on the method GetStringFromWebService. But the strange part is this....that call isn't made until further down in the MainActivity...my assignment call above (bNetworkConnected = true) is the 2nd line of code, just after super.onCreate(savedInstance)...so it's like it doesn't even see the breakpoint that I set there.
MainActivity Code
public static final String TAG = "SQLiteDebug";
private ListView mListViewIssues;
private static final String NameSpace = "RemoteWebService";
private static final String URL = "http://ws.simcare.biz/Service1.asmx";
private static final String DBVersionKey = "DBVersion";
private static final String PreferencesNotLoaded = "User Preferences could not be loaded. \n\nThis app will now close.";
private static final String CustomerCodeNotLoaded = "The Customer Code could not be loaded. \n\nThis app will now close.";
private static final String LocationShortNameNotLoaded = "The Location Short Name could not be loaded. \n\nThis app will now close.";
private static final String DBVersionNotLoaded = "The Database Version could not be loaded. \n\nThis app will now close.";
private static final String App_File = "app_file.xml";
private static final String AppNotConnectedTitle = "App Not Connected to Network";
Boolean ConnectedToNetwork = false;
TextView tvFooter;
int DBVersion = 1;
IssueInfoCreator creator;
AppPreferences appPrefs = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.footer_layout);
//For testing network connectivity only.
boolean bNetworkConnected = true;
//If there's a network connection available, get latest data.
//if(NetworkUtils.getInstance(this).isOnline(this)){
if(bNetworkConnected){
//Load data from web service and get latest data.
LoadWithNetworkConnectivity();
}
else{
InputStream isAppFile = null;
try {
isAppFile = getBaseContext().getAssets().open(App_File);
} catch (IOException e) {
ShowMessageAndClose(PreferencesNotLoaded);
return;
}
Scanner scanner = new Scanner(isAppFile);
String sScannerContents = scanner.useDelimiter("\\A").next();
Document doc = XMLfunctions.XMLfromString(sScannerContents);
try{
if(LoadPreferences(doc))
DBVersion = Integer.valueOf(appPrefs.getDBVersion());
}catch(Exception ex){
Log.e("INT PARSE ERROR", ex.getStackTrace().toString());
}
//Load data from local db only.
LoadWithoutNetworkConnectivity();
}
//Load listview control.
setContentView(R.layout.main);
//Setup Refresh button listener.
Button btn = (Button) findViewById(R.id.btnRefresh);
btn.setOnClickListener(btnRefreshClick);
final Context context = getBaseContext();
mListViewIssues = (ListView)findViewById(R.id.listIssues);
//Load Footer View.
View footerView =((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
tvFooter = (TextView)footerView.findViewById(R.id.footerText);
tvFooter.setText("DBVersion = " + String.valueOf(DBVersion));
mListViewIssues.addFooterView(footerView);
creator = new IssueInfoCreator(this, DBVersion);
creator.open();
//add data to listview through adapter.
mListViewIssues.setAdapter(new IssueInfoAdapter(this, creator.queryAll()));
creator.close();
}
LoadWithNetworkConnectivity code:
private void LoadWithNetworkConnectivity(){
//Set the Titlebar to the stored value in the DB.
String SoapAction = "RemoteWebService/GetApplicationTitle";
String MethodName = "GetApplicationTitle";
setTitle(GetStringFromWebService(NameSpace, MethodName, SoapAction, URL, "ApplicationName", "AndroidApp"));
//Get the DBVersion.
SoapAction = "RemoteWebService/GetDBVersion";
MethodName = "GetDBVersion";
DBVersion = GetIntFromWebService(NameSpace, MethodName, SoapAction, URL, "ApplicationName", "AndroidApp");
//Write DBVersion to Preferences.
Editor ePreferences = this.getPreferences(Context.MODE_PRIVATE).edit();
ePreferences.putInt(DBVersionKey, DBVersion);
ePreferences.commit();
//Get Issues for this Customer/Location.
SoapAction = "RemoteWebService/GetOpenIssues";
MethodName = "GetOpenIssues";
SoapPrimitive xmlData = GetDataFromWebService(NameSpace, MethodName, SoapAction, URL, "ApplicationName", "AndroidApp");
try {
GetLatestData(xmlData);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//Set flag.
ConnectedToNetwork = true;
}
GetDataFromWebService code:
public SoapPrimitive GetDataFromWebService(String NameSpace, String MethodName, String SoapAction, String URL, String argName, String argValue){
try {
SoapObject request = new SoapObject(NameSpace, MethodName);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
request.addProperty(argName, argValue);
if(MethodName == "GetOpenIssues")
{
request.addProperty("CustomerCode", "ABC");
request.addProperty("LocationShortName", "KBIF");
}
envelope.setOutputSoapObject(request);
androidHttpTransport.call(SoapAction, envelope);
SoapPrimitive responseData = (SoapPrimitive) envelope.getResponse();
return responseData;
}
catch (Exception e) {
Log.e("GetStringFromWebService ERROR-", new RuntimeException(e).toString());
return null;
}
}
GetLatestData code:
public void GetLatestData(SoapPrimitive xml)throws ParserConfigurationException, SAXException, IOException{
//get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc;
//parse using builder to get DOM representation of the XML file
InputSource is = new InputSource(new StringReader(xml.toString()));
doc = db.parse(is);
//Clear out Issues table first.
creator = new IssueInfoCreator(this, DBVersion);
creator.open();
creator.ClearIssueTable();
creator.close();
NodeList nodes = doc.getElementsByTagName("Table");
for(int i = 0; i < nodes.getLength(); i++) {
IssueInfo issue = new IssueInfo();
Element e = (Element)nodes.item(i);
issue.setIssueNumber(Long.parseLong(XMLfunctions.getValue(e, "IssueID")));
issue.setIssueSummary(XMLfunctions.getValue(e, "IssueSummary"));
issue.setDateReceived(DateFormat.format("MM/dd/yyyy hh:mm:ss", System.currentTimeMillis()).toString());
if(issue.getIssueNumber() > 0 && issue.getIssueSummary() != null){
creator = new IssueInfoCreator(this, DBVersion);
creator.open();
creator.InsertIssue(issue.getIssueNumber(), issue.getDateReceived(), issue.getIssueSummary());
creator.close();
}
}
}
There's the code you requested....in short, the app starts, checks to see if there's a valid network connection (in this case, I just put a bool flag so I don't have to keep unplugging my cable or disconnecting my wifi to make it work/not work), and it runs the appropriate method. I set the flag to true so it calls the LoadWithNetworkConnectivity() method....this method goes out to our .NET web service and gets the application title, DBVersion, and OpenIssues. In this method it then calls the "GetLatestData" method and parses the XML into an Issue object that I created. Again, all this is working find on the emulator, evo, and droidx, just not my ASUS tablet.
UPDATE #2 - RESOLUTION
I skipped the effort with trying to get my tablet to debug and created an emulator for 3.2 OS (I was running it on 2.3.3 emulator before). So now I can debug and see where the error is coming from. It appears to error out FIRST on the following line:
setTitle(GetStringFromWebService(NameSpace, MethodName, SoapAction, URL, "ApplicationName", "AndroidApp"));
If I put this in a string, it returns null and the error I get in LogCat is:
02-14 16:01:21.177: E/GetStringFromWebService ERROR-(510): java.lang.RuntimeException: android.os.NetworkOnMainThreadException
Just like Maxim said, you have to put the networking stuff on it's own thread. The Android SDK documentation explains it as well NetworkOnMainThreadException. Unreal what it says there...it's allowed on older platforms but not on Honeycomb and above, which is what the ASUS tablet is running, which is why the error is coming about.
Thanks Maxim for helping me out! Once I get the code to put the networking events on it's own thread, I will try to update this post so others will know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的 LogCat 错误中可以看出问题可以隐藏在哪里。
无法启动活动 ComponentInfo{com.adacel.app/com.adacel.app.MainActivity}:java.lang.NullPointerException,这意味着您正在将 null 作为对象获取某处,并尝试从该 null 中获取某些内容。
还有错误-(5934):java.lang.RuntimeException:java.lang.NumberFormatException:无效的int:“null”。
首先确保 WebService 调用在单独的线程中完成,因为(NetworkOnMainThreadException)。其次,您从服务中获取了正确的数据。查看LoadWithNetworkConnectivity()内部
From your LogCat errors say where problem can be hidden.
Unable to start activity ComponentInfo{com.adacel.app/com.adacel.app.MainActivity}: java.lang.NullPointerException, this means you are getting somewhere null as an object and trying to get something from that null.
Also ERROR-(5934): java.lang.RuntimeException: java.lang.NumberFormatException: Invalid int: "null".
First of all make sure WebService call done in a separate thread, because of (NetworkOnMainThreadException). Second, you are getting correct data from Service. Look inside LoadWithNetworkConnectivity()
在我看来,您已经在设备上安装了同一应用程序的 APK。更糟糕的是,如果你通过市场来做到这一点。您应该简单地卸载 APK。顺便说一句,你忘了把清单放在这里。
It seems to me, that you have already installed on the device the APK of the same application. Even worse, if you did it through Market. You should simply uninstall APK. BTW, you have forgotten to put Manifest here.