Android Geofence detection sample app closes when i turn off location services - android

I installed and tested the sample app geofence detection. In my experience i registered geofence keeping location services On.Once i turn Off the location service the app get closed and a alert dialog appears Unfortunately, "Geofence Detection has stopped. OK.". If any one experienced this please explain how we can block that and what might be the problem.
11-24 15:46:14.813: E/AndroidRuntime(27963): FATAL EXCEPTION: IntentService[ReceiveTransitionsIntentService]
11-24 15:46:14.813: E/AndroidRuntime(27963): Process: com.example.android.geofence, PID: 27963
11-24 15:46:14.813: E/AndroidRuntime(27963): java.util.IllegalFormatConversionException: %d can't format java.lang.String arguments
11-24 15:46:14.813: E/AndroidRuntime(27963): at java.util.Formatter.badArgumentType(Formatter.java:1489)
11-24 15:46:14.813: E/AndroidRuntime(27963): at java.util.Formatter.transformFromInteger(Formatter.java:1689)
11-24 15:46:14.813: E/AndroidRuntime(27963): at java.util.Formatter.transform(Formatter.java:1461)
11-24 15:46:14.813: E/AndroidRuntime(27963): at java.util.Formatter.doFormat(Formatter.java:1081)
11-24 15:46:14.813: E/AndroidRuntime(27963): at java.util.Formatter.format(Formatter.java:1042)
11-24 15:46:14.813: E/AndroidRuntime(27963): at java.util.Formatter.format(Formatter.java:1011)
11-24 15:46:14.813: E/AndroidRuntime(27963): at java.lang.String.format(String.java:1999)
11-24 15:46:14.813: E/AndroidRuntime(27963): at android.content.res.Resources.getString(Resources.java:1505)
11-24 15:46:14.813: E/AndroidRuntime(27963): at android.content.Context.getString(Context.java:376)
11-24 15:46:14.813: E/AndroidRuntime(27963): at com.example.android.geofence.ReceiveTransitionsIntentService.onHandleIntent(ReceiveTransitionsIntentService.java:58)
11-24 15:46:14.813: E/AndroidRuntime(27963): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
11-24 15:46:14.813: E/AndroidRuntime(27963): at android.os.Handler.dispatchMessage(Handler.java:102)
11-24 15:46:14.813: E/AndroidRuntime(27963): at android.os.Looper.loop(Looper.java:146)
11-24 15:46:14.813: E/AndroidRuntime(27963): at android.os.HandlerThread.run(HandlerThread.java:61)

Related

Getting different errors for different platforms using Renderscript Support Library

I'm having different troubles trying to implement some code written in Renderscript for Android.
First let me say that all my SDK packages are up-to-dated to the 22.3 version, including the Ecplise ADT and Build-Tools 19.0.0.
My purpose is to implement some high-computational image algorithms on a wide range of Android platforms, possibly starting from API 8. For this, I've set a reference to the renderscript-v8 library on my Ecplise project, while targeting the application to API 19.
I have two Android devices to test, the first is an Android 4.3 (API 18), the second comes with Android 2.2 (API 8). I'm experiencing different exceptions when running this piece of code, that calls ScriptIntrinsicYuvToRGB (code is partially taken from Executing ScriptIntrinsicYuvToRgb question):
/* --------------
global vars */
private RenderScript rs;
private ScriptIntrinsicYuvToRGB rs_YUVtoRGB;
private Allocation rs_YUVtoRGB_in;
private Allocation rs_YUVtoRGB_out;
/* --------------
in constructor... */
this.rs = RenderScript.create(this.getContext());
this.rs_YUVtoRGB = ScriptIntrinsicYuvToRGB.create(this.rs, Element.U8_4(rs));
Type.Builder tb_in = new Type.Builder(this.rs, Element.createPixel(this.rs, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
tb_in.setX(prevWidth);
tb_in.setY(prevHeight);
tb_in.setMipmaps(false);
tb_in.setYuvFormat(this.camera.getParameters().getPreviewFormat());
this.rs_YUVtoRGB_in = Allocation.createTyped(this.rs, tb_in.create(), Allocation.USAGE_SCRIPT);
Type.Builder tb_out = new Type.Builder(this.rs, Element.RGBA_8888(this.rs));
tb_out.setX(prevWidth);
tb_out.setY(prevHeight);
tb_out.setMipmaps(false);
this.rs_YUVtoRGB_out = Allocation.createTyped (this.rs, tb_out.create(), Allocation.USAGE_SCRIPT);
/* --------------
launching the script... */
// byte[] raw... // a YUV image
this.rs_YUVtoRGB_in.copyFrom(raw);
this.rs_YUVtoRGB.setInput(this.rs_YUVtoRGB_in);
this.rs_YUVtoRGB.forEach(this.rs_YUVtoRGB_out);
int[] framePixels = new int[previewSize.width * previewSize.height];
this.rs_YUVtoRGB_out.copyTo(framePixels); // final RGB converted image
Eclipse manages to compile it (it should mean that the library is well referenced), but...
Android 4.3 fails at : Type.Builder tb_in = new Type.Builder(this.rs, Element.createPixel(this.rs, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV)); with Unsupported DataKind
11-24 11:17:57.685: E/AndroidRuntime(2494): FATAL EXCEPTION: main
11-24 11:17:57.685: E/AndroidRuntime(2494): android.renderscript.RSIllegalArgumentException: Unsupported DataKind
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.renderscript.Element.createPixel(Element.java:911)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.support.v8.renderscript.ElementThunker.createPixel(ElementThunker.java:224)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.support.v8.renderscript.Element.createPixel(Element.java:832)
11-24 11:17:57.685: E/AndroidRuntime(2494): at com.lag.appprj.CameraPreview.setupCamera(CameraPreview.java:167)
11-24 11:17:57.685: E/AndroidRuntime(2494): at com.lag.appprj.CameraPreview.surfaceCreated(CameraPreview.java:86)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView.updateWindow(SurfaceView.java:571)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView.access$000(SurfaceView.java:86)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:833)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1860)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
11-24 11:17:57.685: E/AndroidRuntime(2494): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
While on Android 2.2 it fails in the init phase: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Library RSSupport not found
11-24 11:45:45.329: E/AndroidRuntime(2048): FATAL EXCEPTION: main
11-24 11:45:45.329: E/AndroidRuntime(2048): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lag.appprj/com.lag.appprj.CaptureActivity}: android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Library RSSupport not found
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.os.Looper.loop(Looper.java:123)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-24 11:45:45.329: E/AndroidRuntime(2048): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 11:45:45.329: E/AndroidRuntime(2048): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-24 11:45:45.329: E/AndroidRuntime(2048): at dalvik.system.NativeStart.main(Native Method)
11-24 11:45:45.329: E/AndroidRuntime(2048): Caused by: android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Library RSSupport not found
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:945)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:982)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.support.v8.renderscript.RenderScript.create(RenderScript.java:968)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.lag.appprj.CameraPreview.<init>(CameraPreview.java:80)
11-24 11:45:45.329: E/AndroidRuntime(2048): at com.lag.appprj.CaptureActivity.onCreate(CaptureActivity.java:34)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-24 11:45:45.329: E/AndroidRuntime(2048): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
Thanks for the help
The error with createPixel() is an actual bug in ElementThunker.java. It is missing a case for PIXEL_YUV, so it ends up returning null instead of the appropriate type. I will fix this in AOSP and for a future SDK release. (Patch is at https://android-review.googlesource.com/70810).
As far as the library load issue, I believe on your other SO question you noticed that your Application.mk file was not building for all architectures (and hence not bundling the appropriate shared libraries). The reason that it works on 4.3 is that 4.3 has a copy of libRSSupport.so automatically (although it really shouldn't). Older devices will obviously not have a default /system/lib/ copy of that .so, so they will always fail to load it unless your build actually packages it up with the apk.

Decompiled and imported into Eclipse and got instantiation error

I am a newbie to Android App programming. I decompiled an APK and imported into Eclipse. I ran it on an Android emulator and I got the message below on Logcat. Can someone give me an idea where to start looking. The app works on the Android phone. Thanks.
11-24 13:41:39.046: D/AndroidRuntime(363): Shutting down VM
11-24 13:41:39.046: W/dalvikvm(363): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-24 13:41:39.126: E/AndroidRuntime(363): FATAL EXCEPTION: main
11-24 13:41:39.126: E/AndroidRuntime(363): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.breakeven/com.breakeven.BreakEvenCalculatorActivity}: java.lang.ClassNotFoundException: com.breakeven.BreakEvenCalculatorActivity in loader dalvik.system.PathClassLoader[/data/app/com.breakeven-1.apk]
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.os.Looper.loop(Looper.java:123)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 13:41:39.126: E/AndroidRuntime(363): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 13:41:39.126: E/AndroidRuntime(363): at java.lang.reflect.Method.invoke(Method.java:507)
11-24 13:41:39.126: E/AndroidRuntime(363): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 13:41:39.126: E/AndroidRuntime(363): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 13:41:39.126: E/AndroidRuntime(363): at dalvik.system.NativeStart.main(Native Method)
11-24 13:41:39.126: E/AndroidRuntime(363): Caused by: java.lang.ClassNotFoundException: com.breakeven.BreakEvenCalculatorActivity in loader dalvik.system.PathClassLoader[/data/app/com.breakeven-1.apk]
11-24 13:41:39.126: E/AndroidRuntime(363): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-24 13:41:39.126: E/AndroidRuntime(363): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-24 13:41:39.126: E/AndroidRuntime(363): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
11-24 13:41:39.126: E/AndroidRuntime(363): ... 11 more
11-24 13:43:41.106: I/Process(363): Sending signal. PID: 363 SIG: 9
11-24 13:44:17.136: D/AndroidRuntime(393): Shutting down VM
11-24 13:44:17.136: W/dalvikvm(393): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-24 13:44:17.206: E/AndroidRuntime(393): FATAL EXCEPTION: main
11-24 13:44:17.206: E/AndroidRuntime(393): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.breakeven/com.breakeven.BreakEvenCalculatorActivity}: java.lang.ClassNotFoundException: com.breakeven.BreakEvenCalculatorActivity in loader dalvik.system.PathClassLoader[/data/app/com.breakeven-1.apk]
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.os.Looper.loop(Looper.java:123)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 13:44:17.206: E/AndroidRuntime(393): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 13:44:17.206: E/AndroidRuntime(393): at java.lang.reflect.Method.invoke(Method.java:507)
11-24 13:44:17.206: E/AndroidRuntime(393): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 13:44:17.206: E/AndroidRuntime(393): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 13:44:17.206: E/AndroidRuntime(393): at dalvik.system.NativeStart.main(Native Method)
11-24 13:44:17.206: E/AndroidRuntime(393): Caused by: java.lang.ClassNotFoundException: com.breakeven.BreakEvenCalculatorActivity in loader dalvik.system.PathClassLoader[/data/app/com.breakeven-1.apk]
11-24 13:44:17.206: E/AndroidRuntime(393): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-24 13:44:17.206: E/AndroidRuntime(393): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-24 13:44:17.206: E/AndroidRuntime(393): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
11-24 13:44:17.206: E/AndroidRuntime(393): ... 11 more
11-24 13:44:23.546: I/Process(393): Sending signal. PID: 393 SIG: 9
11-24 13:49:28.816: D/AndroidRuntime(403): Shutting down VM
11-24 13:49:28.816: W/dalvikvm(403): threadid=1: thread exiting with uncaught exception (group=0x40015560)

Android Applications: Preference Activity Crashing

I'm trying to set up a preference activity to edit some of my app settings (obviously) but it keeps crashing when I press the action bar button.
Here is the run output:
11-24 19:40:18.629: E/AndroidRuntime(13755): FATAL EXCEPTION: main
11-24 19:40:18.629: E/AndroidRuntime(13755): Process: com.andrewq.simplestflashlight, PID: 13755
11-24 19:40:18.629: E/AndroidRuntime(13755): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.andrewq.simplestflashlight/com.andrewq.simplestflashlight.Preferences}: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.ActivityThread.access$700(ActivityThread.java:135)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.os.Handler.dispatchMessage(Handler.java:102)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.os.Looper.loop(Looper.java:137)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.ActivityThread.main(ActivityThread.java:4998)
11-24 19:40:18.629: E/AndroidRuntime(13755): at java.lang.reflect.Method.invoke(Native Method)
11-24 19:40:18.629: E/AndroidRuntime(13755): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-24 19:40:18.629: E/AndroidRuntime(13755): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
11-24 19:40:18.629: E/AndroidRuntime(13755): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-24 19:40:18.629: E/AndroidRuntime(13755): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.Activity.setContentView(Activity.java:1928)
11-24 19:40:18.629: E/AndroidRuntime(13755): at com.andrewq.simplestflashlight.Preferences.onCreate(Preferences.java:16)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.Activity.performCreate(Activity.java:5243)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
11-24 19:40:18.629: E/AndroidRuntime(13755): ... 9 more
11-24 19:40:18.629: E/AndroidRuntime(13755): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.PreferenceScreen" on path: DexPathList[[zip file "/data/app/com.andrewq.simplestflashlight-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.andrewq.simplestflashlight-1, /vendor/lib, /system/lib]]
11-24 19:40:18.629: E/AndroidRuntime(13755): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-24 19:40:18.629: E/AndroidRuntime(13755): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-24 19:40:18.629: E/AndroidRuntime(13755): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
11-24 19:40:18.629: E/AndroidRuntime(13755): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
11-24 19:40:18.629: E/AndroidRuntime(13755): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
11-24 19:40:18.629: E/AndroidRuntime(13755): ... 18 more
11-24 19:40:18.629: E/AndroidRuntime(13755): Suppressed: java.lang.ClassNotFoundException: android.view.PreferenceScreen
11-24 19:40:18.629: E/AndroidRuntime(13755): at java.lang.Class.classForName(Native Method)
11-24 19:40:18.629: E/AndroidRuntime(13755): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
11-24 19:40:18.629: E/AndroidRuntime(13755): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
11-24 19:40:18.629: E/AndroidRuntime(13755): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
11-24 19:40:18.629: E/AndroidRuntime(13755): ... 24 more
11-24 19:40:18.629: E/AndroidRuntime(13755): Caused by: java.lang.NoClassDefFoundError: Class "Landroid/view/PreferenceScreen;" not found
11-24 19:40:18.629: E/AndroidRuntime(13755): ... 28 more
Here is the class for the activity:
//Class name omitted but added in actual code
//Imports omitted but added in actual code
public class Preferences extends PreferenceActivity{
#Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.xml.preferences);
//Initialize the "up" button
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
}
return super.onOptionsItemSelected(item);
}
Here's the layout file:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="Application Settings" android:padding="10dp" >
<CheckBoxPreference android:title="Check me!"
android:summary="This is a sample check box preference."
android:key="prefCheck" />
</PreferenceCategory>
</PreferenceScreen>
And FINALLY here's the menu file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_about"
android:icon="#drawable/action_about"
android:showAsAction="always"
android:title="#string/action_about"/>
<item
android:id="#+id/action_settings"
android:showAsAction="never"
android:title="#string/action_settings"/>
</menu>
Sorry if there's a not of unneeded code but I don't know what to omit in order to get a solution to my problem. Thanks in advance if anyone helps :)
Andrew
The preference definition in R.xml.preferences cannot be set as a regular layout. Replace:
setContentView(R.xml.preferences);
With:
addPreferencesFromResource(R.xml.preferences);
Quote from the article on Android Settings:
The most important thing to remember is that you do not load a layout
of views during the onCreate() callback. Instead, you call
addPreferencesFromResource() to add the preferences you've declared
in an XML file to the activity.

Simulator Crashes with TextView and ImageView

I recently started programing and when I did a basic ImageView and TextView shown below.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
</TextView>
<ImageView
android:id="#+id/joe"
android:src="#drawable/joe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
The simulator crashed and the logcat gave this error:
11-24 11:09:20.938: D/AndroidRuntime(713): Shutting down VM
11-24 11:09:20.938: W/dalvikvm(713): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
11-24 11:09:20.938: E/AndroidRuntime(713): Uncaught handler: thread main exiting due to uncaught exception
11-24 11:09:20.958: E/AndroidRuntime(713): java.lang.RuntimeException: Unable to start activity ComponentInfo{tristan.wuker.wrje/tristan.wuker.wrje.MrttestActivity}: java.lang.RuntimeException: Binary XML file line #10: You must supply a layout_width attribute.
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.os.Looper.loop(Looper.java:123)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.main(ActivityThread.java:4203)
11-24 11:09:20.958: E/AndroidRuntime(713): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 11:09:20.958: E/AndroidRuntime(713): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 11:09:20.958: E/AndroidRuntime(713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
11-24 11:09:20.958: E/AndroidRuntime(713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
11-24 11:09:20.958: E/AndroidRuntime(713): at dalvik.system.NativeStart.main(Native Method)
11-24 11:09:20.958: E/AndroidRuntime(713): Caused by: java.lang.RuntimeException: Binary XML file line #10: You must supply a layout_width attribute.
11-24 11:09:20.958: E/AndroidRuntime(713): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:438)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:3433)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3513)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1265)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1191)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:45)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.LayoutInflater.rInflate(LayoutInflater.java:619)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-24 11:09:20.958: E/AndroidRuntime(713): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.Activity.setContentView(Activity.java:1620)
11-24 11:09:20.958: E/AndroidRuntime(713): at tristan.wuker.wrje.MrttestActivity.onCreate(MrttestActivity.java:11)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
11-24 11:09:20.958: E/AndroidRuntime(713): ... 11 more
11-24 11:09:20.978: I/dalvikvm(713): threadid=7: reacting to signal 3
11-24 11:09:20.978: E/dalvikvm(713): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
I am also new to this website so I am sorry if I posted this wrong.
Also if it helps to know, when I take out ImageView the text works like a charm.
As I am sure you figured out in the end, the logs tell you where the problem is. Specifically this line (that I shortened so it fits):
11-24 11:09:20.958 .. Caused by.. #10: You must supply a layout_width attribute.
As you can see in the snippet below:
<TextView>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
</TextView>
You closed the <TextView\> element too early, before specifying any attributes. The one that log mentions is _layout_width_.
All you have to do to fix this 'issue' is remove the right shevron from the TextView element opening, like this:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
</TextView>
Boom, done :)
PS: One teeny tiny detail though fill_parent is depreciated, you should use match_parent instead:
<TextView>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
</TextView>
I tried your code just now and seems to work when I take out the closing </TextView> tag:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
<ImageView
android:id="#+id/joe"
android:src="#drawable/joe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

Android webdav Java Sardine

im trying Sardine to make a webdav client in android, im trying this code:
This works perfect on JAVA aplicacion, but crashes in android :(
HttpClient client = new DefaultHttpClient();
SardineImpl sardine = new SardineImpl((AbstractHttpClient) client,"testuser","test");
List<DavResource> resources = sardine.getResources("http://demo.sabredav.org/");
for (int i = 1; i < resources.size(); i++) {
System.out.println(resources.get(i));
}
Replacing System.out.println by Toast i get this
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): java.lang.NoSuchMethodError: org.apache.http.impl.client.AbstractHttpClient.setRedirectStrategy
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.googlecode.sardine.impl.SardineImpl.init(SardineImpl.java:188)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.googlecode.sardine.impl.SardineImpl.<init>(SardineImpl.java:182)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at es.sardine.sardine.onCreate(sardine.java:39)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.os.Looper.loop(Looper.java:143)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.main(ActivityThread.java:4914)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at dalvik.system.NativeStart.main(Native Method)
I had the same trouble trying to use Sardine and including Apache HttpClient which would conflict with the version embedded in Android. So I decided to replace it with OkHttp and I have much less trouble.
Here is the fork I created: https://github.com/thegrizzlylabs/sardine-android
Did you see this q: Using webdav on Android ? It essentially says that Sardine needs newer HttpClient version than packages with Android, and provides a lick to patched HttpClient 4.1 linkable into Android apps.
For you only iterating through the elements on the server this code worked for me:
try{
Sardine sardine = SardineFactory.begin("username", "password");
List<DavResource> resources = sardine.list("webdav/server/directory/");
buffer = new StringBuilder();
for (DavResource res : resources)
{
//for example
buffer.append(res.toString());
}
}catch(Exception e){
Log.e("VIEWER" , e.getMessage());
}
I used the Sardine-Android Project Library in combination with the simpleframework.xml.

Categories

Resources