- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个应用程序正在尝试在我的 ASUS eee TF101 (未 root) 上进行调试,但它无法正常工作。每当我在 Esclipse 中单击“调试”时,我的 ASUS 都会显示“应用程序 .... 意外停止。请重试。”错误信息。我可以在我的 EVO(有根)和 DroidX(无根)上运行它,没有任何问题。我已确保所有适用的设置都已应用 ( Setting up a Device for Development ),但它仍然不起作用。奇怪的是,如果我在 onCreate 事件的第二行代码上放置一个断点,它甚至不会在那里中断:
boolean bNetworkConnected = true;
我认为一个简单的赋值语句可以用于断点,但它不会在那里中断。
对发生的事情有什么想法吗?
更新
Maxim,我也无法在 Release模式下运行它。我已确保 MainActivity 是 list 文件中指定的那个(记住,它在我的 evo 和 droidx 上运行)。这是我在 Release模式下运行时的 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)之后。 ..所以就好像它甚至没有看到我在那里设置的断点。
主要 Activity 代码
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;
}
}
获取最新数据代码:
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 上找到,但不是我的 ASUS 平板电脑。
更新#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 . Unreal what it says there...它在旧平台上允许,但在 Honeycomb 及更高版本上不允许,这是 ASUS 平板电脑正在运行的平台,这就是出现错误的原因。
感谢 Maxim 帮助我!一旦我获得将网络事件放在它自己的线程上的代码,我将尝试更新这篇文章,以便其他人知道。
最佳答案
从您的 LogCat 错误中说出问题可以隐藏的地方。
无法启动 Activity ComponentInfo{com.adacel.app/com.adacel.app.MainActivity}:java.lang.NullPointerException,这意味着您正在将某处 null 作为对象并尝试从中获取某些内容无效的。
还有错误-(5934):java.lang.RuntimeException:java.lang.NumberFormatException:无效的 int:“null”。
首先确保 WebService 调用在单独的线程中完成,因为 (NetworkOnMainThreadException)。其次,您正在从服务中获取正确的数据。查看 LoadWithNetworkConnectivity() 内部
关于android - Eclipse 无法在 ASUS eee TF101 上进行调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9278943/
我正在阅读 developer.android.com 上的文档(例如,http://developer.android.com/reference/android/content/Context.h
我有一个非常具体的问题 - 我正在尝试写入 Asus Nexus 7 上的外部存储,但它正在写入设备上的模拟目录。 这是我使用的代码: public static void writeExternal
刚买了一个ASUS Transformer tablet .无法将其连接为我的开发设备。我确实安装了最新的 USB 驱动程序。有什么方向吗? 最佳答案 您需要从其网站安装华硕驱动程序。 您可以在此处找
我正在开发一个由后台服务运行的应用程序。服务在所有其他设备上运行但不在 ASUS Z008D 上运行。我什至禁用了 ASUS Mobile Manager,但它没有用。 设备公司:ASUS Mobil
我正在开发一个支持多屏幕的应用程序。在开始开发之前,我阅读了开发者网站以了解多屏幕支持。目前我有一个关于设备密度的问题。我在 Samsung Tab 10inch、Toshiba Regza、Cust
我一直在 Android 5 ZenFone 2 上测试我的应用程序。这部手机包含一个名为自动启动管理器的华硕软件。 我的 cordova 应用程序的一些不利情况: 安装应用程序后,自动启动管理器会自
我刚收到一个新的 Asus MeMo Pad (10"),以便在上面调试我们的 Android 应用程序,但是,我似乎无法为它安装合适的驱动程序(它很新,已发布就在几周前) 在 Windows (8)
我发现自己处在一个相当脆弱的境地,我正在开发一个 Web 应用程序,其界面几乎完全使用 RaphaelJS 作为 SVG 的前端来表示,但无法访问目标系统(别误会我的意思开始)。目标系统是 Asus
我正在尝试在 Asus Nexus 设备中从 eclipse 运行我的 android 应用程序,但是当我运行它时,设备如下所示:- ????????????? no permission 并允许选
我有一个 asus zenfone 5,我想在上面开发 android 应用程序,我目前使用 ubuntu 作为我唯一的操作系统, 我已经做过的是: 启用了 usb 调试,但在我的计算机中仍未检测到
我有一个应用程序正在尝试在我的 ASUS eee TF101 (未 root) 上进行调试,但它无法正常工作。每当我在 Esclipse 中单击“调试”时,我的 ASUS 都会显示“应用程序 ....
更新:实际上,这不是华硕手机的问题,而是华硕ZenUI键盘的问题。您可以安装一个您喜欢的键盘来解决这个问题。我已经在安装了 Google 键盘的情况下测试了 Zenfone 2。我的 TextWatc
在我的 ASUS Transformer 平板电脑上查看我在 Google Play 中的应用程序时,我看到以下消息 Your device isn't compatible with this ve
为了开发人员跟随机器人,我使用了 ASUS Xtion 和 OpenNI。为了获得 RGB 图像和骨架关节,我使用了骨架跟踪器脚本 ( https://github.com/Chaos84/skele
我创建了一个包含许多 Activity 的项目。一项 Activity 是录制视频,效果很好。我可以在我的指定文件夹中看到录制的视频,而无需重新启动我的平板电脑。 但是当我尝试使用查询在其他 Acti
我正在使用 GoogleMaps v2 并在各种 android 版本中测试我的应用程序(直到 4.0。我的应用程序正在运行)。 我尝试在 Asus Nexus 7 (4.4) 上使用我的应用程序,但
我正在开发一个需要显示 4 个大位图(6 x 屏幕尺寸)的 Android 应用程序。一开始,我对此有疑问,但内存管理的代码优化适用于整个设备。但是在 4.0.3 android 版本的 ASUS T
我实际上可以从我的 ASUS Xtion 获取 RGB 图像,但无法获取任何深度图像。我看到的是黑色图像,没有错误显示。 OpenNI 提供的示例 SimpleView 有效,所以我猜它不是传感器,不
我可以使用 OpenCV 从网络摄像头 (Microsot HD-3000) 获取图像并且一切正常,当 Xtion 没有插入计算机的 USB 时,但是如果我只是插入它,我只能从摄像头。 Skype 也
我在 Asus Nexus 7 上运行网页(用 jQueryMobile 编写)。我在 CSS 中将字体大小设置为 14px,但在调试期间(在 PC 上使用 Chrome)我可以看到它的计算大小是 2
我是一名优秀的程序员,十分优秀!