android street view crashes with nullpointer exception - java

We have an activity that uses the StreetViewPanoramaFragment to display the street for a particular property. Without any changes, we started receiving street view crashes. Has anybody encountered anything similar?
It is a very simple layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="#layout/toolbar"
android:id="#+id/toolbar"/>
<fragment
android:id="#+id/streetview_fragment"
android:layout_below="#id/toolbar"
class="com.google.android.gms.maps.StreetViewPanoramaFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
The exception thrown is:
NullPointerException (#streetview.bg:a:39246) {main}
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.google.maps.api.android.lib6.gmm6.streetview.b.a()' on a null object reference at
com.google.maps.api.android.lib6.gmm6.streetview.bg.a(:com.google.android.gms.DynamiteModulesB:39246) at com.google.maps.api.android.lib6.gmm6.streetview.bg.onTouchEvent(:com.google.android.gms.DynamiteModulesB:30874) at
android.view.View.dispatchTouchEvent(View.java:9150) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2687) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2362) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2687) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2362) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2687) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2362) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2687) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2362) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2687) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2362) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2687) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2362) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2687) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2362) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2687) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2362) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2740) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1832) at android.app.Activity.dispatchTouchEvent(Activity.java:2944) at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69) at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2701) at android.view.View.dispatchPointerEvent(View.java:9360) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4978) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4739) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4271) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4324) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4290) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4416) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4298) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4473) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4271) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4324) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4290) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4298) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4271) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6866) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6747) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6718) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6956) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:143) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:6837) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Related

Invoking on a Null Object Reference -- Android Studio Electric Eel [duplicate]

This question already has answers here:
java - Android Studio - Unable to instantiate activity
(2 answers)
Reason for NullPointerException if setContentView() is not used
(3 answers)
Android App Runtime Error
(2 answers)
Android - Unable to instantiate activity - App has stopped
(1 answer)
Closed 13 days ago.
This post was edited and submitted for review 13 days ago and failed to reopen the post:
Original close reason(s) were not resolved
I'm building an app for a homework assignment here. The app keeps failing to launch because of an error. I know this is for an error that some others have experienced, but I can't understand how to apply it to my own, which is why I'm asking it here.
Here is the error:
AndroidRuntime: FATAL EXCEPTION: main
Process: wesfritz.c196, PID: 4260
java.lang.RuntimeException: Unable to start activity ComponentInfo{wesfritz.c196/wesfritz.c196.UI.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at wesfritz.c196.UI.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:223) 
at android.app.ActivityThread.main(ActivityThread.java:7656) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Here's the MainActivity.java code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//This is how buttons are set up in Android
Button button=this.findViewById(R.id.enterButton);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, TermList.class);
//Intent is what connects functions together - makes a thing do a thing!
startActivity(intent);
}
});
setContentView(R.layout.activity_main);
}
Here is what the activity_main.xml looks like:
<TextView
android:id="#+id/textView"
android:layout_width="124dp"
android:layout_height="56dp"
android:fontFamily="sans-serif-condensed-medium"
android:text="StudentApp"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.578" />
<ImageView
android:id="#+id/imageView"
android:layout_width="156dp"
android:layout_height="150dp"
app:layout_constraintBottom_toTopOf="#+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.537"
app:srcCompat="#drawable/ic_launcher_foreground" />
<Button
android:id="#+id/enterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
I've tried looking at other examples on here, but they're different and I haven't been able to figure out why mine won't launch. I thought it was because I have a method in a method, but the teacher wrote that code portion. I see that the line that has the problem is the "setOnClickListener" line, but I don't understand. Also, I think "enterButton" is correct across my XML and Java pieces. I'm kind of at a loss.

Android Studio 4.0.1 GridLayout crashes the app

I was learning how to take a grid and find some elements from the grid, but my app was crashing when I was looking to find the grid by id, so I decided to create a test app that would look for the grid right from the start and this app was crashing too. Note that at the testapp I introduced the legacy libraries to make sure that I don't miss something.
This is xml code for the view
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.264" />
<android.support.v7.widget.GridLayout
android:id="#+id/grid"
android:layout_width="409dp"
android:layout_height="354dp"
android:layout_marginEnd="1dp"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
app:columnCount="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:rowCount="3">
</android.support.v7.widget.GridLayout>
</android.support.constraint.ConstraintLayout>
and this is the mainActivity the crash happens at the "GridLayout test" invocation
package com.example.test2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayout;
public class MainActivity extends AppCompatActivity {
GridLayout test =(GridLayout) findViewById(R.id.grid);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
This is the Error message that I get
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.test2, PID: 11311
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test2/com.example.test2.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:249)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:191)
at com.example.test2.MainActivity.<init>(MainActivity.java:9)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Any help on how to fix this issue would be appreciated and some detailed explanation why it happens , thank you .
You are trying to get id before activity knows about its xml layout. You need to put get id line in the onCreate method as below
public class MainActivity extends AppCompatActivity {
private GridLayout test;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
test =(GridLayout) findViewById(R.id.grid);
}
}
change your code from:
GridLayout test =(GridLayout) findViewById(R.id.grid);
to:
androidx.gridlayout.widget.GridLayout gridLayout = findViewById(R.id.gridLayout);
For Android Studio 4.0 and above,
use import androidx.gridlayout.widget.GridLayout
instead of import android.widget.GridLayout;

Making an animated background for an android app not working

Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.widget.RelativeLayout.getBackground()' on a null object reference
I am creating an android app and want to have an animated background for it.
Unfortunatelly, I get this error here and I have no idea why it is so.
Here is the XML that I have:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/my_bg_animate"
tools:context=".AccessControlActivity">
<LinearLayout
..../>
<TextView
.... />
<ImageView
.... />
</RelativeLayout>
Here is the java file/class:
public class AccessControlActivity extends AppCompatActivity {
ConstraintLayout myLayout;
NfcAdapter nfcAdapter;
Button btnPositive, btnNegative;
Dialog epicDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout relativeLayout = findViewById(R.id.myLayout);
AnimationDrawable animationDrawable = (AnimationDrawable) relativeLayout.getBackground();
animationDrawable.setEnterFadeDuration(4500);
animationDrawable.setExitFadeDuration(4500);
animationDrawable.start();
}
}
And that are the errors I see when I attempt to run the programm:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nfc.netvision/com.nfc.netvision.AccessControlActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.widget.RelativeLayout.getBackground()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.widget.RelativeLayout.getBackground()' on a null object reference
at com.nfc.netvision.AccessControlActivity.onCreate(AccessControlActivity.java:37)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7356) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
Thank you in advance! Looking forward to some answers!
super.onCreate(savedInstanceState);
RelativeLayout relativeLayout = findViewById(R.id.myLayout);
After onCreate you didn't setContentView and directly executed findViewById because of that your RelativeLayout is null and running method of it causes exception.
You haven't defined the layout where you want to inflate the view on the onCreate method, write the next line after super.. :
setcontentview(R.layout.yourLayoutname);

Virtual phone error : "App has stopped working"

I have the following github project
GITHUB file Project
Every time I run the app on a virtual phone through android studio it comes up with "App has stopped working". I have updated android studio.
The errors which keep arising in the logcat are as follow:
05.182 4961-4961/app.monmos E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.monmos, PID: 4961
java.lang.RuntimeException: Unable to start activity ComponentInfo{app.monmos/app.monmos.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at app.monmos.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
at android.content.res.TypedArray.getColor(TypedArray.java:473)
at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
at info.hoang8f.widget.FButton.<init>(FButton.java:52)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:334) 
at android.view.LayoutInflater.createView(LayoutInflater.java:647) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at app.monmos.MainActivity.onCreate(MainActivity.java:19) 
at android.app.Activity.performCreate(Activity.java:6999) 
at android.app.Activity.performCreate(Activity.java:6990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
I have also updated the gradle version and still nothing is working.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundimage"
tools:context="app.monmos.Signin">
<LinearLayout
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2">
<com.rengwuxian.materialedittext.MaterialAutoCompleteTextView
android:id="#+id/edtphone"
android:hint ="Phone Number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text ="00000001"
android:textColorHint="#android:color/white"
android:textColor="#android:color/white"
android:textSize="34sp"
android:inputType="phone"
app:met_baseColor="#android:color/white"
app:met_floatingLabel="highlight"
app:met_primaryColor="#android:color/white"
app:met_singleLineEllipsis = "true"
/>
<com.rengwuxian.materialedittext.MaterialAutoCompleteTextView
android:id="#+id/edtPassword"
android:hint ="Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text ="1234"
android:textColorHint="#android:color/white"
android:textColor="#android:color/white"
android:textSize="34sp"
android:inputType="phone"
app:met_baseColor="#android:color/white"
app:met_floatingLabel="highlight"
app:met_primaryColor="#android:color/white"
app:met_singleLineEllipsis = "true"
/>
</LinearLayout>
<info.hoang8f.widget.FButton
android:id="#+id/btnSignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:text="Sign In"
android:textColor="#android:color/white"
app:buttonColor="#color/btsSignActive"
app:cornerRadius="4dp"
app:shadowColor="#android:color/black"
app:shadowEnabled="true"
app:shadowHeight="5dp" />
//Added grade file
</RelativeLayout>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3' +
'.0.1'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You don't have maven set up in your project's gradle file. Your gradle file should look like this:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Java android crash when add android.support.design.widget.NavigationView

When I add this code in activity_main.xml :
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
My app is crashed . Into build gradle, I added a in dependencies :
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
When I remove a android.support.design.widget.NavigationView it is working
This is a log :
Process: com.smok.maps, PID: 16311
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smok.maps/com.smok.maps.MainActivity}: android.view.InflateException: Binary XML file line #431: Binary XML file line #431: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #431: Binary XML file line #431: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)
at android.app.Activity.setContentView(Activity.java:2387)
at com.smok.maps.MainActivity.onCreate(MainActivity.java:285)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)?
at android.app.ActivityThread.access$1100(ActivityThread.java:221)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)?
at android.os.Handler.dispatchMessage(Handler.java:102)?
at android.os.Looper.loop(Looper.java:158)?
at android.app.ActivityThread.main(ActivityThread.java:7224)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)?
Caused by: android.view.InflateException: Binary XML file line #431: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)?
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)?
at android.app.Activity.setContentView(Activity.java:2387)?
at com.smok.maps.MainActivity.onCreate(MainActivity.java:285)?
at android.app.Activity.performCreate(Activity.java:6876)?
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)?
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)?
at android.app.ActivityThread.access$1100(ActivityThread.java:221)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)?
at android.os.Handler.dispatchMessage(Handler.java:102)?
at android.os.Looper.loop(Looper.java:158)?
at android.app.ActivityThread.main(ActivityThread.java:7224)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)?
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)?
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)?
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)?
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)?
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)?
at android.app.Activity.setContentView(Activity.java:2387)?
at com.smok.maps.MainActivity.onCreate(MainActivity.java:285)?
at android.app.Activity.performCreate(Activity.java:6876)?
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)?
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)?
at android.app.ActivityThread.access$1100(ActivityThread.java:221)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)?
at android.os.Handler.dispatchMessage(Handler.java:102)?
at android.os.Looper.loop(Looper.java:158)?
at android.app.ActivityThread.main(ActivityThread.java:7224)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)?
Caused by: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.support.design.internal.NavigationMenuPresenter.getMenuView(NavigationMenuPresenter.java:98)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:161)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:92)
at java.lang.reflect.Constructor.newInstance(Native Method)?
at android.view.LayoutInflater.createView(LayoutInflater.java:631)?
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)?
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)?
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)?
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)?
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)?
at android.app.Activity.setContentView(Activity.java:2387)?
at com.smok.maps.MainActivity.onCreate(MainActivity.java:285)?
at android.app.Activity.performCreate(Activity.java:6876)?
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)?
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)?
at android.app.ActivityThread.access$1100(ActivityThread.java:221)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)?
at android.os.Handler.dispatchMessage(Handler.java:102)?
at android.os.Looper.loop(Looper.java:158)?
at android.app.ActivityThread.main(ActivityThread.java:7224)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)?
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)?
at android.support.design.internal.NavigationMenuPresenter.getMenuView(NavigationMenuPresenter.java:98)?
at android.support.design.widget.NavigationView.<init>(NavigationView.java:161)?
at android.support.design.widget.NavigationView.<init>(NavigationView.java:92)?
at java.lang.reflect.Constructor.newInstance(Native Method)?
at android.view.LayoutInflater.createView(LayoutInflater.java:631)?
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)?
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)?
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)?
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)?
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)?
at android.app.Activity.setContentView(Activity.java:2387)?
at com.smok.maps.MainActivity.onCreate(MainActivity.java:285)?
at android.app.Activity.performCreate(Activity.java:6876)?
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)?
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)?
at android.app.ActivityThread.access$1100(ActivityThread.java:221)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)?
at android.os.Handler.dispatchMessage(Handler.java:102)?
at android.os.Looper.loop(Looper.java:158)?
at android.app.ActivityThread.main(ActivityThread.java:7224)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)?
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)?
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)?
at android.support.design.internal.NavigationMenuPresenter.getMenuView(NavigationMenuPresenter.java:98)?
at android.support.design.widget.NavigationView.<init>(NavigationView.java:161)?
at android.support.design.widget.NavigationView.<init>(NavigationView.java:92)?
at java.lang.reflect.Constructor.newInstance(Native Method)?
at android.view.LayoutInflater.createView(LayoutInflater.java:631)?
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)?
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)?
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)?
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)?
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)?
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)?
at android.app.Activity.setContentView(Activity.java:2387)?
at com.smok.maps.MainActivity.onCreate(MainActivity.java:285)?
at android.app.Activity.performCreate(Activity.java:6876)?
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)?
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)?
at android.app.ActivityThread.access$1100(ActivityThread.java:221)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)?
at android.os.Handler.dispatchMessage(Handler.java:102)?
at android.os.Looper.loop(Looper.java:158)?
at android.app.ActivityThread.main(ActivityThread.java:7224)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)?
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0100b8 a=-1}
at android.content.res.TypedArray.getDrawable(TypedArray.java:883)
at android.widget.AbsListView.<init>(AbsListView.java:1168)
at android.widget.ListView.<init>(ListView.java:
nav_header:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="#dimen/nav_header_height"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
android:gravity="bottom">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:id="#+id/imageView" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="Andy Point"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="andypoint#androidtutorialpoint.com"
android:id="#+id/textView" />
</LinearLayout>
According to your error its pretty much clear that it has failed to inflate navigation menu. Please provide the #menu/activity_main_drawer file. And recheck it for external Strings or drawables and closed tags.
Well then you should use
<menu xmlns:android="http://schemas.android.com/apk/res/android">
instead of
<menu xmlns:android="schemas.android.com/apk/res/android">
and remove ; after that.
This is a problem of layout_gravity at line number 431 Please try to use layout_gravity = left
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:fitsSystemWindows="true" />

Categories