I currently have a BaseAdapter that is populating a gallery of thumbnails. When an item is visible, an AsyncTask is started from the adapters getView() method to download the thumbnail and when completed the imageview is updated with the correct bitmap. This seems to work really well, except when the user scrolls really fast. This is because of the AsyncTask limitations of holding 128 threads in the queue at any given time.
So my question is how do I properly detect whether the thread pool is full before scheduling another task? Or how do I properly catch the error so I don't receive a force close?
Here are the errors I'm receiving:
5-06 10:54:11.416 27931-27931/com.diverg.tidy E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.diverg.tidy, PID: 27931
java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3#426c4e80 rejected from java.util.concurrent.ThreadPoolExecutor#41bddce0[Running, pool size = 5, active threads = 5, queued tasks = 128, completed tasks = 35]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1339)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:590)
at com.diverg.tidy.MediaAdapter.getView(MediaAdapter.java:90)
at android.widget.AbsListView.obtainView(AbsListView.java:2263)
at android.widget.GridView.makeAndAddView(GridView.java:1345)
at android.widget.GridView.makeRow(GridView.java:345)
at android.widget.GridView.fillDown(GridView.java:287)
at android.widget.GridView.fillFromTop(GridView.java:421)
at android.widget.GridView.layoutChildren(GridView.java:1233)
at android.widget.AbsListView.onLayout(AbsListView.java:2091)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.ListView.setupChild(ListView.java:1882)
at android.widget.ListView.makeAndAddView(ListView.java:1793)
at android.widget.ListView.fillDown(ListView.java:691)
at android.widget.ListView.fillGap(ListView.java:655)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5136)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4247)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:543)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
05-06 10:54:13.299 29540-29540/? E/dalvikvm﹕ /system/priv-app/GooglePartnerSetup.apk odex has stale dependencies
05-06 10:54:19.346 8024-8024/? E/fb4a(:<default>):AddressResolver﹕ Failed to deserialize to instance com.facebook.mqtt.AddressEntry
at [Source: java.io.StringReader#42180f18; line: 1, column: 34]
05-06 10:54:20.018 125-439/? E/Netd﹕ Failed to write /sys/class/net/rmnet1/mtu: Invalid argument
05-06 10:54:20.025 447-522/? E/ConnectivityService﹕ exception in setMtu()java.lang.IllegalStateException: command '5905 interface setmtu rmnet1 1500' failed with '400 5905 Failed to get MTU (Invalid argument)'
05-06 10:54:20.369 447-1037/? E/ConnectivityService﹕ startUsingNetworkFeature took too long: 330ms
05-06 10:54:20.393 125-439/? E/Netd﹕ Failed to write /sys/class/net/rmnet1/mtu: Invalid argument
05-06 10:54:20.393 447-522/? E/ConnectivityService﹕ exception in setMtu()java.lang.IllegalStateException: command '5917 interface setmtu rmnet1 1500' failed with '400 5917 Failed to get MTU (Invalid argument)'
05-06 10:54:21.439 447-503/? E/WifiStateMachine﹕ Unexpected BatchedScanResults :OK
05-06 10:54:22.096 447-522/? E/ConnectivityService﹕ Unexpected mtu value: android.net.wifi.WifiStateTracker#423a09c0
05-06 10:54:23.932 29936-29936/? E/dalvikvm﹕ /system/priv-app/SetupWizard.apk odex has stale dependencies
05-06 10:54:24.127 29936-29936/? E/PhoneMonitor﹕ onOtaspChanged old =0, new =3
05-06 10:54:24.338 29957-29957/? E/dalvikvm﹕ /system/app/GalleryGoogle.apk odex has stale dependencies
05-06 10:54:25.127 125-439/? E/SecondaryTablController﹕ ip route del failed: /system/bin/ip route del 10.182.14.1/32 via 0.0.0.0 dev rmnet1 table 60
05-06 10:54:25.143 125-439/? E/SecondaryTablController﹕ ip route del failed: /system/bin/ip route del 0.0.0.0/0 via 10.182.14.1 dev rmnet1 table 60
05-06 10:54:25.150 125-439/? E/SecondaryTablController﹕ ip route del failed: /system/bin/ip route del 2600:1014:b10b:6554::1/128 via :: dev rmnet1 table 60
05-06 10:54:25.166 125-439/? E/SecondaryTablController﹕ ip route del failed: /system/bin/ip route del ::/0 via 2600:1014:b10b:6554::1 dev rmnet1 table 60
You can go through documentation of AsyncTask:
http://developer.android.com/reference/android/os/AsyncTask.html
And you can use getStatus() of AsyncTask to know the status of the worker thread. See http://developer.android.com/reference/android/os/AsyncTask.html#getStatus%28%29
I ended up using this as a template. It works by creating a worker thread and adding images to it's queue.
Related
My problem is when I run my app on API level 23 devices,I have a an issue,when video is playing and I lock the device,after unlocking,it plays sound for 2-3 seconds and then there is no sound,and after a couple of seconds the screen is getting black.
LogCat
09-14 07:56:01.819 1641-1641/system_process E/PowerManagerService-JNI: Couldn't load power module (No such file or directory)
09-14 07:56:01.919 1641-1641/system_process E/art: DexFile_getDexOptNeeded file '/system/framework/org.apache.http.legacy.jar' does not exist
09-14 07:56:02.800 1641-1641/system_process E/ConsumerIrService: Can't open consumer IR HW Module, error: -2
09-14 07:56:02.921 1641-1706/system_process E/EventHub: could not get driver version for /dev/input/mice, Not a typewriter
09-14 07:56:04.158 1641-1641/system_process E/UsbDeviceManager: failed to write to /sys/class/android_usb/android0/f_rndis/ethaddr
09-14 07:56:04.158 1641-1641/system_process E/UsbDeviceManagerJNI: could not open /dev/usb_accessory
09-14 07:56:04.266 1641-1641/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.password.key: open failed: ENOENT (No such file or directory)
09-14 07:56:04.266 1641-1641/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/password.key: open failed: ENOENT (No such file or directory)
09-14 07:56:04.266 1641-1641/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.pattern.key: open failed: ENOENT (No such file or directory)
09-14 07:56:04.266 1641-1641/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.gesture.key: open failed: ENOENT (No such file or directory)
09-14 07:56:04.266 1641-1641/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gesture.key: open failed: ENOENT (No such file or directory)
09-14 07:56:04.274 1641-1641/system_process E/WifiService: Invoking mWifiStateMachine.setWifiEnabled
09-14 07:56:04.679 1641-1722/system_process E/BluetoothAdapter: Bluetooth binder is null
09-14 07:56:04.684 1641-1722/system_process E/BluetoothAdapter: Bluetooth binder is null
09-14 07:56:04.693 1641-2001/system_process E/WVMExtractor: Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found
09-14 07:56:04.702 1641-1641/system_process E/InputMethodManagerService: Ignoring updateSystemUiLocked due to an invalid token. uid:1000 token:null
09-14 07:56:04.725 1641-1641/system_process E/FlpHardwareProvider: Error hw_get_module 'flp': -2
09-14 07:56:04.725 1641-1641/system_process E/LocationManagerService: FLP HAL not supported
09-14 07:56:04.726 1641-1641/system_process E/ActivityRecognitionHardware: Error hw_get_module: -2
09-14 07:56:04.726 1641-1641/system_process E/LocationManagerService: Hardware Activity-Recognition not supported.
09-14 07:56:04.741 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:04.781 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:04.782 1641-1715/system_process E/WifiStateMachine: Failed to reload STA firmware java.lang.IllegalArgumentException: command '16 softap fwreload wlan0 STA' failed with '501 16 SoftAP command has failed'
09-14 07:56:04.784 1641-1715/system_process E/WifiStateMachine: Unable to change interface settings: java.lang.IllegalStateException: command '18 interface setcfg wlan0 0.0.0.0 0 down' failed with '400 18 Failed to set address (No such device)'
09-14 07:56:04.784 1641-1715/system_process E/WifiMonitor: killSupplicant p2pfalse init.svc.wpa_supplicant=unknown init.svc.p2p_supplicant=unknown
09-14 07:56:04.902 1641-1641/system_process E/BluetoothAdapter: Bluetooth binder is null
09-14 07:56:04.917 1641-1641/system_process E/BluetoothAdapter: Bluetooth binder is null
09-14 07:56:04.922 1641-1641/system_process E/BluetoothAdapter: Bluetooth binder is null
09-14 07:56:05.328 1641-1717/system_process E/ConnectivityService: Failed to find Messenger in unregisterNetworkFactory
09-14 07:56:06.506 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:06.533 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:06.687 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:06.726 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:06.737 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:06.857 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:06.862 1641-1662/system_process E/GpsLocationProvider: no AGPS interface in set_agps_server
09-14 07:56:10.042 1641-1715/system_process E/WifiHW: Failed to stop supplicant
09-14 07:56:10.042 1641-1715/system_process E/WifiNative-HAL: Could not start hal
09-14 07:56:10.042 1641-1715/system_process E/WifiStateMachine: Failed to start HAL
09-14 07:56:10.042 1641-1715/system_process E/WifiHW: Cannot open "/system/etc/wifi/wpa_supplicant.conf": No such file or directory
09-14 07:56:10.042 1641-1715/system_process E/WifiHW: Wi-Fi will not be enabled
09-14 07:56:10.042 1641-1715/system_process E/WifiStateMachine: Failed to start supplicant!
09-14 07:56:39.975 1641-1674/system_process E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaaf4b0e0
09-14 07:56:39.975 1641-1674/system_process E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
09-14 07:56:39.990 1641-1715/system_process E/WifiStateMachine: Fail to set up pno, want false now false
09-14 07:56:39.997 1641-1715/system_process E/WifiStateMachine: Fail to set up pno, want false now false
09-14 07:56:43.721 1641-1715/system_process E/WifiStateMachine: Fail to set up pno, want false now false
These two line are printed every time when I lock or unlock the device.
09-14 07:56:43.721 1641-1715/system_process E/WifiStateMachine: Fail
to set up pno, want false now false 09-14 08:03:36.788
1641-1674/system_process E/Surface: getSlotFromBufferLocked: unknown
buffer: 0xaaf4b0e0
Any help is appreciated,thx.
They have fixed the issue in Android 6.0.1. Just update your Android OS version and it will be ok.
I tried to integrate google play service with my unity android game. After signed in google play service, following log message appeared in DDMS and app was crashed.
02-27 13:50:00.633 13419-13419/? D/AndroidNative﹕ GameHelper: onConnected: connected! client=1
02-27 13:50:00.633 13419-13419/? D/AndroidNative﹕ GameHelper: Connected clients updated to: 1
02-27 13:50:00.633 13419-13419/? D/AndroidNative﹕ GameHelper: connectNextClient: requested clients: 1, connected clients: 1
02-27 13:50:00.633 13419-13419/? D/AndroidNative﹕ GameHelper: Pending clients: 0
02-27 13:50:00.633 13419-13419/? D/AndroidNative﹕ GameHelper: All clients now connected. Sign-in successful!
02-27 13:50:00.633 13419-13419/? D/AndroidNative﹕ GameHelper: All requested clients connected. Sign-in succeeded!
02-27 13:50:00.633 13419-13419/? D/AndroidRuntime﹕ Shutting down VM
02-27 13:50:00.633 13419-13419/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415baba8)
02-27 13:50:00.633 13419-13419/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.dokinkon.projectp, PID: 13419
java.lang.Error: FATAL EXCEPTION [main]
Unity version : 4.3.2f1
Device model : LGE Nexus 5
Device fingerprint: google/hammerhead/hammerhead:4.4.2/KOT49H/937116:user/release-keys
Caused by: java.lang.IllegalStateException: No AppStateClient. Did you request it at setup?
at com.google.example.games.basegameutils.GameHelper.getAppStateClient(GameHelper.java:294)
at com.android.gs.GameClientManager.onStateChange(GameClientManager.java:690)
at com.google.example.games.basegameutils.GameHelper.setState(GameHelper.java:272)
at com.google.example.games.basegameutils.GameHelper.succeedSignIn(GameHelper.java:813)
at com.google.example.games.basegameutils.GameHelper.connectNextClient(GameHelper.java:695)
at com.google.example.games.basegameutils.GameHelper.onConnected(GameHelper.java:805)
at com.google.android.gms.internal.k.y(Unknown Source)
at com.google.android.gms.internal.au.y(Unknown Source)
at com.google.android.gms.internal.k$f.a(Unknown Source)
at com.google.android.gms.internal.k$f.a(Unknown Source)
at com.google.android.gms.internal.k$b.D(Unknown Source)
at com.google.android.gms.internal.k$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
I don't know what "java.lang.IllegalStateException: No AppStateClient. Did you request it at setup?" means for. Thanks.
You need to add the APPSTATE client as shown below:
//should be called on your application start
//best practice to call it only once. Any way other calls will be ignored by the plugin.
//if you want to use only Game service (Leader-boards, achievements) use GooglePlayConnection.CLIENT_GAMES
//if you want to use only Google Cloud service use GooglePlayConnection.CLIENT_APPSTATE
//if you want both: GooglePlayConnection.CLIENT_GAMES | GooglePlayConnection.CLIENT_APPSTATE
//and if you whant to get avaliable permissions for your app use: GooglePlayConnection.CLIENT_ALL
GooglePlayConnection.instance.start (GooglePlayConnection.CLIENT_GAMES | GooglePlayConnection.CLIENT_APPSTATE );
I've been having problems with displaying Contacts in an AlertDialog, and I think I've found the
problem, but am still confused. The pertinent suspect part of my code is:
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, mContacts,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { android.R.id.text1 });
...Now "simple_list_item_1" is accepted by the compiler (the app runs in the Emulator), however when
I try to run this ListActivity, it bombs.
So after reading elsewhere about how to accomplish this task my eyes lit upon the aforepasted
"simple_list_item_1" - where is that? I didn't create any simple_list_item_1.xml file, and it doesn't exist in my \res\layout folder. So I (in Eclipse) right-clicked "simple_list_item_1" and selected "Open Declaration" and it invoked an err msg much or exactly like the one I see in the Debug Perspective about "Class File Editor | Source nout found | The JAR file ....\android.jar has no source attachment."
So...assuming this is the problem (there is no "simple_list_item_1.xml" in my \res\layout folder), what exactly is expected in this file (which I assume is simply a xml definition of what I want each Contact to display in)?
==============
Here is some LogCat data:
Here are the last lines in LogCat (it seems to die/hang once it gets to the ListActivity (ContactsActivity):
com.aXX3AndSpace.KeepInTouch/.KeepInTouchActivity: +5s368ms
01-08 21:54:34.020: I/ActivityManager(61): Starting: Intent { cmp=com.aXX3AndSpace.KeepInTouch/.ContactsActivity } from pid 385
...and here are all of the Error msgs in one attempted run (open the app, try to invoke the ListActivity). Note the "THIS SHOULD NEVER occur" msg at the end:
01-08 21:53:36.592: E/Zygote(33): setreuid() failed. errno: 2
01-08 21:53:46.423: E/Zygote(33): setreuid() failed. errno: 17
01-08 21:53:47.842: E/BatteryService(61): usbOnlinePath not found
01-08 21:53:47.842: E/BatteryService(61): batteryVoltagePath not found
01-08 21:53:47.842: E/BatteryService(61): batteryTemperaturePath not found
01-08 21:53:47.862: E/SurfaceFlinger(61): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
01-08 21:53:48.082: E/SensorService(61): couldn't open device for module sensors (Invalid argument)
01-08 21:53:53.722: E/System(61): Failure starting core service
01-08 21:53:53.722: E/System(61): java.lang.SecurityException
01-08 21:53:53.722: E/System(61): at android.os.BinderProxy.transact(Native Method)
01-08 21:53:53.722: E/System(61): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
01-08 21:53:53.722: E/System(61): at android.os.ServiceManager.addService(ServiceManager.java:72)
01-08 21:53:53.722: E/System(61): at com.android.server.ServerThread.run(SystemServer.java:207)
01-08 21:53:53.742: E/EventHub(61): could not get driver version for /dev/input/mouse0, Not a typewriter
01-08 21:53:53.742: E/EventHub(61): could not get driver version for /dev/input/mice, Not a typewriter
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/Effect_Tick.ogg
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/KeypressStandard.ogg
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-08 21:53:54.042: E/SoundPool(61): error loading /system/media/audio/ui/KeypressDelete.ogg
01-08 21:53:54.042: E/SoundPool(61): error loading /system/media/audio/ui/KeypressReturn.ogg
01-08 21:53:54.703: E/ThrottleService(61): Could not open GPS configuration file /etc/gps.conf
01-08 21:53:57.172: E/logwrapper(158): executing /system/bin/tc failed: No such file or directory
01-08 21:53:57.242: E/logwrapper(159): executing /system/bin/tc failed: No such file or directory
01-08 21:53:57.282: E/logwrapper(160): executing /system/bin/tc failed: No such file or directory
01-08 21:54:00.074: E/jdwp(174): Failed sending reply to debugger: Broken pipe
01-08 21:54:00.712: E/Database(116): sqlite_config failed error_code = 21. THIS SHOULD NEVER occur.
simple_list_item_1 is a standard layout defined in the SDK, it's basically just a TextView with the id "android:id/text1", which is what you supply in your view identifiers.
Do you have the stacktrace of the crash? Because it's most likely not due to a missing simple_list_item_1 layout.
Create a new XML layout file using Eclipse wizard. The name of this file will replace simple_list_item_1 in your code:
In this layout, create a TextView (or any other container) element and call it text1:
Then SimpleCursorAdaptor will match your contact info and the text1 field in your layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
I'm going to get data with Restlet of this official OData page:
http://services.odata.org/OData/OData.svc/
I've started this tutorial:
http://weblogs.asp.net/uruit/archive/2011/09/13/accessing-odata-from-android-using-restlet.aspx
My problem is, that at the end, he can't get the metadata. But first:
When I'm trying to generate the Restleg-Files (Point 5), the console is showing this, where the lines with are date are red:
---------------------------
OData client code generator
---------------------------
step 1 - check parameters
step 2 - check the ouput directory
step 3 - get the metadata descriptor
Nov 28, 2011 3:12:46 PM org.restlet.engine.http.connector.HttpClientHelper start
Information: Starting the default HTTP client
Nov 28, 2011 3:12:48 PM org.restlet.ext.odata.Service getMetadata
Information: Get the metadata for http://services.odata.org/OData/OData.svc/ at http://services.odata.org/OData/OData.svc/$metadata
Nov 28, 2011 3:12:48 PM org.restlet.engine.http.connector.HttpClientHelper start
Information: Starting the default HTTP client
step 4 - generate source code
Nov 28, 2011 3:12:48 PM org.restlet.engine.http.connector.HttpClientHelper start
Information: Starting the default HTTP client
Nov 28, 2011 3:12:49 PM org.restlet.ext.odata.Service getMetadata
Information: Get the metadata for http://services.odata.org/OData/OData.svc/ at http://services.odata.org/OData/OData.svc/$metadata
Nov 28, 2011 3:12:49 PM org.restlet.engine.http.connector.HttpClientHelper start
Information: Starting the default HTTP client
Nov 28, 2011 3:12:49 PM org.restlet.engine.http.connector.HttpClientHelper stop
Information: Stopping the default HTTP client
Nov 28, 2011 3:12:50 PM org.restlet.engine.http.connector.HttpClientHelper stop
Information: Stopping the default HTTP client
The source code has been generated in directory: C:\Projects\MyProjects\Android App\main\app\Java\Workspace\TestOData2\src
So the files are generated, but when I'm going forward in the tutorial, copy the class into my Android project, import libraries and write the following code, then I get the error below.
public ArrayList<Product> getOdataSampleProduct(String zip) {
ODataDemoService proxy = new OdataDemoService();
try {
Query<Product> query = proxy.createProductQuery("Products(1)");
Product product = query.iterator().next(); //breaks here
Log.d("Test","id: "+product.getId()); //isn't logged
}
catch(Exception e) {
//is catched before query.iterator().next()
};
So, LogCat shows this error (line 3 is red):
...
11-29 09:01:01.039: INFO/org.restlet(700): Starting the default HTTP client
11-29 09:01:01.329: INFO/org.restlet(700): A recoverable error was detected (1001), attempting again in 2000 ms.
11-29 09:01:05.589: ERROR/org.restlet(700): Can't get the metadata for http://services.odata.org/OData/OData.svc/ (response's status: Communication Error (1001) - services.odata.org)
11-29 09:01:05.629: INFO/org.restlet(700): Get the metadata for http://services.odata.org/OData/OData.svc/ at http://services.odata.org/OData/OData.svc/$metadata
11-29 09:01:06.200: INFO/org.restlet(700): Starting the default HTTP client
11-29 09:01:06.329: INFO/org.restlet(700): A recoverable error was detected (1001), attempting again in 2000 ms.
11-29 09:01:06.359: DEBUG/dalvikvm(408): GC_EXPLICIT freed 3K, 5% free 6308K/6595K, paused 3ms+2ms
11-29 09:01:08.409: INFO/org.restlet(700): A recoverable error was detected (1001), attempting again in 2000 ms.
11-29 09:01:10.499: ERROR/org.restlet(700): Can't get the metadata for http://services.odata.org/OData/OData.svc/ (response's status: Communication Error (1001) - services.odata.org)
11-29 09:01:10.579: WARN/org.restlet(700): Can't parse the content of http://services.odata.org/OData/OData.svc/Products(1)
11-29 09:01:10.579: WARN/org.restlet(700): java.lang.Exception: Can't execute the query without the service's metadata.
11-29 09:01:10.579: WARN/org.restlet(700): at org.restlet.ext.odata.Query.execute(Query.java:347)
11-29 09:01:10.579: WARN/org.restlet(700): at org.restlet.ext.odata.Query.iterator(Query.java:642)
11-29 09:01:10.579: WARN/org.restlet(700): at my.folder.testApp.MapView.getData(MapView.java:77)
11-29 09:01:10.579: WARN/org.restlet(700): at my.folder.testApp.MapView.onCreate(MapView.java:141)
11-29 09:01:10.579: WARN/org.restlet(700): at android.app.Activity.performCreate(Activity.java:4397)
11-29 09:01:10.579: WARN/org.restlet(700): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-29 09:01:10.579: WARN/org.restlet(700): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
11-29 09:01:10.579: WARN/org.restlet(700): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
11-29 09:01:10.579: WARN/org.restlet(700): at android.app.ActivityThread.access$500(ActivityThread.java:122)
11-29 09:01:10.579: WARN/org.restlet(700): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
11-29 09:01:10.579: WARN/org.restlet(700): at android.os.Handler.dispatchMessage(Handler.java:99)
11-29 09:01:10.579: WARN/org.restlet(700): at android.os.Looper.loop(Looper.java:132)
11-29 09:01:10.579: WARN/org.restlet(700): at android.app.ActivityThread.main(ActivityThread.java:4123)
11-29 09:01:10.579: WARN/org.restlet(700): at java.lang.reflect.Method.invokeNative(Native Method)
11-29 09:01:10.579: WARN/org.restlet(700): at java.lang.reflect.Method.invoke(Method.java:491)
11-29 09:01:10.579: WARN/org.restlet(700): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-29 09:01:10.579: WARN/org.restlet(700): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-29 09:01:10.579: WARN/org.restlet(700): at dalvik.system.NativeStart.main(Native Method)
It seems that there is a problem with the metadata, but I can't figure out what.
Any idea?
Could you try registering the Restlet extension for Apache HTTP Client instead of the default internal connector?
See this page for details:
http://wiki.restlet.org/docs_2.1/13-restlet/275-restlet/266-restlet.html
At least, I've found a solution:
I had to put the query into an AsyncTask.
Before, in the UI thread, the query didn't have time to get an answer.
So I put it into the doInBackground.
I am trying to run the simplest Hello World example app and looks like I can crash it even all it does is showing a TextView.
Steps to reproduce: Launch it in the emulator (1.5). Open the app - it shows the text view, then lock the phone by pressing "end call" button. Unlock by pressing "menu", then press "back". App crashes with "The process android.process.acore has stopped unexpectedly..." and Force Close button. It does not happen all the time, but I am able to reproduce it every time after wiping the user data at least.
I wonder if default Hello World is missing a detail which was considered too advanced for a hello world... Such problems with a basic example does not look very encouraging =)
Any idea what detail is missing and how to avoid this crash?
Stack (I've truncated timestamps):
37.478: DEBUG/KeyguardViewMediator(576): wakeWhenReadyLocked(82)
37.481: DEBUG/KeyguardViewMediator(576): handleWakeWhenReady(82)
37.481: DEBUG/KeyguardViewMediator(576): pokeWakelock(5000)
39.110: DEBUG/KeyguardViewMediator(576): pokeWakelock(5000)
39.140: WARN/InputManagerService(576): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#436e3fc0
40.990: ERROR/IMemory(679): binder=0x238aa8 transaction failed fd=-2147483647, size=0, err=-2147483646 (Unknown error: 2147483646)
40.990: ERROR/IMemory(679): cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
40.990: ERROR/IMemory(679): cannot map BpMemoryHeap (binder=0x238aa8), size=0, fd=-1 (Bad file number)
40.990: ERROR/Surface(679): Couldn't map Surface's heap (binder=0x238aa8, heap=0x238b00)
40.990: DEBUG/AndroidRuntime(679): Shutting down VM
40.990: WARN/dalvikvm(679): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
40.990: ERROR/AndroidRuntime(679): Uncaught handler: thread main exiting due to uncaught exception
40.990: ERROR/AndroidRuntime(679): java.lang.IllegalArgumentException
40.990: ERROR/AndroidRuntime(679): at android.view.Surface.lockCanvasNative(Native Method)
40.990: ERROR/AndroidRuntime(679): at android.view.Surface.lockCanvas(Surface.java:196)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.draw(ViewRoot.java:1175)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.performTraversals(ViewRoot.java:1030)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
40.990: ERROR/AndroidRuntime(679): at android.os.Handler.dispatchMessage(Handler.java:99)
40.990: ERROR/AndroidRuntime(679): at android.os.Looper.loop(Looper.java:123)
40.990: ERROR/AndroidRuntime(679): at android.app.ActivityThread.main(ActivityThread.java:3948)
40.990: ERROR/AndroidRuntime(679): at java.lang.reflect.Method.invokeNative(Native Method)
40.990: ERROR/AndroidRuntime(679): at java.lang.reflect.Method.invoke(Method.java:521)
40.990: ERROR/AndroidRuntime(679): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
40.990: ERROR/AndroidRuntime(679): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
40.990: ERROR/AndroidRuntime(679): at dalvik.system.NativeStart.main(Native Method)
41.000: INFO/Process(576): Sending signal. PID: 679 SIG: 3
41.000: INFO/dalvikvm(679): threadid=7: reacting to signal 3
41.030: ERROR/ActivityThread(576): Failed to find provider info for android.server.checkin
41.030: ERROR/Checkin(576): Error reporting crash: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/crashes
41.070: INFO/dalvikvm(679): Wrote stack trace to '/data/anr/traces.txt'
50.940: WARN/ActivityManager(576): Launch timeout has expired, giving up wake lock!
50.980: WARN/ActivityManager(576): Activity idle timeout for HistoryRecord{4366ac40 {com.android.launcher/com.android.launcher.Launcher}}
sounds to me more like something wrong with your emulator. Why dont you delete your emulator and create a new one and try again with a fresh project.
Hope that will help you. BTW why are you using emulator on 1.5?? Start to build applications for min 2.1.
Good luck.