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?
Related
First of all sorry for my bad English, I am improving it.
I am trying to test the INSTALL_REFERER boradcast but I can't make it work.
My package:
es.beedroid.beebubble
The receiver in my manifest is:
<receiver
android:name="es.beedroid.beebubble.Load$InstallReferrerReceiver"
android:exported="true" >
<intent-filter >
<action android:name="com.android.vending.INSTALL_REFERRER" >
</action>
</intent-filter>
</receiver>
To test that receiver I make this:
static void displayMessage(Context context, String message) {
Intent i = new Intent("com.android.vending.INSTALL_REFERRER");
// i.setPackage("es.beedroid.beebubble");
i.putExtra("referrer", "&huevos=hola");
context.sendBroadcast(i);
}
But when I launch the app I get the following error:
04-04 12:46:05.432: E/AndroidRuntime(20996): FATAL EXCEPTION: main
04-04 12:46:05.432: E/AndroidRuntime(20996): java.lang.RuntimeException: Unable to instantiate receiver es.beedroid.beebubble.Load$InstallReferrerReceiver: java.lang.InstantiationException: es.beedroid.beebubble.Load$InstallReferrerReceiver
04-04 12:46:05.432: E/AndroidRuntime(20996): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1874)
04-04 12:46:05.432: E/AndroidRuntime(20996): at android.app.ActivityThread.access$2400(ActivityThread.java:156)
04-04 12:46:05.432: E/AndroidRuntime(20996): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1050)
04-04 12:46:05.432: E/AndroidRuntime(20996): at android.os.Handler.dispatchMessage(Handler.java:130)
04-04 12:46:05.432: E/AndroidRuntime(20996): at android.os.Looper.loop(SourceFile:351)
04-04 12:46:05.432: E/AndroidRuntime(20996): at android.app.ActivityThread.main(ActivityThread.java:3821)
04-04 12:46:05.432: E/AndroidRuntime(20996): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 12:46:05.432: E/AndroidRuntime(20996): at java.lang.reflect.Method.invoke(Method.java:538)
04-04 12:46:05.432: E/AndroidRuntime(20996): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
04-04 12:46:05.432: E/AndroidRuntime(20996): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
04-04 12:46:05.432: E/AndroidRuntime(20996): at dalvik.system.NativeStart.main(Native Method)
04-04 12:46:05.432: E/AndroidRuntime(20996): Caused by: java.lang.InstantiationException: es.beedroid.beebubble.Load$InstallReferrerReceiver
04-04 12:46:05.432: E/AndroidRuntime(20996): at java.lang.Class.newInstanceImpl(Native Method)
04-04 12:46:05.432: E/AndroidRuntime(20996): at java.lang.Class.newInstance(Class.java:1440)
04-04 12:46:05.432: E/AndroidRuntime(20996): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1865)
04-04 12:46:05.432: E/AndroidRuntime(20996): ... 10 more
Why? Is there another way to test that function? I tried to test it with adb but it doesn't work (it never passes by the receiver) .
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n es.beedroid.beebubble/.com.beedroid.activities.Load$InstallReferrerReceiver --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"
Try adding ./ to adb and use the below
./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n es.beedroid.beebubble/es.beedroid.beebubble.Load$InstallReferrerReceiver --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"
Also there were white spaces which I have removed and your path said
.com.beedroid.activities.Load$InstallReferrerReceiver
which I feel should be
es.beedroid.beebubble.Load$InstallReferrerReceiver
Let me know if it does work, coz I debugged using the same way and it did.
Note - App should NOT be running when you hit this from terminal.
Happy coding:)
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
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!
Help!
I’m having problems with my Sudoku application. I plugged in all the code to have my application remember the current position. Now when I run the application and I try to either start a new game or continue my Sudoku application says:
Sorry the application Sudoku (process org.example.sudoku) has stopped unexpectedly. Please try again.
It hasn’t done this in the past yet and I’m confused on where to go from here. I took a look at the logcat but I’m not sure what I should look for and how to fix it. Here is the logcat below
12-05 14:47:32.376: DEBUG/AndroidRuntime(289): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-05 14:47:32.376: DEBUG/AndroidRuntime(289): CheckJNI is ON
12-05 14:47:32.796: DEBUG/AndroidRuntime(289): —registering native functions --
12-05 14:47:34.306: DEBUG/AndroidRuntime(289): Shutting down VM
12-05 14:47:34.325: DEBUG/dalvikvm(289): Debugger has detached; object registry had 1 entries
12-05 14:47:34.345: INFO/AndroidRuntime(289): NOTE: attach of thread ‘Binder Thread #3’ failed
12-05 14:47:35.246: DEBUG/AndroidRuntime(297): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-05 14:47:35.246: DEBUG/AndroidRuntime(297): CheckJNI is ON
12-05 14:47:35.625: DEBUG/AndroidRuntime(297): —registering native functions --
12-05 14:47:36.985: INFO/ActivityManager(60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10000000 cmp=org.example.sudoku/.Sudoku }
12-05 14:47:37.126: DEBUG/AndroidRuntime(297): Shutting down VM
12-05 14:47:37.146: DEBUG/dalvikvm(297): Debugger has detached; object registry had 1 entries
12-05 14:47:37.186: INFO/AndroidRuntime(297): NOTE: attach of thread ‘Binder Thread #3’ failed
12-05 14:47:37.359: INFO/ActivityManager(60): Start proc org.example.sudoku for activity org.example.sudoku/.Sudoku: pid=304 uid=10037 gids={}
12-05 14:47:39.327: INFO/ActivityManager(60): Displayed activity org.example.sudoku/.Sudoku: 2047 ms (total 333042 ms)
12-05 14:47:44.516: DEBUG/dalvikvm(128): GC_EXPLICIT freed 205 objects / 9864 bytes in 134ms
12-05 14:48:14.936: DEBUG/Sudoku(304): clicked on 0
12-05 14:48:14.957: INFO/ActivityManager(60): Starting activity: Intent { cmp=org.example.sudoku/.Game (has extras) }
12-05 14:48:15.146: DEBUG/AndroidRuntime(304): Shutting down VM
12-05 14:48:15.146: WARN/dalvikvm(304): threadid=1: thread exiting with uncaught exception (group=0×4001d800)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): FATAL EXCEPTION: main
12-05 14:48:15.295: ERROR/AndroidRuntime(304): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.example.sudoku/org.example.sudoku.Game}: java.lang.NullPointerException
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.os.Looper.loop(Looper.java:123)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at java.lang.reflect.Method.invoke(Method.java:521)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at dalvik.system.NativeStart.main(Native Method)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): Caused by: java.lang.NullPointerException
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.Activity.getLocalClassName(Activity.java:3478)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.Activity.getPreferences(Activity.java:3512)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at org.example.sudoku.Game.<init>(Game.java:104)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at java.lang.Class.newInstanceImpl(Native Method)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at java.lang.Class.newInstance(Class.java:1429)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
12-05 14:48:15.295: ERROR/AndroidRuntime(304): ... 11 more
12-05 14:48:15.376: WARN/ActivityManager(60): Force finishing activity org.example.sudoku/.Game
12-05 14:48:15.455: WARN/ActivityManager(60): Force finishing activity org.example.sudoku/.Sudoku
12-05 14:48:15.927: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{44049308 org.example.sudoku/.Game}
12-05 14:48:27.095: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{43f562c0 org.example.sudoku/.Sudoku}
12-05 14:48:27.202: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{44049308 org.example.sudoku/.Game}
12-05 14:49:20.407: DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol
Any help would be greatly appreciated. Thank you
-James
You need to look at line 104 of Game.java as it seems it may be the cause of a NullPointerException
Your error of interest is:
12-05 14:48:15.295: ERROR/AndroidRuntime(304): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.example.sudoku/org.example.sudoku.Game}: java.lang.NullPointerException
Usual error - your intent is not in the Manifest.xml