bmi app crashes when calculate button pressed - android

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.

Related

Android - Unfortunately, myapp has stopped

I am learning to develop Android applications and have come across a problem with my app. I have created an app that will allow user to type some text and when a button is pressed, a function is called that performs parsing the input string to double and then displays it. I have received no errors, but whenever I run the app on any emulator, it says "Unfortunately, myapp has stopped".
Here is the LogCat:
04-04 14:34:11.579: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:11.969: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:12.089: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:12.720: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:12.860: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:12.979: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:13.069: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:13.479: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:13.599: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:14.009: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:14.129: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:14.320: D/libEGL(657): loaded /system/lib/egl/libGLES_android.so
04-04 14:34:14.390: D/libEGL(657): loaded /system/lib/egl/libEGL_emulation.so
04-04 14:34:14.409: D/(657): HostConnection::get() New Host Connection established 0xd7820, tid 657
04-04 14:34:14.429: D/libEGL(657): loaded /system/lib/egl/libGLESv1_CM_emulation.so
04-04 14:34:14.449: D/libEGL(657): loaded /system/lib/egl/libGLESv2_emulation.so
04-04 14:34:14.519: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:14.579: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:14.719: W/EGL_emulation(657): eglSurfaceAttrib not implemented
04-04 14:34:14.769: D/OpenGLRenderer(657): Enabling debug mode 0
04-04 14:34:15.049: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:15.173: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:15.579: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:15.790: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:16.030: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:16.109: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:16.549: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:16.739: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:17.029: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:17.220: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:27.099: D/AndroidRuntime(657): Shutting down VM
04-04 14:34:27.099: W/dalvikvm(657): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-04 14:34:27.219: E/AndroidRuntime(657): FATAL EXCEPTION: main
04-04 14:34:27.219: E/AndroidRuntime(657): java.lang.IllegalStateException: Could not execute method of the activity
04-04 14:34:27.219: E/AndroidRuntime(657): at android.view.View$1.onClick(View.java:3044)
04-04 14:34:27.219: E/AndroidRuntime(657): at android.view.View.performClick(View.java:3511)
04-04 14:34:27.219: E/AndroidRuntime(657): at android.view.View$PerformClick.run(View.java:14105)
04-04 14:34:27.219: E/AndroidRuntime(657): at android.os.Handler.handleCallback(Handler.java:605)
04-04 14:34:27.219: E/AndroidRuntime(657): at android.os.Handler.dispatchMessage(Handler.java:92)
04-04 14:34:27.219: E/AndroidRuntime(657): at android.os.Looper.loop(Looper.java:137)
04-04 14:34:27.219: E/AndroidRuntime(657): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-04 14:34:27.219: E/AndroidRuntime(657): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 14:34:27.219: E/AndroidRuntime(657): at java.lang.reflect.Method.invoke(Method.java:511)
04-04 14:34:27.219: E/AndroidRuntime(657): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-04 14:34:27.219: E/AndroidRuntime(657): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-04 14:34:27.219: E/AndroidRuntime(657): at dalvik.system.NativeStart.main(Native Method)
04-04 14:34:27.219: E/AndroidRuntime(657): Caused by: java.lang.reflect.InvocationTargetException
04-04 14:34:27.219: E/AndroidRuntime(657): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 14:34:27.219: E/AndroidRuntime(657): at java.lang.reflect.Method.invoke(Method.java:511)
04-04 14:34:27.219: E/AndroidRuntime(657): at android.view.View$1.onClick(View.java:3039)
04-04 14:34:27.219: E/AndroidRuntime(657): ... 11 more
04-04 14:34:27.219: E/AndroidRuntime(657): Caused by: java.lang.NumberFormatException: Invalid double: "android.widget.EditText#40f7be40"
04-04 14:34:27.219: E/AndroidRuntime(657): at java.lang.StringToReal.invalidReal(StringToReal.java:63)
04-04 14:34:27.219: E/AndroidRuntime(657): at java.lang.StringToReal.initialParse(StringToReal.java:114)
04-04 14:34:27.219: E/AndroidRuntime(657): at java.lang.StringToReal.parseDouble(StringToReal.java:263)
04-04 14:34:27.219: E/AndroidRuntime(657): at java.lang.Double.parseDouble(Double.java:295)
04-04 14:34:27.219: E/AndroidRuntime(657): at com.example.coinage.MainActivity.convert(MainActivity.java:25)
04-04 14:34:27.219: E/AndroidRuntime(657): ... 14 more
04-04 14:34:28.069: I/dalvikvm(657): threadid=3: reacting to signal 3
04-04 14:34:28.179: I/dalvikvm(657): Wrote stack traces to '/data/anr/traces.txt'
04-04 14:34:29.729: I/Process(657): Sending signal. PID: 657 SIG: 9
Method that performs Computation
public void convert(View view){
int countOf2Po = 0, countOf1Po = 0, countOf50p = 0, countOf20p = 0, countOf2p = 0, countOf1p = 0;
EditText amt = (EditText) findViewById (R.id.amount);
TextView penny = (TextView) findViewById (R.id.penny);
double amount = Double.parseDouble(amt.toString()) * 100;
while(amount >= 200){
amount = amount - 200;
countOf2Po++;
}
while(amount >= 100){
amount = amount - 100;
countOf1Po++;
}
while(amount >= 50){
amount = amount - 50;
countOf50p++;
}
while(amount >= 20){
amount = amount - 20;
countOf20p++;
}
while(amount >= 2){
amount = amount - 2;
countOf2p++;
}
if(amount % 2 != 0){
countOf1p++;
}
penny.setText("Converting " + penny + " into coins.");
penny.setVisibility(View.VISIBLE);
}
You're trying to cast the toString() value of the EditText to a double, which is not the text entered into the EditText like you expected, but the name the name of the class concatenated with the instance's hash code:
The toString method for class Object returns a string consisting of
the name of the class of which the object is an instance, the at-sign
character `#', and the unsigned hexadecimal representation of the hash
code of the object. In other words, this method returns a string equal
to the value of:
getClass().getName() + '#' + Integer.toHexString(hashCode())
What you want to do, is to retrieve the entered text using getText(), and convert that to a String:
double amount = Double.parseDouble(amt.getText().toString()) * 100;
Note that this may lead to a NumberFormatException if the input is not a proper double.

Erroneous exception "A WebView method was called on thread 'WebViewCoreThread'."

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");

Google maps api version 1 doesn't work anymore (Android) why?

I had signed up for Google maps api vesrion 1. I got a key that used to work fine before but now it's not working. On the Official site they said that the applications using google maps version 1 will continue to work, but it is advised not to use it.
So then why doesn't my application work now... I haven't made any changes in the Code.... here is my log cat.
04-04 16:37:26.701: W/MapActivity(873): Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher#411fc5b0
04-04 16:37:26.801: V/MapActivity(873): Recycling map object.
04-04 16:37:27.321: I/MapActivity(873): Handling network change notification:CONNECTED
04-04 16:37:27.321: E/MapActivity(873): Couldn't get connection factory client
04-04 16:37:32.590: W/System.err(873): IOException processing: 26
04-04 16:37:32.590: W/System.err(873): java.io.IOException: Server returned: 3
04-04 16:37:32.641: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
04-04 16:37:32.641: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
04-04 16:37:32.641: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
04-04 16:37:32.641: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
04-04 16:37:32.641: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
04-04 16:37:32.641: W/System.err(873): at java.lang.Thread.run(Thread.java:856)
04-04 16:37:38.341: W/System.err(873): IOException processing: 26
04-04 16:37:38.341: W/System.err(873): java.io.IOException: Server returned: 3
04-04 16:37:38.415: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
04-04 16:37:38.415: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
04-04 16:37:38.415: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
04-04 16:37:38.421: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
04-04 16:37:38.421: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
04-04 16:37:38.421: W/System.err(873): at java.lang.Thread.run(Thread.java:856)
04-04 16:37:45.323: W/System.err(873): IOException processing: 26
04-04 16:37:45.323: W/System.err(873): java.io.IOException: Server returned: 3
04-04 16:37:45.323: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
04-04 16:37:45.331: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
04-04 16:37:45.331: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
04-04 16:37:45.331: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
04-04 16:37:45.331: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
04-04 16:37:45.331: W/System.err(873): at java.lang.Thread.run(Thread.java:856)
04-04 16:37:51.241: I/Choreographer(873): Skipped 34 frames! The application may be doing too much work on its main thread.
04-04 16:37:53.021: W/System.err(873): java.lang.IllegalStateException: Connection pool shut down.
04-04 16:37:53.021: W/System.err(873): at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:284)
04-04 16:37:53.030: W/System.err(873): at org.apache.http.impl.conn.tsccm.ConnPoolByRoute$1.getPoolEntry(ConnPoolByRoute.java:238)
04-04 16:37:53.030: W/System.err(873): at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:176)
04-04 16:37:53.030: W/System.err(873): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:326)
04-04 16:37:53.114: W/System.err(873): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
04-04 16:37:53.114: W/System.err(873): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
04-04 16:37:53.114: W/System.err(873): at android_maps_conflict_avoidance.com.google.common.io.android.AndroidHttpClient.execute(AndroidHttpClient.java:246)
04-04 16:37:53.114: W/System.err(873): at android_maps_conflict_avoidance.com.google.common.io.android.GoogleHttpClient.executeWithoutRewriting(GoogleHttpClient.java:129)
04-04 16:37:53.170: W/System.err(873): at android_maps_conflict_avoidance.com.google.common.io.android.GoogleHttpClient.execute(GoogleHttpClient.java:189)
04-04 16:37:53.200: W/System.err(873): at android_maps_conflict_avoidance.com.google.common.io.android.GoogleHttpClient.execute(GoogleHttpClient.java:242)
04-04 16:37:53.200: W/System.err(873): at android_maps_conflict_avoidance.com.google.common.io.android.AndroidHttpConnectionFactory$AndroidGoogleHttpConnection.getResponse(AndroidHttpConnectionFactory.java:132)
04-04 16:37:53.280: W/System.err(873): at android_maps_conflict_avoidance.com.google.common.io.android.AndroidHttpConnectionFactory$AndroidGoogleHttpConnection.openDataInputStream(AndroidHttpConnectionFactory.java:153)
04-04 16:37:53.280: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:922)
04-04 16:37:53.280: W/System.err(873): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
04-04 16:37:53.280: W/System.err(873): at java.lang.Thread.run(Thread.java:856)
Here's my Layout
<RelativeLayout 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" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
<com.google.android.maps.MapView
android:id="#+id/pooja"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:apiKey="I've used my Key here!!"
android:clickable="true" />

Stericson's root tools library not working - makes force close?

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!

Problem with adding rows in TableLayout programmatically

I am trying to add rows in a TableLayout programmatically and I am following instructions given in following links:
Dynamically Adding Rows to TableLayout and Creating Table Rows Inside A Table Layout Programmatically
I am always getting Application has stopped unexpectedly. Please try again. error. If I define the whole TableLayout in XML, then it works fine but when I try to do it programmatically, I always get the that error.
Here is the code of my XML file (main.xml):
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:id="#+id/maintable">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_column="1"
android:text="Open..."
android:padding="3dip" />
<TextView
android:text="Ctrl-O"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>
and this is the code I've done in my .java:
public class HelloTableLayout extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Find Tablelayout defined in main.xml */
TableLayout tl = (TableLayout)findViewById(R.id.maintable);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("Dynamic Button");
b.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
/* Add row to TableLayout. */
tl.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
Here is LogCat for the problem:
04-04 13:56:21.161: DEBUG/AndroidRuntime(502): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
04-04 13:56:21.171: DEBUG/AndroidRuntime(502): CheckJNI is ON
04-04 13:56:21.441: DEBUG/AndroidRuntime(502): --- registering native functions ---
04-04 13:56:21.871: DEBUG/ddm-heap(502): Got feature list request
04-04 13:56:22.411: DEBUG/AndroidRuntime(502): Shutting down VM
04-04 13:56:22.411: DEBUG/dalvikvm(502): DestroyJavaVM waiting for non-daemon threads to exit
04-04 13:56:22.411: DEBUG/dalvikvm(502): DestroyJavaVM shutting VM down
04-04 13:56:22.421: DEBUG/dalvikvm(502): HeapWorker thread shutting down
04-04 13:56:22.421: DEBUG/dalvikvm(502): HeapWorker thread has shut down
04-04 13:56:22.431: DEBUG/jdwp(502): JDWP shutting down net...
04-04 13:56:22.431: ERROR/AndroidRuntime(502): ERROR: thread attach failed
04-04 13:56:22.441: INFO/dalvikvm(502): Debugger has detached; object registry had 1 entries
04-04 13:56:22.451: DEBUG/dalvikvm(502): VM cleaning up
04-04 13:56:22.481: DEBUG/dalvikvm(502): LinearAlloc 0x0 used 629532 of 5242880 (12%)
04-04 13:56:23.111: DEBUG/AndroidRuntime(510): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
04-04 13:56:23.121: DEBUG/AndroidRuntime(510): CheckJNI is ON
04-04 13:56:23.391: DEBUG/AndroidRuntime(510): --- registering native functions ---
04-04 13:56:23.821: DEBUG/ddm-heap(510): Got feature list request
04-04 13:56:24.401: INFO/ActivityManager(35): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.vision.HelloLinearLayout/.HelloLinearLayout }
04-04 13:56:24.471: DEBUG/AndroidRuntime(510): Shutting down VM
04-04 13:56:24.491: DEBUG/dalvikvm(510): DestroyJavaVM waiting for non-daemon threads to exit
04-04 13:56:24.521: DEBUG/dalvikvm(510): DestroyJavaVM shutting VM down
04-04 13:56:24.521: DEBUG/dalvikvm(510): HeapWorker thread shutting down
04-04 13:56:24.547: ERROR/AndroidRuntime(510): ERROR: thread attach failed
04-04 13:56:24.571: DEBUG/dalvikvm(510): HeapWorker thread has shut down
04-04 13:56:24.591: DEBUG/jdwp(510): JDWP shutting down net...
04-04 13:56:24.611: INFO/dalvikvm(510): Debugger has detached; object registry had 1 entries
04-04 13:56:24.611: DEBUG/dalvikvm(510): VM cleaning up
04-04 13:56:24.761: INFO/ActivityManager(35): Start proc com.vision.HelloLinearLayout for activity com.vision.HelloLinearLayout/.HelloLinearLayout: pid=517 uid=10028 gids={3003}
04-04 13:56:24.771: DEBUG/dalvikvm(510): LinearAlloc 0x0 used 639500 of 5242880 (12%)
04-04 13:56:25.041: DEBUG/ddm-heap(517): Got feature list request
04-04 13:56:25.651: DEBUG/AndroidRuntime(517): Shutting down VM
04-04 13:56:25.661: WARN/dalvikvm(517): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-04 13:56:25.661: ERROR/AndroidRuntime(517): Uncaught handler: thread main exiting due to uncaught exception
04-04 13:56:25.692: ERROR/AndroidRuntime(517): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vision.HelloLinearLayout/com.vision.HelloLinearLayout.HelloLinearLayout}: java.lang.NullPointerException
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.os.Looper.loop(Looper.java:123)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at java.lang.reflect.Method.invoke(Method.java:521)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at dalvik.system.NativeStart.main(Native Method)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): Caused by: java.lang.NullPointerException
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at com.vision.HelloLinearLayout.HelloLinearLayout.onCreate(HelloLinearLayout.java:35)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-04 13:56:25.692: ERROR/AndroidRuntime(517): ... 11 more
04-04 13:56:25.731: INFO/Process(35): Sending signal. PID: 517 SIG: 3
04-04 13:56:25.741: INFO/dalvikvm(517): threadid=7: reacting to signal 3
04-04 13:56:25.741: INFO/dalvikvm(517): Wrote stack trace to '/data/anr/traces.txt'
04-04 13:56:34.527: WARN/ActivityManager(35): Launch timeout has expired, giving up wake lock!
04-04 13:56:35.244: WARN/ActivityManager(35): Activity idle timeout for HistoryRecord{43cb3358 com.vision.HelloLinearLayout/.HelloLinearLayout}
04-04 13:56:40.471: DEBUG/dalvikvm(98): GC freed 184 objects / 7888 bytes in 185ms
04-04 13:56:42.241: INFO/Process(517): Sending signal. PID: 517 SIG: 9
04-04 13:56:42.281: INFO/ActivityManager(35): Process com.vision.HelloLinearLayout (pid 517) has died.
04-04 13:56:42.361: INFO/UsageStats(35): Unexpected resume of com.android.launcher while already resumed in com.vision.HelloLinearLayout
04-04 13:56:42.461: ERROR/gralloc(35): [unregister] handle 0x342e08 still locked (state=40000001)
04-04 13:56:42.471: WARN/InputManagerService(35): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#43cd6e30
04-04 13:57:04.991: DEBUG/dalvikvm(94): GC freed 13267 objects / 589160 bytes in 124ms
04-04 14:14:44.061: DEBUG/dalvikvm(35): threadid=15: bogus mon 1+0>0; adjusting
Please help me sorting out this issue and guide me what I am doing wrong.
The line you want to look at is this one:
ERROR/AndroidRuntime(517): Caused by:
java.lang.NullPointerException 04-04
13:56:25.692:
ERROR/AndroidRuntime(517): at
com.vision.HelloLinearLayout.HelloLinearLayout.onCreate(HelloLinearLayout.java:35)
04-04 13:56:25.692:
ERROR/AndroidRuntime(517): at
I'm guessing this is line 35:
tl.addView(tr,new TableLayout.LayoutParams(
And that means your call here:
TableLayout tl = (TableLayout)findViewById(R.id.maintable);
has returned NULL?

Categories

Resources