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

  • SEARCH
  • Home
  • 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 8634893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:50:03+00:00 2026-06-12T09:50:03+00:00

I’m a beginner in Android development and am trying to develop a program where

  • 0

I’m a beginner in Android development and am trying to develop a program where the user can convert the text being displayed in the TextView (TextView is displaying a code 39 barcode font text which I’ve imported from assets) to bitmap after pressing the “Convert to Bitmap!” button. I’ve tried searching around google but I’ve only managed to get answers like converting string to bitmap without guides on where to type the codes so I’m rather confuse on that.
I’ve tried running the program with the codes I tried typing out after googling around but it crashes everytime I press the convert button.

Really hope that you can help! Thank you in advance! 😀

The following are my codes so far:-

*Edited with respect to Simon’s code

At java:

public class MainActivity extends Activity 
implements OnClickListener {
    //Called when activity is first created

    TextView tv1;
    ImageView iv;
    Button b;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv1 = (TextView) findViewById(R.id.txtV);  
        tv1.setDrawingCacheEnabled(true); 

        //To change to code 39 barCode font
        Typeface barcodefont = Typeface.createFromAsset(getAssets(),                 
                "fonts/IDAutomationHC39M_FREE.otf");         
        TextView tv = (TextView) findViewById(R.id.txtV);         
        tv.setTypeface(barcodefont);
    }

    public void onClick(View v) {

        tv1.buildDrawingCache(); 
        iv.setImageBitmap(tv1.getDrawingCache()); 
    } 

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Logcat error:

10-04 06:33:25.076: E/AndroidRuntime(1423): FATAL EXCEPTION: main
10-04 06:33:25.076: E/AndroidRuntime(1423): java.lang.IllegalStateException: Could not find a method ConvertText(View) in the activity class com.example.txtvbitmapconverter.MainActivity for onClick handler on view class android.widget.Button with id 'btnConvert'
10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.view.View$1.onClick(View.java:3578)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.view.View.performClick(View.java:4084)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.view.View$PerformClick.run(View.java:16966)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.os.Handler.handleCallback(Handler.java:615)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.os.Looper.loop(Looper.java:137)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at java.lang.reflect.Method.invokeNative(Native Method)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at java.lang.reflect.Method.invoke(Method.java:511)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at dalvik.system.NativeStart.main(Native Method)
10-04 06:33:25.076: E/AndroidRuntime(1423): Caused by: java.lang.NoSuchMethodException: ConvertText [class android.view.View]
10-04 06:33:25.076: E/AndroidRuntime(1423):     at java.lang.Class.getConstructorOrMethod(Class.java:460)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at java.lang.Class.getMethod(Class.java:915)
10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.view.View$1.onClick(View.java:3571)
10-04 06:33:25.076: E/AndroidRuntime(1423):     ... 11 more
  • 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-06-12T09:50:05+00:00Added an answer on June 12, 2026 at 9:50 am

    Try this

    Add to your onCreate()

    tv1.setDrawingCacheEnabled(true);
    

    Then in your onClick()

    tv1.buildDrawingCache();
    iv.setImageBitmap(tv1.getDrawingCache());
    

    http://developer.android.com/reference/android/view/View.html#buildDrawingCache(boolean)

    http://developer.android.com/reference/android/view/View.html#getDrawingCache(boolean)

    [EDIT]

    The problem you now have is that you are trying to enable the drawing cache before tv1 exists.

    You should do this:

    TextView tv1 = (TextView) findViewById(R.id.txtV); 
    tv1.setDrawingCacheEnabled(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group
Does anyone know how can I replace this 2 symbol below from the string

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.