2015-10-29 116 views
0

最近我決定更新我的舊應用程序,但我得到一個錯誤,native typeface cannot be made。我沒有得到它。爲了測試這個特定項目中是否有一些小故障,我創建了一個新的實現自定義字體的錯誤,但錯誤也是一樣的。自定義字體麻煩

這裏我MainActivity.java:

public class MainActivity extends Activity { 
Typeface MontBold; 
Typeface AsapBold; 
TextView txt1; 

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

    MontBold = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Bold.ttf"); 
    AsapBold = Typeface.createFromAsset(getAssets(), "fonts/Asap-Bold.otf"); 
    txt1 = (TextView) findViewById(R.id.txt1); 
    txt1.setTypeface(AsapBold); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

字體位置

enter image description here

logcat的錯誤

enter image description here

回答

0

我認爲這裏有一個錯字。從資產創建時,您提供了錯誤的字體名稱。它應該是「Montserrat-Bold.otf」。

+0

謝謝。我怎麼會錯過這個?它在新項目中做到了訣竅,儘管如此,還是沒有運氣。 –