Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to resolve the canvas error in QR Code generation
    text
    copied!<p>I am trying to execute the QR Code tutorial according to this website <a href="http://www.onbarcode.com/products/android_barcode/barcodes/qrcode.html" rel="nofollow">http://www.onbarcode.com/products/android_barcode/barcodes/qrcode.html</a>, where only one error shoots up "canvas cannot be resolved to a variable</p> <p>Here is the Java code</p> <pre><code> package com.qrcode; import com.onbarcode.barcode.android.AndroidColor; import com.onbarcode.barcode.android.IBarcode; import com.onbarcode.barcode.android.QRCode; import android.app.Activity; import android.graphics.Canvas; import android.graphics.RectF; import android.os.Bundle; public class QrcodeActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); QRCode barcode = new QRCode(); /* QRCode Valid data char set: numeric data (digits 0 - 9); alphanumeric data (digits 0 - 9; upper case letters A -Z; nine other characters: space, $ % * + - . / : ); byte data (default: ISO/IEC 8859-1); Kanji characters */ barcode.setData("http://www.onbarcode.com"); barcode.setDataMode(QRCode.M_AUTO); barcode.setVersion(10); barcode.setEcl(QRCode.ECL_M); // if you want to encode GS1 compatible QR Code, you need set FNC1 mode to IBarcode.FNC1_ENABLE barcode.setFnc1Mode(IBarcode.FNC1_NONE); // Set the processTilde property to true, if you want use the tilde character "~" to // specify special characters in the input data. Default is false. // 1-byte character: ~ddd (character value from 0 ~ 255) // ASCII (with EXT): from ~000 to ~255 // 2-byte character: ~6ddddd (character value from 0 ~ 65535) // Unicode: from ~600000 to ~665535 // ECI: from ~7000000 to ~7999999 // SJIS: from ~9ddddd (Shift JIS 0x8140 ~ 0x9FFC and 0xE040 ~ 0xEBBF) barcode.setProcessTilde(false); // unit of measure for X, Y, LeftMargin, RightMargin, TopMargin, BottomMargin barcode.setUom(IBarcode.UOM_PIXEL); // barcode module width in pixel barcode.setX(3f); barcode.setLeftMargin(15f); barcode.setRightMargin(15f); barcode.setTopMargin(15f); barcode.setBottomMargin(15f); // barcode image resolution in dpi barcode.setResolution(72); // barcode bar color and background color in Android device barcode.setForeColor(AndroidColor.black); barcode.setBackColor(AndroidColor.white); /* specify your barcode drawing area */ RectF bounds = new RectF(30, 30, 0, 0); ************************ERROR Shoots up in the below line stating "canvas cannot be resolved into a variable*************** barcode.drawBarcode(canvas, bounds); } } </code></pre> <p>Here is my main.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; </code></pre> <p>Am a naive in qr generation, so please help me with the rest of the code friends</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload