0

please am trying to use a custom font which i did, but my app crashes when its suppose to start the LoginActivity. have searched but could not find a solution the issue. this is the error msg:

E/AndroidRuntime: FATAL EXCEPTION: main
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.squaresoft.spotr/com.squaresoft.spotr.LoginActivity}: android.view.InflateException: Binary XML file line #69: Error inflating class com.squaresoft.customfonts.MyEditText
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
                      at android.app.ActivityThread.access$700(ActivityThread.java:140)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
                      at android.os.Handler.dispatchMessage(Handler.java:99)
                      at android.os.Looper.loop(Looper.java:137)
                      at android.app.ActivityThread.main(ActivityThread.java:4946)
                      at java.lang.reflect.Method.invokeNative(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:511)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
                      at dalvik.system.NativeStart.main(Native Method)
                   Caused by: android.view.InflateException: Binary XML file line #69: Error inflating class com.squaresoft.customfonts.MyEditText
                      at android.view.LayoutInflater.createView(LayoutInflater.java:613)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                      at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
                      at android.app.Activity.setContentView(Activity.java:1924)
                      at com.squaresoft.spotr.LoginActivity.onCreate(LoginActivity.java:34)
                      at android.app.Activity.performCreate(Activity.java:5206)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135) 
                      at android.app.ActivityThread.access$700(ActivityThread.java:140) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237) 
                      at android.os.Handler.dispatchMessage(Handler.java:99) 
                      at android.os.Looper.loop(Looper.java:137) 
                      at android.app.ActivityThread.main(ActivityThread.java:4946) 
                      at java.lang.reflect.Method.invokeNative(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:511) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803) 
                      at dalvik.system.NativeStart.main(Native Method) 
                   Caused by: java.lang.reflect.InvocationTargetException
                      at java.lang.reflect.Constructor.constructNative(Native Method)
                      at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                      at android.view.LayoutInflater.createView(LayoutInflater.java:587)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                      at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308) 
                      at android.app.Activity.setContentView(Activity.java:1924) 
                      at com.squaresoft.spotr.LoginActivity.onCreate(LoginActivity.java:34) 
                      at android.app.Activity.performCreate(Activity.java:5206) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135) 
                      at android.app.ActivityThread.access$700(ActivityThread.java:140) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237) 
                      at android.os.Handler.dispatchMessage(Handler.java:99) 
                      at android.os.Looper.loop(Looper.java:137) 
                      at android.app.ActivityThread.main(ActivityThread.java:4946) 
                      at java.lang.reflect.Method.invokeNative(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:511) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803) 
                      at dalvik.system.NativeStart.main(Native Method) 
                   Caused by: java.lang.RuntimeException: native typeface cannot be made
                      at android.graphics.Typeface.<init>(Typeface.java:265)
                      at android.graphics.Typeface.createFromAsset(Typeface.java:239)
                      at com.squaresoft.customfonts.MyEditText.init(MyEditText.java:30)
                      at com.squaresoft.customfonts.MyEditText.<init>(MyEditText.java:20)
                      at java.lang.reflect.Constructor.constructNative(Native Method) 
                      at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
                      at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                      at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308) 
                      at android.app.Activity.setContentView(Activity.java:1924) 
                      at com.squaresoft.spotr.LoginActivity.onCreate(LoginActivity.java:34) 
                      at android.app.Activity.performCreate(Activity.java:5206) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135) 
                      at android.app.ActivityThread.access$700(ActivityThread.java:140) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237) 
                      at android.os.Handler.dispatchMessage(Handler.java:99) 
                      at android.os.Looper.loop(Looper.java:137) 
                      at android.app.ActivityThread.main(ActivityThread.java:4946) 
                      at java.lang.reflect.Method.invokeNative(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:511) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803) 
                      at dalvik.system.NativeStart.main(Native Method) 

For my LoginActivity:

package com.squaresoft.spotr;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;



public class LoginActivity extends Activity
{
EditText email, pass;
Button log;
TextView signin, fb, account;
TextView signup;
SQLiteDBHelper dbhelper;


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


    //Referencing UserEmail, Password EditText and TextView for SignUp 

    fb = (TextView)findViewById(R.id.fb);
    account = (TextView)findViewById(R.id.account);
    email = (EditText) findViewById(R.id.emailT);
    pass = (EditText) findViewById(R.id.passwordT);
    log = (Button) findViewById(R.id.buttonsignin);
    signup = (TextView)findViewById(R.id.signup);
    signin = (TextView)findViewById(R.id.signin);

    //Opening SQLite Pipeline
    dbhelper = new SQLiteDBHelper(this);
    dbhelper = dbhelper.open();

    log.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String email1 = email.getText().toString();
            String pass1 = pass.getText().toString();
            // fetch the Password form database for respective user name
            String storedPassword = dbhelper.getSinlgeEntry(email1);

            // check if the Stored password matches with  Password 

            if (pass1.equals(storedPassword)) {
                Toast.makeText(LoginActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();
                Intent intent = new  Intent(LoginActivity.this,Home.class);
                startActivity(intent);

            }
            else {
                Toast.makeText(LoginActivity.this, "User Name or  Password does not match", Toast.LENGTH_LONG).show();
                email.setText("");
                pass.setText("");
            }
        }


    });



    // Intent For Opening RegisterAccountActivity
    signup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent intent = new Intent(LoginActivity.this, SignUp.class);
            startActivity(intent);
        }
    });



}
  @Override
  protected void onDestroy() {
    super.onDestroy();
    // Close The Database
    dbhelper.close();
}
}

the xml for login...

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


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="260dp">



    <ImageView
        android:layout_width="match_parent"
        android:layout_height="260dp"
        android:background="@drawable/banner"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center|bottom"

        android:background="#80000000">



        <TextView
            android:id="@+id/signin"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="Sign in"
            android:textColor="#087272"
            android:textSize="16dp"
            android:layout_gravity="center"
            android:gravity="center"
            android:padding="16dp"/>



        <TextView
            android:id="@+id/signup"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="Sign up"
            android:textColor="#fff"
            android:textSize="16dp"
            android:padding="16dp"/>


     </LinearLayout>






  </FrameLayout>


 <com.squaresoft.customfonts.MyEditText
    android:id="@+id/emailT"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="E-mail"
    android:inputType="text"
    android:textColor="#000"
    android:background="#f0f0f4"
    android:padding="12dp"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:drawableLeft="@drawable/ic_shapes_2"
    android:drawablePadding="16dp"

    />


  <com.squaresoft.customfonts.MyEditText
    android:id="@+id/passwordT"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Password"
    android:inputType="textPassword"
    android:background="#f0f0f4"
    android:textColor="#000"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:padding="12dp"
    android:drawablePadding="16dp"
    android:drawableLeft="@drawable/ic_tool_6"
    />


  <com.squaresoft.customfonts.MyRegulerText
    android:id="@+id/buttonsignin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded1"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="70dp"
    android:layout_marginRight="70dp"
    android:textAlignment="center"
    android:padding="14dp"
    android:text="Sign In"
    android:textSize="16dp"
    android:textColor="#fff"
    />


  <com.squaresoft.customfonts.MyRegulerText
    android:id="@+id/fb"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="70dp"
    android:layout_marginRight="70dp"
    android:textAlignment="center"
    android:padding="14dp"
    android:text="Facebook Connect"
    android:textColor="#fff"
    android:textSize="16dp"
    />


  <com.squaresoft.customfonts.MyTextView
    android:id="@+id/account"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Don't have an account?"
    android:textSize="16dp"
    android:layout_gravity="center" />







</LinearLayout>

final the java class for MyEditText

package com.squaresoft.customfonts;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.EditText;


public class MyEditText extends EditText {

public MyEditText(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

public MyEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public MyEditText(Context context) {
    super(context);
    init();
}

private void init() {
    if (!isInEditMode()) {
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/Lato-Light.ttf");
        setTypeface(tf);
    }
    }

  }

thanks for your help.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Moplio
  • 250
  • 2
  • 5
  • 15

2 Answers2

0

seems like error happends at LoginActivity:line 34, but line 34 is space in your code copy.

Inso
  • 837
  • 1
  • 7
  • 11
0

Check your MyEditText class:

com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: native typeface cannot be made at android.graphics.Typeface.(Typeface.java:265)

    Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/Lato-Light.ttf");

You cannot use native Typeface here. Using another method.

PLe
  • 137
  • 4
  • so we're do I use the native Typeface – Moplio Oct 17 '16 at 06:15
  • [another topic for solution...](http://stackoverflow.com/questions/7531856/issue-when-using-a-custom-font-native-typeface-cannot-be-made) – PLe Oct 17 '16 at 06:51
  • try to change your font 's name to lowercase, replace - with _: fonts/Lato-Light.ttf -> fonts/lato_light.ttf – PLe Oct 17 '16 at 07:09