为什么我得到这些错误,java truetype错误?

时间:2013-10-16 14:13:34

标签: java android eclipse error-handling barcode

为什么eclipse不允许我编译它。 我希望自己点击按钮,然后Edittext数据转到Textview。然后从那里我想通过按另一个textViewButton转换为条形码,所以我有2 Buttons和2 textViews和1 {{1}完全

请告诉我该怎么做或我错在哪里

editTexts

ADTIONAL INFO。 我已编译但现在我得到错误,这里是logcat:

public class cc extends Activity {

EditText inputc;
TextView outputc;
TextView tv1;
ImageView iv;
Button b;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cc);

inputc = (EditText) findViewById(R.id.ccinput);
outputc = (TextView) findViewById(R.id.outputc);
Button send = (Button) findViewById(R.id.button);
final TextView tv1 = (TextView) findViewById(R.id.outputc);  
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.outputc);         
tv.setTypeface(barcodefont);

send.setOnClickListener (new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        tv1.buildDrawingCache(); 
        iv.setImageBitmap(tv1.getDrawingCache()); 
        outputc.setText((inputc.getText()));
    }
});

}
}

3 个答案:

答案 0 :(得分:2)

logcat中的错误指向此行:

Typeface barcodefont = Typeface.createFromAsset(getAssets(), "fonts/IDAutomationHC39M_FREE.otf");

确保fonts/IDAutomationHC39M_FREE.otf存在,它没有损坏,并且名称大小写完全匹配。

或者,如果以上操作不起作用,请尝试此处的建议:Custom fonts in android

答案 1 :(得分:1)

您的ImageView iv未初始化。你会得到NullPointerException。初始化iv

 iv = (ImageView) findViewById(R.id.yourimageviewid);

这是错误之一。正如@NickT所指出的那样,这将是一个运行时错误。

你有textview outputc和tv1都用相同的id R.id.outputc

初始化
  outputc = (TextView) findViewById(R.id.outputc); 
  final TextView tv1 = (TextView) findViewById(R.id.outputc);  

你有

 TextView tv = (TextView) findViewById(outputc); 
 // remove this line  or use R.id.yourtextviewid
 // outputc is a textview 

确保{/ 1}}位于/ assests / fonts下。

答案 2 :(得分:1)

这里有一些问题:

您已宣布TextView tv1;,因此您无需再次final TextView tv1 = (TextView) findViewById(R.id.outputc);

你还提到:

  

所以我有2个按钮和2个textViews和1个editTexts altogther

public class cc扩展了Activity {

EditText inputc;
TextView outputc;
TextView tv1;
ImageView iv;
Button b;
Button send;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cc);

    inputc = (EditText) findViewById(R.id.ccinput);
    outputc = (TextView) findViewById(R.id.outputc);
    send = (Button) findViewById(R.id.button);
    tv1 = (TextView) findViewById(R.id.outputc);
    tv1.setDrawingCacheEnabled(true);

    //To change to code 39 barCode font
    Typeface barcodefont = Typeface.createFromAsset(getAssets(), 
                "fonts/IDAutomationHC39M_FREE.otf");


    outputc.setTypeface(barcodefont);

    send.setOnClickListener (new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            tv1.buildDrawingCache();
            iv.setImageBitmap(tv1.getDrawingCache());
            outputc.setText((inputc.getText()));
        }
    });
}
}