Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么会出现这些错误,java truetype错误?_Java_Android_Eclipse_Error Handling_Barcode - Fatal编程技术网

为什么会出现这些错误,java truetype错误?

为什么会出现这些错误,java truetype错误?,java,android,eclipse,error-handling,barcode,Java,Android,Eclipse,Error Handling,Barcode,为什么eclipse不让我编译这个。 我想自己点击一个按钮,然后编辑文本数据进入文本视图。然后,我希望通过按下另一个按钮将文本视图转换为条形码,因此我总共有2个按钮和2个文本视图和1个编辑文本 请告诉我怎么做或者我错在哪里 public class cc extends Activity { EditText inputc; TextView outputc; TextView tv1; ImageView iv; Button b; protected void onCreate(Bund

为什么eclipse不让我编译这个。 我想自己点击一个按钮,然后
编辑文本
数据进入
文本视图
。然后,我希望通过按下另一个
按钮将
文本视图
转换为条形码,因此我总共有2个
按钮
和2个
文本视图
和1个
编辑文本

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

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()));
    }
});

}
}
附加信息。 我已经编译了,但是现在我得到了错误,这里是logcat:

10-16 15:41:11.095: E/AndroidRuntime(5822): FATAL EXCEPTION: main
10-16 15:41:11.095: E/AndroidRuntime(5822): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.barcodedisplayer/com.example.barcodedisplayer.cc}: java.lang.RuntimeException: native typeface cannot be made
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.app.ActivityThread.access$600(ActivityThread.java:156)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.os.Looper.loop(Looper.java:137)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.app.ActivityThread.main(ActivityThread.java:5303)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at java.lang.reflect.Method.invokeNative(Native Method)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at java.lang.reflect.Method.invoke(Method.java:525)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at dalvik.system.NativeStart.main(Native Method)
10-16 15:41:11.095: E/AndroidRuntime(5822): Caused by: java.lang.RuntimeException: native typeface cannot be made
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.graphics.Typeface.<init>(Typeface.java:175)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.graphics.Typeface.createFromAsset(Typeface.java:149)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at com.example.barcodedisplayer.cc.onCreate(cc.java:32)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.app.Activity.performCreate(Activity.java:5207)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-16 15:41:11.095: E/AndroidRuntime(5822):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
10-16 15:41:11.095: E/AndroidRuntime(5822):     ... 11 more
10-16 15:41:11.095:E/AndroidRuntime(5822):致命异常:主
10-16 15:41:11.095:E/AndroidRuntime(5822):java.lang.RuntimeException:无法启动活动组件信息{com.example.barcodedisplayer/com.example.barcodedisplayer.cc}:java.lang.RuntimeException:无法生成本机字体
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.app.ActivityThread.access$600(ActivityThread.java:156)
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.os.Handler.dispatchMessage(Handler.java:99)上
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.os.Looper.loop(Looper.java:137)
10-16 15:41:11.095:E/AndroidRuntime(5822):位于android.app.ActivityThread.main(ActivityThread.java:5303)
10-16 15:41:11.095:E/AndroidRuntime(5822):位于java.lang.reflect.Method.Invokenactive(本机方法)
10-16 15:41:11.095:E/AndroidRuntime(5822):在java.lang.reflect.Method.invoke(Method.java:525)
10-16 15:41:11.095:E/AndroidRuntime(5822):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
10-16 15:41:11.095:E/AndroidRuntime(5822):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
10-16 15:41:11.095:E/AndroidRuntime(5822):在dalvik.system.NativeStart.main(本机方法)
10-16 15:41:11.095:E/AndroidRuntime(5822):原因:java.lang.RuntimeException:无法生成本机字体
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.graphics.Typeface.(Typeface.java:175)
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.graphics.Typeface.createFromAsset(Typeface.java:149)上
10-16 15:41:11.095:E/AndroidRuntime(5822):在com.example.barcodediplayer.cc.onCreate(cc.java:32)
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.app.Activity.performCreate(Activity.java:5207)上
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)上
10-16 15:41:11.095:E/AndroidRuntime(5822):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
10-16 15:41:11.095:E/AndroidRuntime(5822):。。。还有11个

您的ImageView
iv
未初始化。您将获得
NullPointerException
。初始化iv

 iv = (ImageView) findViewById(R.id.yourimageviewid);
这是一个错误。正如@NickT指出的,这将是一个运行时错误

您已使用相同的id
R.id.outptutc

  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 

确保在/assests/font下有
IDAutomationHC39M\u FREE.otf

这里有一些错误:

您已经声明了
TextView tv1这样您就不必再次执行
final TextView tv1=(TextView)findViewById(R.id.outptutc)

你还提到:

所以我有两个按钮,两个文本视图和一个编辑文本替换

公共课cc扩展活动{

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()));
        }
    });
}
}

logcat中的错误指向此行:

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

确保
字体/IDAutomationHC39M\u FREE.otf
存在,没有损坏,并且名称大小写完全匹配


或者,如果上述方法不起作用,请尝试此处的建议:

如果编译器确实有问题,请包括错误消息和获得错误的行。此问题的答案最好作为如何使用编译器的课程,而不是代码中的任何特定问题。发布错误消息,发布日志cat@HussainAkhtarWahid-如果不编译,则不会运行;如果不运行,则不会有任何logcat@HussainAkhtarWahid-如果它运行了,那么它一定已成功编译。不会导致他所说的编译错误,但当它最终编译时,肯定是运行时的问题。感谢poin我已经纠正了。现在我有一个错误,logcat在OP
java.lang中。RuntimeException:无法启动activity ComponentInfo
是错误,在上面的logcat中说明question@xiHarpzZ您是否更改了此行
TextView tv=(TextView)findViewById(R.id.outputc)
??@meda现在已经修复了它,但是我现在收到了一个不同的错误。
10-16 15:31:32.027:E/AndroidRuntime(3110):java.lang.RuntimeException:无法启动activity ComponentInfo{com.example.barcodedisplayer/com.example.barcodedisplayer.cc}:java.lang.RuntimeException:无法使用本机字体
Hi@meda。非常感谢。但是现在我面临另一个错误
10-16 15:31:32.027:E/AndroidRuntime(3110):java.lang.RuntimeException:无法启动activity ComponentInfo{com.example.barcodedisplayer/com.example.barcodedisplayer.cc}:java.lang.RuntimeException:无法使用本机字体
Hi,我注意到这种情况,我已反复检查单词和语法是否正确。但是如果可能,我仍然会出错,然后尝试使用其他字体,如TTF字体。如果可以使用其他字体,