Im getting "unclosed cursor detected" when starting a MapActivity even in the most basic form:
protected void onCreate(Bundle icicle) {
super.onCreate(icicle); // <--- The Exception occurs here
setContentView(R.layout.layout_map);
}
After the exception, the map starts and it works perfectly, but that exception every time it starts the activity really bothers me.
The Exception:
04-04 12:02:22.858: W/Cursor(14122): Unclosed Cursor detected
04-04 12:02:22.866: W/Cursor(14122): at android.content.ContentResolver.query(ContentResolver.java:258)
04-04 12:02:22.866: W/Cursor(14122): at com.google.common.android.AndroidConfig.getSetting(Unknown Source)
04-04 12:02:22.866: W/Cursor(14122): at com.google.common.android.AndroidConfig.getDistributionChannelInternal(Unknown Source)
04-04 12:02:22.866: W/Cursor(14122): at com.google.common.Config.init(Unknown Source)
04-04 12:02:22.866: W/Cursor(14122): at com.google.common.android.AndroidConfig.(Unknown Source)
04-04 12:02:22.866: W/Cursor(14122): at com.google.common.android.AndroidConfig.(Unknown Source)
04-04 12:02:22.866: W/Cursor(14122): at com.google.android.maps.MapActivity.onCreate(MapActivity.java:405)
04-04 12:02:22.866: W/Cursor(14122): at com.myapp.activity.MyMapActivity.onCreate(MyMapActivity.java:25)
04-04 12:02:22.874: W/Cursor(14122): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-04 12:02:22.874: W/Cursor(14122): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
04-04 12:02:22.874: W/Cursor(14122): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
04-04 12:02:22.874: W/Cursor(14122): at android.app.ActivityThread.access$2500(ActivityThread.java:129)
04-04 12:02:22.874: W/Cursor(14122): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2117)
04-04 12:02:22.874: W/Cursor(14122): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 12:02:22.874: W/Cursor(14122): at android.os.Looper.loop(Looper.java:143)
04-04 12:02:22.874: W/Cursor(14122): at android.app.ActivityThread.main(ActivityThread.java:4717)
04-04 12:02:22.874: W/Cursor(14122): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 12:02:22.882: W/Cursor(14122): at java.lang.reflect.Method.invoke(Method.java:521)
04-04 12:02:22.882: W/Cursor(14122): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-04 12:02:22.882: W/Cursor(14122): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-04 12:02:22.882: W/Cursor(14122): at dalvik.system.NativeStart.main(Native Method)
I searched the web but found nothing...
Extra info:
Im using Google API 2.2
Tested it on the device and on the AVD
Have other Map projects working with Google API 2.1 (Without that exception of course)
My AndroidManifest is not missing anything (hence the map starts and works after the exception is thrown)
Help is appreciated!
Edit:
I updated both Google API level 7 and 8 (the problem started on 8) now it happens on API level 7 too...
Hydrangea helped me notice that the Bundle variables name in my MapActivity (icicle) differs from the "standard" (savedInstanceState) maybe that has something to do with the problem?
You need to close the cursor after you have the information from the database.
Example:
cursor.close();
Are you sure the problem doesn't exist from another class? Your code looks okay to me.
I ran this on a 2.2 device, and didn't get any such error. Is something else happening in your Activity that might be causing it? Perhaps something in the bundle causing super.onCreate() to have issues?
public class HelloGoogleMapsActivity extends MapActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Related
I'm having this StackTrace logged when trying a simple WebView project on the Samsung Tab 8.9
04-04 13:32:26.688: D/core(9992): core.cpp 228 bind alias=User
04-04 13:32:26.708: W/webview(9992): java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
04-04 13:32:26.708: W/webview(9992): at android.webkit.WebView.checkThread(WebView.java:14244)
04-04 13:32:26.708: W/webview(9992): at android.webkit.WebView.getSettings(WebView.java:5378)
04-04 13:32:26.708: W/webview(9992): at android.webkit.WebView.getVisibleTitleHeightImpl(WebView.java:2343)
04-04 13:32:26.708: W/webview(9992): at android.webkit.WebView.getViewHeight(WebView.java:2385)
04-04 13:32:26.708: W/webview(9992): at android.webkit.WebViewCore.setupViewport(WebViewCore.java:3422)
04-04 13:32:26.708: W/webview(9992): at android.webkit.WebViewCore.didFirstLayout(WebViewCore.java:3149)
04-04 13:32:26.708: W/webview(9992): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
04-04 13:32:26.708: W/webview(9992): at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113)
04-04 13:32:26.708: W/webview(9992): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 13:32:26.708: W/webview(9992): at android.os.Looper.loop(Looper.java:137)
04-04 13:32:26.708: W/webview(9992): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:828)
04-04 13:32:26.708: W/webview(9992): at java.lang.Thread.run(Thread.java:856)
04-04 13:32:26.718: W/webview(9992): java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
04-04 13:32:26.718: W/webview(9992): at android.webkit.WebView.checkThread(WebView.java:14244)
04-04 13:32:26.718: W/webview(9992): at android.webkit.WebView.getSettings(WebView.java:5378)
04-04 13:32:26.718: W/webview(9992): at android.webkit.WebView.getVisibleTitleHeightImpl(WebView.java:2343)
04-04 13:32:26.718: W/webview(9992): at android.webkit.WebView.getViewHeight(WebView.java:2385)
04-04 13:32:26.718: W/webview(9992): at android.webkit.WebViewCore.setupViewport(WebViewCore.java:3422)
04-04 13:32:26.718: W/webview(9992): at android.webkit.WebViewCore.didFirstLayout(WebViewCore.java:3149)
04-04 13:32:26.718: W/webview(9992): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
04-04 13:32:26.718: W/webview(9992): at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113)
04-04 13:32:26.718: W/webview(9992): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 13:32:26.718: W/webview(9992): at android.os.Looper.loop(Looper.java:137)
04-04 13:32:26.718: W/webview(9992): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:828)
04-04 13:32:26.718: W/webview(9992): at java.lang.Thread.run(Thread.java:856)
As I understand it, the WebView is saying that I'm calling a WebView method on a WebView thread - rather than on the UI Thread. My problem is that I'm strictly not touching the WebView apart from in my onCreate() method - which is always run as part of the Activity lifecycle which AFAIK is always on the UI thread...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView mWebView = new WebView(this);
mWebView.loadUrl("file:///android_asset/index.htm");
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new CoreModInterface(), "Android");
mWebView.setWebViewClient(new WebViewClient());
setContentView(mWebView);
}
This warning doesn't happen on Nexus devices. Is this a problem with the Samsung Tab 8.9?
Edit
Removing these two lines removes the error. Adding these two lines at the same position inside of an explicit runOnUiThread() also gives the same error. At this stage I'm believing once more Samsung have made another mistake.
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new CoreModInterface(), "Android");
I've been adding a map to an Android project of mine and when ever my class loads the XML file with the map fragment it crashes, I was following this tutorial
( https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key )
I'm using a Nexus 7 (Jellybean 4.1) so that shouldn't be a problem, here is my class:
package com.app.thetoolstore;
import android.app.Activity;
import android.os.Bundle;
public class Tool_map extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_activity);
}
}
And here is my XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#001" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
and finally my Stack Trace:
04-04 10:01:35.551: E/AndroidRuntime(14362): FATAL EXCEPTION: main
04-04 10:01:35.551: E/AndroidRuntime(14362): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.thetoolstore/com.app.thetoolstore.Tool_map}: android.view.InflateException: Binary XML file line #29: Error inflating class fragment
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.os.Looper.loop(Looper.java:150)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.main(ActivityThread.java:4385)
04-04 10:01:35.551: E/AndroidRuntime(14362): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 10:01:35.551: E/AndroidRuntime(14362): at java.lang.reflect.Method.invoke(Method.java:507)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
04-04 10:01:35.551: E/AndroidRuntime(14362): at dalvik.system.NativeStart.main(Native Method)
04-04 10:01:35.551: E/AndroidRuntime(14362): Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class fragment
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.Activity.setContentView(Activity.java:1742)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.app.thetoolstore.Tool_map.onCreate(Tool_map.java:11)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
04-04 10:01:35.551: E/AndroidRuntime(14362): ... 11 more
04-04 10:01:35.551: E/AndroidRuntime(14362): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.app.thetoolstore-2.apk]
04-04 10:01:35.551: E/AndroidRuntime(14362): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-04 10:01:35.551: E/AndroidRuntime(14362): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-04 10:01:35.551: E/AndroidRuntime(14362): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-04 10:01:35.551: E/AndroidRuntime(14362): ... 20 more
UPDATE
I solved the issue using this tutorial https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw speciffically I had issues with the libs and google-pay services.
Hmmm lots of issue
1) You need to use FragmentActivity instead of Activity
2) android:name="com.google.android.gms.maps.MapFragment" replace by android:name="com.google.android.gms.maps.SupportMapFragment"/>
3) You need to add your key in manifest file and use Google Android Map API v2
4) Refer this tutorial http://www.vogella.com/articles/AndroidGoogleMaps/article.html
Is it possible to run Google Maps (API V1 is fine) on a none Google API build target? I have a special emulator that does not have the google api built in.
When I try adding the maps.jar to the libs folder in my project so the MapActivity can reference that I am getting the stack trace shown below. I am using the Google Maps API V1 Maps.jar for this.
I have tried setting the manifest to use , and also removed it, both do not work.
Thanks!
04-04 17:23:20.553: E/AndroidRuntime(12458): FATAL EXCEPTION: main
04-04 17:23:20.553: E/AndroidRuntime(12458): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.google.android.maps/com.google.android.maps.MapMainActivity}: java.lang.RuntimeException: stub
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.os.Looper.loop(Looper.java:123)
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-04 17:23:20.553: E/AndroidRuntime(12458): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 17:23:20.553: E/AndroidRuntime(12458): at java.lang.reflect.Method.invoke(Method.java:507)
04-04 17:23:20.553: E/AndroidRuntime(12458): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-04 17:23:20.553: E/AndroidRuntime(12458): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-04 17:23:20.553: E/AndroidRuntime(12458): at dalvik.system.NativeStart.main(Native Method)
04-04 17:23:20.553: E/AndroidRuntime(12458): Caused by: java.lang.RuntimeException: stub
04-04 17:23:20.553: E/AndroidRuntime(12458): at com.google.android.maps.MapActivity.<init>(Unknown Source)
04-04 17:23:20.553: E/AndroidRuntime(12458): at com.google.android.maps.MapMainActivity. <init>(MapMainActivity.java:10)
04-04 17:23:20.553: E/AndroidRuntime(12458): at java.lang.Class.newInstanceImpl(Native Method)
04-04 17:23:20.553: E/AndroidRuntime(12458): at java.lang.Class.newInstance(Class.java:1409)
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-04 17:23:20.553: E/AndroidRuntime(12458): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
Nope. The Google API's are required.
You should be using Google Maps Android API v2. API v1 is deprecated and you won't have it working for new applications.
It is even worse with API v2. Not officially supported to run on any emulator.
I think you can use a webView and load your map from a web server.
I'm a android beginner (my first post) and get a crash on running this bmi calculator tutorial: http://android-meda.blogspot.co.uk/2012/01/writing-your-first-android-app-body.html?m=1
Launched on my phone, the screen goes black with the message "BMI has stopped unfortunately". I'm not sure where to diagnose the problem so any help would be much appreciated.
Thank you
04-04 14:14:44.750: E/SensorManager(24999): thread start
04-04 14:14:44.755: D/SensorManager(24999): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl#42b75490
04-04 14:14:44.760: D/SensorManager(24999): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl#42b75490
04-04 14:14:44.760: D/Sensors(24999): Remain listener = Sending .. normal delay 200ms
04-04 14:14:44.760: I/Sensors(24999): sendDelay --- 200000000
04-04 14:14:44.765: D/SensorManager(24999): JNI - sendDelay
04-04 14:14:44.765: I/SensorManager(24999): Set normal delay = true
04-04 14:14:44.815: D/SensorManager(24999): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl#42b75490
04-04 14:14:44.870: D/libEGL(24999): loaded /system/lib/egl/libEGL_mali.so
04-04 14:14:44.875: D/libEGL(24999): loaded /system/lib/egl/libGLESv1_CM_mali.so
04-04 14:14:44.880: D/libEGL(24999): loaded /system/lib/egl/libGLESv2_mali.so
04-04 14:14:44.885: D/(24999): Device driver API match
04-04 14:14:44.885: D/(24999): Device driver API version: 10
04-04 14:14:44.885: D/(24999): User space API version: 10
04-04 14:14:44.885: D/(24999): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
04-04 14:14:44.910: D/OpenGLRenderer(24999): Enabling debug mode 0
04-04 14:14:44.985: W/IInputConnectionWrapper(24999): showStatusIcon on inactive InputConnection
04-04 14:14:52.235: D/SensorManager(24999): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl#42b75490
04-04 14:14:52.235: D/Sensors(24999): Remain listener = Sending .. normal delay 200ms
04-04 14:14:52.235: I/Sensors(24999): sendDelay --- 200000000
04-04 14:14:52.235: D/SensorManager(24999): JNI - sendDelay
04-04 14:14:52.235: I/SensorManager(24999): Set normal delay = true
04-04 14:14:52.240: D/SensorManager(24999): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl#42b78da8
04-04 14:14:52.260: W/IInputConnectionWrapper(24999): getSelectedText on inactive InputConnection
04-04 14:14:52.265: W/IInputConnectionWrapper(24999): setComposingText on inactive InputConnection
04-04 14:14:52.265: W/IInputConnectionWrapper(24999): getExtractedText on inactive InputConnection
04-04 14:14:53.420: D/AndroidRuntime(24999): Shutting down VM
04-04 14:14:53.420: W/dalvikvm(24999): threadid=1: thread exiting with uncaught exception (group=0x41f052a0)
04-04 14:14:53.430: E/AndroidRuntime(24999): FATAL EXCEPTION: main
04-04 14:14:53.430: E/AndroidRuntime(24999): java.lang.IllegalStateException: Could not execute method of the activity
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.view.View$1.onClick(View.java:3691)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.view.View.performClick(View.java:4211)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.view.View$PerformClick.run(View.java:17267)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.os.Handler.handleCallback(Handler.java:615)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.os.Handler.dispatchMessage(Handler.java:92)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.os.Looper.loop(Looper.java:137)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.app.ActivityThread.main(ActivityThread.java:4898)
04-04 14:14:53.430: E/AndroidRuntime(24999): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 14:14:53.430: E/AndroidRuntime(24999): at java.lang.reflect.Method.invoke(Method.java:511)
04-04 14:14:53.430: E/AndroidRuntime(24999): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
04-04 14:14:53.430: E/AndroidRuntime(24999): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
04-04 14:14:53.430: E/AndroidRuntime(24999): at dalvik.system.NativeStart.main(Native Method)
04-04 14:14:53.430: E/AndroidRuntime(24999): Caused by: java.lang.reflect.InvocationTargetException
04-04 14:14:53.430: E/AndroidRuntime(24999): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 14:14:53.430: E/AndroidRuntime(24999): at java.lang.reflect.Method.invoke(Method.java:511)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.view.View$1.onClick(View.java:3686)
04-04 14:14:53.430: E/AndroidRuntime(24999): ... 11 more
04-04 14:14:53.430: E/AndroidRuntime(24999): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
04-04 14:14:53.430: E/AndroidRuntime(24999): at com.example.bmi.MainActivity.calculateClickHandler(MainActivity.java:22)
04-04 14:14:53.430: E/AndroidRuntime(24999): ... 14 more
You are somewhere trying to cast a TextView into an EditText:
Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
Check your code for something like (TextView) variable = (EditText) findViewById(..)...
The problem is on line 22 in your MainActivity.java file.
If you analyze the stack trace you pasted:
Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
at com.example.bmi.MainActivity.calculateClickHandler(MainActivity.java:22)
It points you to where the problem is (MainActivity.java:22). This means line 22 from your MainActivity.java file.
Better, if you can't find the issue, paste a code snippet here so I can point more specifically to the problem. You should post the code from the onClick listener
EditText is used to edit text and TextView is a component used to display text. Therefore they are not compatible. The first is an editable form element while the latter is just for displaying purposes. You cannot cast one into another.
I am currently testing the roottools jar/library made by stericson in an app, but every time the app loads it force closes.
Here is the code:
package com.liamwli.root;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.stericson.RootTools.*;
public class root_test extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (RootTools.isBusyboxAvailable()) {
setContentView(R.layout.main);
} else {
RootTools.offerBusyBox(this);
}
if (RootTools.isRootAvailable()) {
Toast liam = Toast.makeText(this, "Root Available",
Toast.LENGTH_SHORT);
liam.show();
} else {
// do something else
}
}
}
And here is the logcat:
04-04 21:44:47.009: I/Process(6622): Sending signal. PID: 6622 SIG: 9
04-04 21:45:40.859: I/dalvikvm(6722): Could not find method com.stericson.RootTools.RootTools.isBusyboxAvailable, referenced from method com.liamwli.root.root_test.onCreate
04-04 21:45:40.859: W/dalvikvm(6722): VFY: unable to resolve static method 16: Lcom/stericson/RootTools/RootTools;.isBusyboxAvailable ()Z
04-04 21:45:40.859: D/dalvikvm(6722): VFY: replacing opcode 0x71 at 0x0003
04-04 21:45:40.859: D/AndroidRuntime(6722): Shutting down VM
04-04 21:45:40.859: W/dalvikvm(6722): threadid=1: thread exiting with uncaught exception (group=0x40ac21f8)
04-04 21:45:40.869: E/AndroidRuntime(6722): FATAL EXCEPTION: main
04-04 21:45:40.869: E/AndroidRuntime(6722): java.lang.NoClassDefFoundError: com.stericson.RootTools.RootTools
04-04 21:45:40.869: E/AndroidRuntime(6722): at com.liamwli.root.root_test.onCreate(root_test.java:16)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.app.Activity.performCreate(Activity.java:4465)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.os.Looper.loop(Looper.java:137)
04-04 21:45:40.869: E/AndroidRuntime(6722): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-04 21:45:40.869: E/AndroidRuntime(6722): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 21:45:40.869: E/AndroidRuntime(6722): at java.lang.reflect.Method.invoke(Method.java:511)
04-04 21:45:40.869: E/AndroidRuntime(6722): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
04-04 21:45:40.869: E/AndroidRuntime(6722): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
04-04 21:45:40.869: E/AndroidRuntime(6722): at dalvik.system.NativeStart.main(Native Method)
I am quite new to android, and I am now very confused :(
If someone could possibly help me, I would be grateful!
In Eclipse, right click your project, navigate to "Build Path", then to "configure build path"
Now choose "add External Jar"
Navigate to the RootTools .jar file you download and choose it.
Navigate to "Order and Export" make sure the box is ticked next to the library, and move it to the top of the list.
Finish up by choosing "ok"
I resolved this by separating the imports. Instead of:
import com.stericson.RootTools.*;
I only used/needed:
import com.stericson.RootTools.RootTools;
Try adding the others individually if you need them.
import com.stericson.RootTools.Mount;
import com.stericson.RootTools.Permissions;
import com.stericson.RootTools.RootToolsException;
import com.stericson.RootTools.Symlink;
import com.stericson.RootTools.SanityCheckRootTools;
It worked for me, hope it does for you!