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.
Related
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)
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.
I have a WebView in a TabView. The webView has a button. When the button is pressed a spinner is opened.
I am just loadng the webview with the URL. The action listener and spinner is triggered from the server side.
webview = (WebView) findViewById(R.id.webview);
....
....
webview.loadUrl(locationUrl);
My App is developed on Android 2.2. It is working fine in a device with OS 2.2 but crashing in 2.3.
Below is the log
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord#406e21e0 is not valid; is your activity running?
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.ViewRoot.setView(ViewRoot.java:527)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.app.Dialog.show(Dialog.java:241)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.webkit.WebView$InvokeListBox.run(WebView.java:7583)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Handler.handleCallback(Handler.java:587)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Handler.dispatchMessage(Handler.java:92)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Looper.loop(Looper.java:130)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at java.lang.reflect.Method.invoke(Method.java:507)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at dalvik.system.NativeStart.main(Native Method)
Use getparent() to get the parent context. As this is a tab, everything is done in parent context.
I have a WebView in one of the tabs in TabView. The webView loads a specific url which contains a spinner. The action listener and spinner is triggered from the server side embedded in the url.
webview = (WebView) findViewById(R.id.webview);
....
....
webview.loadUrl(locationUrl);
My App is developed on Android 2.2. It is working fine in a device with OS 2.2 but When I click the Spinner my app is crashing in a device with OS 2.3.
Below is the log
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord#406e21e0 is not valid; is your activity running?
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.ViewRoot.setView(ViewRoot.java:527)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.app.Dialog.show(Dialog.java:241)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.webkit.WebView$InvokeListBox.run(WebView.java:7583)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Handler.handleCallback(Handler.java:587)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Handler.dispatchMessage(Handler.java:92)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Looper.loop(Looper.java:130)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at java.lang.reflect.Method.invoke(Method.java:507)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at dalvik.system.NativeStart.main(Native Method)
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>