Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:37:23+00:00 2026-05-31T02:37:23+00:00

I am trying to execute the QR Code tutorial according to this website http://www.onbarcode.com/products/android_barcode/barcodes/qrcode.html

  • 0

I am trying to execute the QR Code tutorial according to this website http://www.onbarcode.com/products/android_barcode/barcodes/qrcode.html, where only one error shoots up “canvas cannot be resolved to a variable

Here is the Java 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);

}

    }

Here is my main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >


    </LinearLayout>

Am a naive in qr generation, so please help me with the rest of the code friends

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:37:25+00:00Added an answer on May 31, 2026 at 2:37 am

    You should write all of the code above, in onDraw method of a custom view in android. create a class that extends android.view.View class, and then write your code in it. this method will give you a variable that is the canvas you want. see the code below:

    public class Test extends View {
    
    public Test(Context context) {
        super(context);
    }
    
    @Override
    protected void onDraw(Canvas canvas) {
        //write your code here!
    }
    

    after creating this class, put this view in your activity xml file like this:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
                <somepackage.somepackage.someview 
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                </somepackage.somepackage.someview>
    </LinearLayout>
    

    note: replace the somepackage.somepackage with package of your recently created view class, and replace someview with you custom view class name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the signalR chat app (as laid out in this tutorial http://sergiotapia.com/2011/09/signalr-with-mvc3-chat-app-build-asynchronous-real-time-persistant-connection-websites/
I am trying to execute this code: for i in Fil: for k in
I am trying to execute this code in C#.NET to turn an SQL table
Im trying to execute this code on a mac. I have installed the curl.
I'm trying to execute this code (this is a minimal sample in order to
When I am trying to execute following code to email the contact form details,
I'm trying to execute a long-running piece of code in a background thread and
I am trying to emulate a web browser in order to execute JavaScript code
I'm trying the following code to execute a search and it's not working. On
I am trying to execute this SQL query prior to restoring a .BAK file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.