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

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!

Related

I can't test the INSTALL_REFERER broadcast receiver

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:)

Google map fragment has trouble inflating

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

Google maps on none google API build target Android

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.

Unclosed Cursor detected

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;
}
}

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