Weird Android Maps Extensions Run Time Issues - android

I downloaded a library called Android Maps Extensions from Github.
I can run the demo of this library in debugging mode, on my Samsung Note (GT-N7000) which runs Android 4.0.4.
If I click a button inside app, the app will stop and the screen will become black and after several seconds, and a dialog appears saying:
Unfortunately, Android Maps Extensions has stopped.
I am not sure what is happening. The logcat output can be seen below:
01-05 01:09:17.118: I/Process(24896): Sending signal. PID: 24896 SIG: 9
01-05 01:26:43.328: D/CLIPBOARD(27226): Hide Clipboard dialog at Starting input: finished by someone else... !
01-05 01:27:09.043: D/dalvikvm(27226): GC_CONCURRENT freed 56K, 2% free 14452K/14663K, paused 2ms+3ms
01-05 01:27:09.053: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.053: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.053: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.053: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.058: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.058: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.058: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.058: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.063: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.063: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.078: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.078: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.078: D/AndroidRuntime(27226): Shutting down VM
01-05 01:27:09.078: W/dalvikvm(27226): threadid=1: thread exiting with uncaught exception (group=0x40c4f1f8)
01-05 01:27:09.083: E/AndroidRuntime(27226): FATAL EXCEPTION: main
01-05 01:27:09.083: E/AndroidRuntime(27226): java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.mg6.android.maps.extensions.demo/pl.mg6.android.maps.extensions.demo.DemoActivity}: java.lang.NullPointerException
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.os.Looper.loop(Looper.java:137)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.main(ActivityThread.java:4511)
01-05 01:27:09.083: E/AndroidRuntime(27226): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 01:27:09.083: E/AndroidRuntime(27226): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 01:27:09.083: E/AndroidRuntime(27226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-05 01:27:09.083: E/AndroidRuntime(27226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-05 01:27:09.083: E/AndroidRuntime(27226): at dalvik.system.NativeStart.main(Native Method)
01-05 01:27:09.083: E/AndroidRuntime(27226): Caused by: java.lang.NullPointerException
01-05 01:27:09.083: E/AndroidRuntime(27226): at pl.mg6.android.maps.extensions.demo.DemoActivity.addCircles(DemoActivity.java:220)
01-05 01:27:09.083: E/AndroidRuntime(27226): at pl.mg6.android.maps.extensions.demo.DemoActivity.onCreate(DemoActivity.java:84)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.Activity.performCreate(Activity.java:4470)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-05 01:27:09.083: E/AndroidRuntime(27226): ... 11 more

Related

need assistance with log cat error

I have made made 2 xml files that have identical widgets. First file (main) the widgets are arranged in a Relative layout and the second (testgrid2) the widgets are in a TableLayout. The first xml file works fine and app runs. The second xml file I created so I can test before I replace it with the original (main). when I test the second (testgrids)it crashes but I cannot understand the log cat errors it is generating.
The only changes I make to test is in the set Content view.
setContentView(R.layout.main);
and testing
setContentView(R.layout.testgrid2);
Logcat
01-05 13:14:38.790: D/dalvikvm(8152): GC_FOR_ALLOC freed 63K, 1% free 8906K/8992K, paused 16ms, total 16ms
01-05 13:14:38.790: I/dalvikvm-heap(8152): Grow heap (frag case) to 9.428MB for 746512-byte allocation
01-05 13:14:38.810: D/dalvikvm(8152): GC_FOR_ALLOC freed <1K, 1% free 9635K/9724K, paused 15ms, total 15ms
01-05 13:14:38.830: D/dalvikvm(8152): GC_FOR_ALLOC freed <1K, 1% free 9635K/9724K, paused 11ms, total 11ms
01-05 13:14:38.840: I/dalvikvm-heap(8152): Grow heap (frag case) to 12.276MB for 2986000-byte allocation
01-05 13:14:38.850: D/dalvikvm(8152): GC_FOR_ALLOC freed 0K, 1% free 12551K/12644K, paused 11ms, total 11ms
01-05 13:14:38.931: D/TAG(8152): Size Pre 600
01-05 13:14:38.941: D/TAG(8152): File SET 600
01-05 13:14:38.941: D/TAG(8152): BT true
01-05 13:14:38.941: D/TAG(8152): CON true
01-05 13:14:38.941: W/BluetoothAdapter(8152): getBluetoothService() called with no BluetoothManagerCallback
01-05 13:14:38.941: D/BluetoothSocket(8152): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[41]}
01-05 13:14:39.411: D/AndroidRuntime(8152): Shutting down VM
01-05 13:14:39.411: W/dalvikvm(8152): threadid=1: thread exiting with uncaught exception (group=0x4159a700)
01-05 13:14:39.421: E/AndroidRuntime(8152): FATAL EXCEPTION: main
01-05 13:14:39.421: E/AndroidRuntime(8152): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.simplergb/com.example.simplergb.SimpleRGB_Main}: java.lang.NullPointerException
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.os.Looper.loop(Looper.java:137)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-05 13:14:39.421: E/AndroidRuntime(8152): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 13:14:39.421: E/AndroidRuntime(8152): at java.lang.reflect.Method.invoke(Method.java:525)
01-05 13:14:39.421: E/AndroidRuntime(8152): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-05 13:14:39.421: E/AndroidRuntime(8152): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-05 13:14:39.421: E/AndroidRuntime(8152): at dalvik.system.NativeStart.main(Native Method)
01-05 13:14:39.421: E/AndroidRuntime(8152): Caused by: java.lang.NullPointerException
01-05 13:14:39.421: E/AndroidRuntime(8152): at com.example.simplergb.SimpleRGB_Main.onCreate(SimpleRGB_Main.java:1429)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.app.Activity.performCreate(Activity.java:5133)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-05 13:14:39.421: E/AndroidRuntime(8152): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-05 13:14:39.421: E/AndroidRuntime(8152): ... 11 more
Here:
Caused by: java.lang.NullPointerException
at com.example.simplergb.SimpleRGB_Main.onCreate(SimpleRGB_Main.java:1429)
So fix your NPE in SimpleRGB_Main.java line 1429

How to generate QR code with Zxing 2.1 library?

The problem:
Well, I´ve seen many examples how to do it, but in this library (Zxing 2.1) none seems to work. I want to encode a string into a QRCode and get the bitmap to show in a Imageview.
Question:
Should I use the older version? Anyone have a working sample with Zxing library 2.1?
What I´ve tried:
String contents = uniqueID;
BarcodeFormat barcodeFormat = BarcodeFormat.QR_CODE;
int width = 300;
int height = 300;
MultiFormatWriter barcodeWriter = new MultiFormatWriter();
try {
BitMatrix matrix = barcodeWriter.encode(contents, barcodeFormat, width, height);
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
And got this:
01-05 13:02:10.701: E/AndroidRuntime(1375): FATAL EXCEPTION: main
01-05 13:02:10.701: E/AndroidRuntime(1375): java.lang.NoClassDefFoundError: com.google.zxing.BarcodeFormat
01-05 13:02:10.701: E/AndroidRuntime(1375): at br.com.example.nightid.slidingsubmenu.IDcard.onCreate(IDcard.java:75)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.Activity.performCreate(Activity.java:4465)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.os.Looper.loop(Looper.java:137)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-05 13:02:10.701: E/AndroidRuntime(1375): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 13:02:10.701: E/AndroidRuntime(1375): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 13:02:10.701: E/AndroidRuntime(1375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-05 13:02:10.701: E/AndroidRuntime(1375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-05 13:02:10.701: E/AndroidRuntime(1375): at dalvik.system.NativeStart.main(Native Method)
And sorry If I'm doing a big mistake, first time using this library.
It says it right there. You didn't actually build these classes into your app. Nothing to do with the library.

When i run my android UIAutomator code, it shows error

When I run my android UIAutomator code, it shows following error.
INSTRUMENTATION_RESULT: shortMsg=java.lang.RuntimeException
INSTRUMENTATION_RESULT: longMsg=com.android.ui.testing
INSTRUMENTATION_CODE: 0
I just ran the sample code given in developer.android.com
How to solve this error?
Log attached below:
01-05 01:07:53.559: D/AndroidRuntime(5712): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-05 01:07:53.559: D/AndroidRuntime(5712): CheckJNI is ON
01-05 01:07:53.559: E/AndroidRuntime(5712): cannot open customer xml file
01-05 01:07:53.559: E/AndroidRuntime(5712): /system/csc/customer.xml can't open file
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: start
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: already setted!!
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: end
01-05 01:07:53.589: D/dalvikvm(5712): Trying to load lib libjavacore.so 0x0
01-05 01:07:53.599: D/dalvikvm(5712): Added shared lib libjavacore.so 0x0
01-05 01:07:53.609: D/dalvikvm(5712): Trying to load lib libnativehelper.so 0x0
01-05 01:07:53.609: D/dalvikvm(5712): Added shared lib libnativehelper.so 0x0
01-05 01:07:53.664: I/dalvikvm(5712): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
01-05 01:07:53.874: D/dalvikvm(5712): Note: class Landroid/app/ActivityManagerNative; has 152 unimplemented (abstract) methods
01-05 01:07:53.924: D/AndroidRuntime(5712): Calling main entry com.android.commands.uiautomator.Launcher
01-05 01:07:53.934: D/AndroidRuntime(5712): Shutting down VM
01-05 01:07:53.934: W/dalvikvm(5712): threadid=1: thread exiting with uncaught exception (group=0x40ffa2a0)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): uncaught exception
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): java.lang.RuntimeException: com.uia.example.my.LaunchSettings
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:95)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:82)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:237)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at dalvik.system.NativeStart.main(Native Method)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): Caused by: java.lang.ClassNotFoundException: com.uia.example.my.LaunchSettings
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:83)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:71)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.TestCaseCollector.addTestClasses(TestCaseCollector.java:52)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:92)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): ... 6 more
01-05 01:07:53.944: I/AndroidRuntime(5712): VM exiting with result code -1.
If you get a ClassNotFindException while running your uiautomator tests :
Some of us my get this error because their ROM puts the folder /data/dalvik-cache in read-only mode. That happened to me with Cyanogen for a S3.
In that case type, in bash :
adb shell
su
chmod 777 /data/dalvik-cache
exit
rerun your tests and that should work. As dalvik-cache is locked for apps, uiautomator can't ask dalvik to unzip the jar of your tests and dalvik won't find the its classes.
See if removing the #UiThreadTest annotation or removing the runOnUiThread() call or re-factoring your tests work. But without a logcat, difficult to understand where it's coming from.
Had the same problem. Most demos I've seen indicate to install the jar to /data/local/tmp/. I've seen others indicate to try and install it to your sd card (/storage/sdcard0). After doing that it worked. Seems to be a problem with read permissions.
I solved this error by using"ant build" to create my jar.If u use export in eclipse to create a jar file, there might be some errors in the resulting class file, hence the above class not found error.

Dialog with Button and onClick Listener throws exception

I coded a Dialog that shows up with 2 textviews and 2 buttons.
I googled for that Problem as well but I didn't find anything that mathced my issue.
Here is some Code:
case R.id.open:
openDialog=new Dialog(this);
openDialog.setContentView(R.layout.open_dialog);
openDialog.setTitle(head);
openDialog.setCancelable(true);
Button open_cancel=(Button)findViewById(R.id.open_cancel);
open_cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
openDialog.cancel();
}
});
but I can't show the dialog up with the buttons.
If I call it without these Lines there is no Problem:
Button open_cancel=(Button)findViewById(R.id.open_cancel);
open_cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
openDialog.cancel();
}
});
This is the XML File:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/open_dialog"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<EditText android:id="#+id/open_head"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="ojfpojew ojr pojr"
/>
<EditText android:id="#+id/open_note"
android:layout_width="fill_parent"
android:text="oijpojepojpotjpotejpe ojtpojtpo ewpoj tpojt pp jpojtpoj etpoj poj poj t"
android:layout_height="150dp"
/>
<Button android:id="#+id/open_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="edit"
/>
<Button android:id="#+id/open_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="cancel"
/>
</LinearLayout>
I really do not understand why this not works...
here is the error log, if it helps:
01-05 16:43:51.004: D/dalvikvm(2336): GC freed 1010 objects / 70136 bytes in 75ms
01-05 16:43:51.204: D/dalvikvm(2336): GC freed 91 objects / 3664 bytes in 53ms
01-05 16:43:51.494: D/dalvikvm(2336): GC freed 132 objects / 6240 bytes in 62ms
01-05 16:43:51.674: D/dalvikvm(2336): GC freed 58 objects / 2312 bytes in 56ms
01-05 16:43:51.944: D/dalvikvm(2336): GC freed 147 objects / 9128 bytes in 63ms
01-05 16:43:52.383: D/ViewFlipper(2336): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
01-05 16:44:00.973: D/dalvikvm(2336): GC freed 25495 objects / 1393728 bytes in 88ms
01-05 16:44:02.644: D/dalvikvm(2336): GC freed 45722 objects / 2044568 bytes in 102ms
01-05 16:44:04.424: I/Resources(2336): Loaded time zone names for en in 1591ms.
01-05 16:44:06.834: D/dalvikvm(2336): GC freed 36788 objects / 1674624 bytes in 102ms
01-05 16:44:11.243: D/AndroidRuntime(2336): Shutting down VM
01-05 16:44:11.263: W/dalvikvm(2336): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-05 16:44:11.263: E/AndroidRuntime(2336): Uncaught handler: thread main exiting due to uncaught exception
01-05 16:44:11.273: E/AndroidRuntime(2336): java.lang.NullPointerException
01-05 16:44:11.273: E/AndroidRuntime(2336): at producteev.push.Producteev_pushActivity.onContextItemSelected(Producteev_pushActivity.java:247)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.app.Activity.onMenuItemSelected(Activity.java:2174)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2731)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:129)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:884)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.widget.ListView.performItemClick(ListView.java)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.os.Handler.handleCallback(Handler.java:587)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.os.Handler.dispatchMessage(Handler.java:92)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.os.Looper.loop(Looper.java:123)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-05 16:44:11.273: E/AndroidRuntime(2336): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 16:44:11.273: E/AndroidRuntime(2336): at java.lang.reflect.Method.invoke(Method.java:521)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-05 16:44:11.273: E/AndroidRuntime(2336): at dalvik.system.NativeStart.main(Native Method)
01-05 16:44:11.293: I/dalvikvm(2336): threadid=7: reacting to signal 3
01-05 16:44:11.323: I/dalvikvm(2336): Wrote stack trace to '/data/anr/traces.txt'
01-05 16:44:13.383: I/Process(2336): Sending signal. PID: 2336 SIG: 9
Try this,
Button open_cancel=(Button)openDialog.findViewById(R.id.open_cancel);

using a button to switch between tabs

Does anyone know how to create a button which will help me to switch between tabs?
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {{
// Perform action on click
if (v.getId() == R.id.button1) {
setContentView(R.layout.tab3);
}
else if (v.getId() == R.id.button1) {
setContentView(R.layout.main);
}
}
}
});
}}
this is the code in my tab 1, this next code is the button in my tab.xml. i want to press the buy button below and i want it to go to another tab, is this possible?
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageButton1"
android:text="Buy"
android:onClick="tab3" />
this is my logcat file
01-05 16:04:20.903: D/dalvikvm(215): GC freed 806 objects / 70928 bytes in 96ms
01-05 15:30:29.072: D/AndroidRuntime(213): Shutting down VM
01-05 15:30:29.082: W/dalvikvm(213): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-05 15:30:29.082: E/AndroidRuntime(213): Uncaught handler: thread main exiting due to uncaught exception
01-05 15:30:29.132: E/AndroidRuntime(213): java.lang.IllegalStateException: Could not find a method tab3(View) in the activity
01-05 15:30:29.132: E/AndroidRuntime(213): at android.view.View$1.onClick(View.java:2020)
01-05 15:30:29.132: E/AndroidRuntime(213): at android.view.View.performClick(View.java:2364)
01-05 15:30:29.132: E/AndroidRuntime(213): at android.view.View.onTouchEvent(View.java:4179)
01-05 15:30:29.132: E/AndroidRuntime(213): at android.widget.TextView.onTouchEvent(TextView.java:6541)
01-05 15:30:29.132: E/AndroidRuntime(213): at android.view.View.dispatchTouchEvent(View.java:3709)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.os.Looper.loop(Looper.java:123)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-05 16:04:25.693: E/AndroidRuntime(215): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 16:04:25.693: E/AndroidRuntime(215): at java.lang.reflect.Method.invoke(Method.java:521)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-05 16:04:25.693: E/AndroidRuntime(215): at dalvik.system.NativeStart.main(Native Method)
01-05 16:04:25.693: E/AndroidRuntime(215): Caused by: java.lang.NoSuchMethodException: Tab3
01-05 16:04:25.693: E/AndroidRuntime(215): at java.lang.ClassCache.findMethodByName(ClassCache.java:308)
01-05 16:04:25.693: E/AndroidRuntime(215): at java.lang.Class.getMethod(Class.java:1014)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.View$1.onClick(View.java:2017)
01-05 16:04:25.693: E/AndroidRuntime(215): ... 25 more
01-05 16:04:25.733: I/dalvikvm(215): threadid=7: reacting to signal 3
01-05 16:04:25.733: I/dalvikvm(215): Wrote stack trace to '/data/anr/traces.txt'
01-05 16:04:27.505: I/Process(215): Sending signal. PID: 215 SIG: 9
+1 Midoalageb and +1 Mark Gjol have given you exactly what you need to switch the tab. What they are leaving out is the code for the event you are trying to do. What you need to do is set up a button on TAB1 that will have an onClick() listener that will call either getTabHost().setCurrentTabByTag(TAB2); or getTabHost().setCurrentTab(1);. Either one of those will work fine, just depends on how you want to do it.
Do you know how to do buttons and onClick() listeners? If not, google has some great examples. Just create a button in your tabView then set the onClick and then put your code in there for switching to the tab you want.
Another post that is very similar to this one that may help you out.
getTabHost().setCurrentTabByTag(TAB2);
This will look for the tab labeled "TAB2" and change to that tab.
getTabHost().setCurrentTab(1);
This will look for the tab with the index of "1" and change to that tab.
In regards to your xml
The xml files are mainly used to abstract defining your Views from the implementation of your Views. This allows you or other developers to provide different views to your code if needed. It helps provide a way to use the MVC pattern. However, this pattern is a little different in Android, but the xml file is most commonly considered the View in that pattern.
So Yes, if you are going to have multiple buttons they will need to be defined in your xml and implemented in your code.
In regards to your button dilema
The API for Button from google actually provides you with an example of this on the very front page. Keep in mind that Android is maturing very fast as a development platform and A LOT of this stuff is actually well documented already on line. The API documentation is also very good and gives great examples. Go by there and read it and you will most likely solve a lot of the more easy problems there.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is Tab1");
setContentView(textview);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
// perform the switch to tab event here for instance...
getTabHost().setCurrentTabByTag("TAB2");
}
});
}
When you create your tabs you give them a tag, let's store one such tag in the variable TAB_1. So in your onClick() method, you select that tab by:
getTabHost().setCurrentTabByTag(TAB_1);
Or, as midoalageb wrote, by index:
getTabHost().setCurrentTab(index);
Here is an explanation of Tab example :
Create a master Activity:
public class HelloTabWidget extends TabActivity
And create an Activity for each Tab:
public class ArtistsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Artists tab");
setContentView(textview); // you replace this with your layout for each view
}
}
In the master Activity (HelloTabWidget), initiate a TabHost:
TabHost tabHost = getTabHost();
And add TabSpecs for each Tab you have:
intent = new Intent().setClass(this, ArtistsActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
Select which Tab you need to be the default one:
tabHost.setCurrentTab(int index);
And finally your Button's onClickListener should be set in the Activity of the Tab containing the Button to:
intent = new Intent().setClass(this, ArtistsActivity.class);
startActivity(intent);
This Button should be present in all Tabs if you want it to switch between them.

Categories

Resources