How to generate QR code with Zxing 2.1 library? - android

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.

Related

Unable to start activity NullPointerException-onActivityCreated

My App crash rarely
i want to get off this bug for ever.
this is the log that users Report
i tried so long on this but nothing helps
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.xxx.xxx.Master_}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.access$600(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.xxx.xxx.HomeFragment.onActivityCreated(HomeFragment.java:140)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1508)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:566)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
at android.app.Activity.performStart(Activity.java:5018)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)
... 11 more

Image Gallery on Android 3

I run this program it is show normally but when I click this image or scroll this image it is crashed.Please Help me!
My code Here: enter link description here
My Error:
05-18 14:18:56.064: E/AndroidRuntime(1375): FATAL EXCEPTION: main
05-18 14:18:56.064: E/AndroidRuntime(1375): java.lang.OutOfMemoryError
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.content.res.Resources.loadDrawable(Resources.java:1965)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.content.res.Resources.getDrawable(Resources.java:660)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.widget.ImageView.resolveUri(ImageView.java:616)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.widget.ImageView.setImageResource(ImageView.java:349)
05-18 14:18:56.064: E/AndroidRuntime(1375): at com.example.gallerycookbook.GalleryImageAdapter.getView(GalleryImageAdapter.java:47)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.widget.Gallery.makeAndAddView(Gallery.java:865)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:819)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.widget.Gallery.fillToGalleryRight(Gallery.java:763)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.widget.Gallery.trackMotionScroll(Gallery.java:393)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.widget.Gallery.onScroll(Gallery.java:1043)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:572)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.widget.Gallery.onTouchEvent(Gallery.java:958)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.View.dispatchTouchEvent(View.java:7246)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-18 14:18:56.064: E/AndroidRuntime(1375): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
05-18 14:18:56.064: E/AndroidRuntime(1375): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
05-18 14:18:56.064: E/AndroidRuntime(1375): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.View.dispatchPointerEvent(View.java:7426)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
05-18 14:18:56.064: E/AndroidRuntime(1375): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
This line shows the problem :
05-18 14:18:56.064: E/AndroidRuntime(1375): FATAL EXCEPTION: main
05-18 14:18:56.064: E/AndroidRuntime(1375): java.lang.OutOfMemoryError
from oracle doc :
Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector. OutOfMemoryError objects may be constructed by the virtual machine as if suppression were disabled and/or the stack trace was not writable.
use this code to down scale your picture :
private Bitmap downscaleBitmapUsingDensities(final int sampleSize,final int imageResId)
{
final Options bitmapOptions=new Options();
bitmapOptions.inDensity=sampleSize;
bitmapOptions.inTargetDensity=1;
final Bitmap scaledBitmap=BitmapFactory.decodeResource(getResources(),imageResId,bitmapOptions);
scaledBitmap.setDensity(Bitmap.DENSITY_NONE);
return scaledBitmap;
}
You ran out of memory. This is usually when you try to show many images in one view. You should use bitmaps efficiently. One way to do it would be to use library like Universal Image loader which uses lazyloading. See here for more details.
You are trying to open image that fill whole memory that android gave to process. To avoid it you have to down sample image before show it. I suggest to use very cool library - Android Query.

Connection for httppost : NetworkOnMainThreadException [duplicate]

This question already has answers here:
How can I fix 'android.os.NetworkOnMainThreadException'?
(66 answers)
Closed 9 years ago.
I'm trying to upload a png file to a server. What is the problem?
I think there is a problem about connection but address is correct. It is a php URL. So, what is the problem? It does not upload image.
ByteArrayOutputStream stream = new ByteArrayOutputStream();
BMUpload.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte [] byte_arr = stream.toByteArray();
String image_str = Base64.encodeBytes(byte_arr);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",image_str));
nameValuePairs.add(new BasicNameValuePair( "id", String.valueOf(((App)Global).m_iUserID) ));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(adrupload);
try
{
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
}catch(Exception e)
{
e.printStackTrace();
return;
}
error log:
01-05 01:50:11.591: W/System.err(11415): android.os.NetworkOnMainThreadException
01-05 01:50:11.596: W/System.err(11415): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1144)
01-05 01:50:11.596: W/System.err(11415): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
01-05 01:50:11.596: W/System.err(11415): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
01-05 01:50:11.596: W/System.err(11415): at java.net.InetAddress.getAllByName(InetAddress.java:214)
01-05 01:50:11.596: W/System.err(11415): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
01-05 01:50:11.596: W/System.err(11415): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-05 01:50:11.596: W/System.err(11415): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-05 01:50:11.596: W/System.err(11415): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-05 01:50:11.596: W/System.err(11415): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-05 01:50:11.596: W/System.err(11415): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-05 01:50:11.596: W/System.err(11415): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-05 01:50:11.596: W/System.err(11415): at com.todogram.Settings.UpdateAvatar(Settings.java:351)
01-05 01:50:11.596: W/System.err(11415): at com.todogram.Settings.onActivityResult(Settings.java:139)
01-05 01:50:11.596: W/System.err(11415): at android.app.Activity.dispatchActivityResult(Activity.java:5563)
01-05 01:50:11.596: W/System.err(11415): at android.app.ActivityThread.deliverResults(ActivityThread.java:3496)
01-05 01:50:11.596: W/System.err(11415): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3543)
01-05 01:50:11.596: W/System.err(11415): at android.app.ActivityThread.access$1200(ActivityThread.java:159)
01-05 01:50:11.596: W/System.err(11415): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
01-05 01:50:11.596: W/System.err(11415): at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 01:50:11.596: W/System.err(11415): at android.os.Looper.loop(Looper.java:137)
01-05 01:50:11.596: W/System.err(11415): at android.app.ActivityThread.main(ActivityThread.java:5419)
01-05 01:50:11.596: W/System.err(11415): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 01:50:11.596: W/System.err(11415): at java.lang.reflect.Method.invoke(Method.java:525)
01-05 01:50:11.596: W/System.err(11415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
01-05 01:50:11.596: W/System.err(11415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
01-05 01:50:11.601: W/System.err(11415): at dalvik.system.NativeStart.main(Native Method)
Android OS prevents any application from using Network related processes (e.g. loading a site, sending or receiving data from a server, etc) to be executed in the main thread. The logic behind this is that network processes tend to be slow (more so if you have slow connection) and placing a process like this on the main thread will greatly slow the program down - and a slow program is a program with bad user experience.
You have to put it in a thread and use that thread in your onCreate() function or in a button pressed function.
This link should get you started with threads and file upload.

android arduino usb communication

I'm trying to establish communication between Arduino UNO R3 and Galaxy SII on Android 4.1 cross usb. The code sample i am following i here: http://androidgurusolutions.blogspot.com/2012/07/arduino-adk-board-blink-led-with-your.html . Unfortunately, i am getting this message 'app has stopped' and here is LogCat error
LogCat:
E/AndroidRuntime(535): FATAL EXCEPTION: main
E/AndroidRuntime(535): java.lang.NoClassDefFoundError: com.android.future.usb.UsbManager
E/AndroidRuntime(535): at com.example.mypro.MainActivity.onCreate(MainActivity.java:123)
E/AndroidRuntime(535): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(535): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
E/AndroidRuntime(535): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime(535):at android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime(535):at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime(535):at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(535):at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(535):at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(535):at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(535):at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(535):at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(535):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(535):at dalvik.system.NativeStart.main(Native Method)
please can anybody help me. thanks in advance.....

Weird Android Maps Extensions Run Time Issues

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

Categories

Resources