Getting this error while running the navigation drawer activity - android

error is:
07/18 11:08:26: Launching app $ adb install-multiple -r -t
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_2.apk
E:\Nav_drawer\app\build\intermediates\instant-run-apk\debug\app-debug.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_1.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_8.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_5.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_6.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_7.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_4.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_9.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_3.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\dep\dependencies.apk
E:\Nav_drawer\app\build\intermediates\split-apk\debug\slices\slice_0.apk
Split APKs installed $ adb shell am start -n
"com.example.nidhi.nav_drawer/com.example.nidhi.nav_drawer.MainActivity"
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER Client not ready yet..Waiting for process to come online Waiting for
process to come online Connected to process 3012 on device
emulator-5554 Capturing and displaying logcat messages from
application. This behavior can be disabled in the "Logcat output"
section of the "Debugger" settings page. D/AndroidRuntime: Shutting
down VM
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.nidhi.nav_drawer, PID: 3012
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nidhi.nav_drawer/com.example.nidhi.nav_drawer.MainActivity}: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.support.v7.widget.Toolbar
at com.example.nidhi.nav_drawer.MainActivity.onCreate(MainActivity.java:32)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Application terminated.

Why are you trying to cast FrameLayout to Toolbar..? FrameLayout never cast to Toolbar please change it.

your code says that FramLayout can not cast to toolbar
so that means you casting Framelayout to Toolbar like this
frame = (Toolbar) findViewById(R.id.Frameloayout);
try changing like this
frame = (Framelayout) findViewById(R.id.Frameloayout);

Related

Running android app problem : E/AndroidRuntime: FATAL EXCEPTION: main

I get the next message from logcat afyter trying to run my app in andorid studio:
5545-5545/com.example.reyesdelafter E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.reyesdelafter, PID: 5545
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.reyesdelafter/com.example.reyesdelafter.MainActivity}: java.lang.InstantiationException: java.lang.Class cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.InstantiationException: java.lang.Class cannot be instantiated
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Also y get the message: "E/art: Failed sending reply to debugger: Broken pipe" before that, my code is exactly the same as in the beginning (and it runned well in the emulator, but I do some tries to change the icons of bottom nav view, and some other things but I get back everything to normality (or so I thought ) and it does not run properly. What is the possible problem ? I alredy tried to uprgrade SDK tools, and make sure my Manifest.xml includes my main activity.
The app has just the splash screen and login with Firebase alredy well done and it runned well before that. Thanks

How to run specific adb command in android code? I have a problem of permission

I want run specific command(adb) in my application.
override fun onReceive(context: Context?, intent: Intent?) {
intent?.let {
if (it.action.equals(Intent.ACTION_BOOT_COMPLETED)) {
with(Intent(context, MainService::class.java)) {
logger.warn("riorio - android boot completed")
var process = Runtime.getRuntime()
.exec("adb shell app_process -Djava.class.path=/data/local/tmp/classes.dex /system/bin com.sds.agent.Main #")
process.waitFor()
logger.warn("riorio - shell server start")
}
}
}
}
This code causes an error.
Looking at the error log, there seems to be a permission problem with the command.
Below is error log.
2019-09-16 19:50:07.826 8518-8518/com.sds.agent W/com.sds.agent.receiver.AutorunReceiver: riorio - android boot completed
2019-09-16 19:50:07.832 8518-8518/com.sds.agent E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sds.agent, PID: 8518
java.lang.RuntimeException: Unable to start receiver com.sds.agent.receiver.AutorunReceiver: java.io.IOException: Cannot run program "adb": error=13, Permission denied
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3313)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1719)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.io.IOException: Cannot run program "adb": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:983)
at java.lang.Runtime.exec(Runtime.java:691)
at java.lang.Runtime.exec(Runtime.java:524)
at java.lang.Runtime.exec(Runtime.java:421)
at com.sds.agent.receiver.AutorunReceiver.onReceive(AutorunReceiver.kt:31)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3306)
at android.app.ActivityThread.-wrap20(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1719) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6692) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 
Caused by: java.io.IOException: error=13, Permission denied
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
at java.lang.ProcessImpl.start(ProcessImpl.java:128)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:964)
at java.lang.Runtime.exec(Runtime.java:691) 
at java.lang.Runtime.exec(Runtime.java:524) 
at java.lang.Runtime.exec(Runtime.java:421) 
at com.sds.agent.receiver.AutorunReceiver.onReceive(AutorunReceiver.kt:31) 
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3306) 
at android.app.ActivityThread.-wrap20(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1719) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6692) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 
How to get access permission to run 'adb' in android application?
Is it possible?
I think you don't have to specify that it is an adb command. Something like this will do the trick
var process = Runtime.getRuntime().exec("app_process -Djava.class.path=/data/local/tmp/classes.dex /system/bin com.sds.agent.Main #")
process.waitFor()
You will need a rooted device in order for this to work.

My app crashes when I try to navigate, can't seem to find issue

I can't seem to find whats wrong with my application...
Here is the logcat:
11-05 16:37:30.030 7867-7867/com.capstone.miguel.studentassistant E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.capstone.miguel.studentassistant, PID: 7867
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.capstone.miguel.studentassistant/com.capstone.miguel.studentassistant.user_sign.LoginActivity}: java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout
at com.capstone.miguel.studentassistant.user_sign.LoginActivity.onCreate(LoginActivity.java:34)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Any idea why the application crashes?
It looks like you have wrong casting: java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout
Check if you use the same types in xml and in your code, probably they are different.
This line is the problem
Caused by: java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout
Check the declared types match those in the layout file
private TextInputEditText inputEmail, inputPass;
inputEmail = (TextInputEditText) findViewById(R.id.input_log_email);
inputPass = (TextInputEditText) findViewById(R.id.input_log_pass);

First app in Android Studio won't start

I am building my first app in android studio but my app crash when I try to open it. I am very new to this and I don't even know what I can show you to solve my problem.
What should I do to solve this problem?
This is what i get from logcat:
--------- beginning of crash
09-06 06:45:25.516 4182-4182/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.questionnaireapplication, PID: 4182
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.questionnaireapplication/com.example.android.questionnaireapplication.QuestionnaireActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.content.res.Resources.getText(Resources.java:331)
at android.widget.TextView.setText(TextView.java:4554)
at com.example.android.questionnaireapplication.QuestionnaireActivity.mettreÀJourQuestion(QuestionnaireActivity.java:38)
at com.example.android.questionnaireapplication.QuestionnaireActivity.onCreate(QuestionnaireActivity.java:49)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
Below portion of stacktrace should be useful for you as it says that you have a problem on line 38 in QuestionnaireActivity.java which is actually a resource not found exception, i-e string resource you are using to set text in your text view is not a valid resource.
Caused by: android.content.res.Resources$NotFoundException: String
resource ID #0x0 at
android.content.res.Resources.getText(Resources.java:331) at
android.widget.TextView.setText(TextView.java:4554) at
com.example.android.questionnaireapplication.QuestionnaireActivity.mettreÀJourQuestion(QuestionnaireActivity.java:38)
at

How to use custom fonts in Android Studio

I am attempting to use a custom font in an Android app. I placed my font files under /app/src/main/assets/fonts, and I reference them with
Typeface.createFromAsset(getApplicationContext().getAssets(),
"fonts/magorian_font.ttf")
When I run my app, I get the error:
04-23 16:14:40.017 13342-13342/com.pottermore.mandrake.pottermoreapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pottermore.mandrake.pottermoreapp, PID: 13342
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pottermore.mandrake.pottermoreapp/com.pottermore.mandrake.pottermoreapp.ActivityHome}: java.lang.RuntimeException: Font asset not found magorian_font.ttf
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.RuntimeException: Font asset not found magorian_font.ttf
at android.graphics.Typeface.createFromAsset(Typeface.java:206)
at com.pottermore.mandrake.pottermoreapp.ActivityHome.onCreate(ActivityHome.java:34)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
What am I doing wrong?
add assets folder in this path : src/main/assets/font
and use this code :
Typeface typrface=Typeface.createFromAsset(getAssets(),"font/iranian_sans");
Text.setTypeface(typrface);
Update
ِDont Forget , you must copy ttf format of font in font folder
It should be look like this when you want to give a TextView a different font :)
private TextView yourtext;
yourtext= (TextView) findViewById(R.id.the_id_of_the_textview);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/magorian_font.ttf");
yourtext.setTypeface(tf);

Categories

Resources