Android Studio Web Browser Project Code Errors - java

I just developed my first android web browser project,
but it didn't go well.
I found there's some crash on my MainActivity,
But I can't find it.
This is my java code, from my MainActivity.
package org.thunderdot.station;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText editText_search = (EditText) findViewById(R.id.EditText_Uri);
WebView webView = (WebView) findViewById(R.id.webview);
ImageButton button_search = (ImageButton) findViewById(R.id.ImageButton_Search);
ImageButton button_more = (ImageButton) findViewById(R.id.ImageButton_More);
WebSettings webSettings = webView.getSettings();
String default_url = "https://www.google.com";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView.setWebViewClient(new WebViewClient());
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadsImagesAutomatically(true);
webView.loadUrl(default_url);
}
public void onClick_button_search() {
String url = editText_search.getText().toString();
if(url.isEmpty()) {
Toast.makeText(getApplicationContext(), "Please Input URL First!", Toast.LENGTH_SHORT).show();
}
else {
webView.loadUrl(url);
}
}
And Here's my activity_main.xml source.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="org.thunderdot.station.MainActivity"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="368dp"
android:layout_height="60dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"
android:gravity="center"
android:id="#+id/LinerLayout_Search" >
<EditText
android:id="#+id/EditText_Uri"
android:layout_width="210dp"
android:layout_height="50dp"
android:hint="Input Url or Text"
android:inputType="textUri"
android:onClick="onClick_button_search"/>
<Space
android:layout_width="5dp"
android:layout_height="0dp" />
<ImageButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#mipmap/ic_launcher"
android:id="#+id/ImageButton_Search"/>
<Space
android:layout_width="5dp"
android:layout_height="0dp" />
<ImageButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#mipmap/ic_launcher"
android:id="#+id/ImageButton_More"/>
</LinearLayout>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/LinerLayout_Search"
android:id="#+id/webview"> </WebView>
</RelativeLayout>
And here's my logcat, too.
05-31 12:20:14.241 2709-2709/org.thunderdot.station I/art: Not late-enabling -Xcheck:jni (already on)
05-31 12:20:14.241 2709-2709/org.thunderdot.station W/art: Unexpected CPU variant for X86 using defaults: x86
05-31 12:20:14.431 2709-2709/org.thunderdot.station W/System: ClassLoader referenced unknown path: /data/app/org.thunderdot.station-1/lib/x86
05-31 12:20:14.441 2709-2709/org.thunderdot.station I/InstantRun: starting instant run server: is main process
05-31 12:20:14.542 2709-2709/org.thunderdot.station W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-31 12:20:14.661 2709-2729/org.thunderdot.station I/OpenGLRenderer: Initialized EGL, version 1.4
05-31 12:20:14.661 2709-2729/org.thunderdot.station D/OpenGLRenderer: Swap behavior 1
05-31 12:20:14.661 2709-2729/org.thunderdot.station W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
05-31 12:20:14.661 2709-2729/org.thunderdot.station D/OpenGLRenderer: Swap behavior 0
05-31 12:21:41.277 2709-2709/org.thunderdot.station D/AndroidRuntime: Shutting down VM
--------- beginning of crash
05-31 12:21:41.278 2709-2709/org.thunderdot.station E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.thunderdot.station, PID: 2709
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.thunderdot.station/org.thunderdot.station.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: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.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:120)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:151)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:33)
at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:33)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at org.thunderdot.station.MainActivity.<init>(MainActivity.java:14)
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) 
And here's the java source that calls MainActivity.
package org.thunderdot.station;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TitleScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_title_screen);
Button button = (Button)findViewById(R.id.Button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), MainActivity.class);
startActivity(intent);
}
});
}
}

Related

Why after clicking + icon in the appbar the app crashes? Showing null pointer exception

I am not getting the up button(in fact activity_order activity doesn't start).It crashes when i click the icon (+) in MainActivity appbar
I have this intuition that there is something wrong with
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
This is the second activity
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
public class activity_order extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar_main);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
This is the main/parent activity
import android.content.Intent;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.ShareActionProvider;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar= findViewById(R.id.toolbar_main);
setSupportActionBar(toolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_main,menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
if(R.id.action_create_order==item.getItemId()) {
Intent intent = new Intent(this, activity_order.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Error Log
2019-06-18 22:51:49.374 4127-4147/com.example.orderpizza I/Adreno: QUALCOMM build : f47ef91, I09d312ff84
Build Date : 07/24/17
OpenGL ES Shader Compiler Version: XE031.09.00.04
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.5.5.R1.07.01.02.269.046
Remote Branch : NONE
Reconstruct Branch : NOTHING
2019-06-18 22:51:49.383 4127-4147/com.example.orderpizza I/OpenGLRenderer: Initialized EGL, version 1.4
2019-06-18 22:51:49.383 4127-4147/com.example.orderpizza D/OpenGLRenderer: Swap behavior 1
2019-06-18 22:51:49.418 4127-4127/com.example.orderpizza W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
2019-06-18 22:51:52.150 4127-4127/com.example.orderpizza V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance#7d39c7c
2019-06-18 22:51:52.269 4127-4127/com.example.orderpizza I/Timeline: Timeline: Activity_launch_request time:28140110 intent:Intent { cmp=com.example.orderpizza/.activity_order }
2019-06-18 22:51:52.317 4127-4127/com.example.orderpizza D/AndroidRuntime: Shutting down VM
2019-06-18 22:51:52.318 4127-4127/com.example.orderpizza E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.orderpizza, PID: 4127
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.orderpizza/com.example.orderpizza.activity_order}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2757)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2818)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at com.example.orderpizza.activity_order.onCreate(activity_order.java:16)
at android.app.Activity.performCreate(Activity.java:6858)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2710)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2818) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:163) 
at android.app.ActivityThread.main(ActivityThread.java:6393) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
2019-06-18 22:51:52.337 4127-4127/com.example.orderpizza I/Process: Sending signal. PID: 4127 SIG: 9
Please help as I am not getting why is it showing a nullPointerException.
You probably is not using the support library, if you're importing android.app.ActionBar you should user getActionBar() instead. Or just import android.support.v7.app.ActionBar.
To your safety, always check if getSupportActionBar() != null as well
i think your activity_order layout don't have any Toolbar xml with id toolbar_main
please recheck that...
you should at least have a appbarlayout and a toolbar
<android.support.design.widget.AppBarLayout
android:id="#+id/my_appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_margin="0dp"
app:layout_scrollFlags="snap"
app:navigationIcon="#drawable/ic_arrow_back_black_24dp"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:theme="#style/ThemeToolbar.default" />
</android.support.design.widget.AppBarLayout>

Google signin in android app

I'm a newbie in programming, trying to implement a Google Signin in my test app.
Folowing Google API documentation I've added all required dependencies at gradle files and registered my test app through OAuth...
Further I wrote a code as described in example provided by Google, but my app crashes at the begining, before any user's action in Virtual device, and does not even set up via APK file at the real device....
What am i doing wrong?
Main (single) activity code:
package ru.podgorny.carcall;
import android.accounts.Account;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;
public class MainActivity extends AppCompatActivity {
SignInButton signInButton;
public static final int RC_SIGN_IN = 07;
public static final String TAG = "MainActivity";
TextView tw1;
TextView tw2;
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.build();
GoogleSignInClient mGSC = GoogleSignIn.getClient(this, gso);
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViews();
}
private void findViews() {
signInButton = findViewById(R.id.idButtonGoogle);
tw1 = findViewById(R.id.textView1);
tw1 = findViewById(R.id.textView2);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.idButtonGoogle:
signIn();
break;
}
}
private void signIn() {
Intent signInIntent = mGSC.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
updateUI(account);
} catch (ApiException e) {
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
updateUI(null);
}
}
private void updateUI(GoogleSignInAccount account) {
tw1.setText("OK");
tw2.setText("Name: " + account.getGivenName() + ", Family name: " + account.getFamilyName() + ", Email: " + account.getEmail() + " image: " +
account.getPhotoUrl());
}
}
Activity.xml code:
<?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="ru.podgorny.carcall.MainActivity"
>
<com.google.android.gms.common.SignInButton
android:id="#+id/idButtonGoogle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foregroundGravity="top"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/idButtonGoogle" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView1" />
</android.support.constraint.ConstraintLayout>
Manifest.xml by default:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.podgorny.carcall">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Console logs :
03-23 08:35:32.774 5682-5682/? E/libprocessgroup: failed to make and chown /acct/uid_10060: Read-only file system
03-23 08:35:32.774 5682-5682/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
03-23 08:35:32.775 5682-5682/? I/art: Not late-enabling -Xcheck:jni (already on)
03-23 08:35:33.180 5682-5682/ru.podgorny.carcall I/InstantRun: starting instant run server: is main process
03-23 08:35:33.746 5682-5682/ru.podgorny.carcall D/AndroidRuntime: Shutting down VM
03-23 08:35:33.753 5682-5682/ru.podgorny.carcall E/AndroidRuntime: FATAL EXCEPTION: main
Process: ru.podgorny.carcall, PID: 5682
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ru.podgorny.carcall/ru.podgorny.carcall.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference
at android.content.ContextWrapper.getMainLooper(ContextWrapper.java:101)
at com.google.android.gms.common.api.GoogleApi.<init>(Unknown Source)
at com.google.android.gms.auth.api.signin.GoogleSignInClient.<init>(Unknown Source)
at com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(Unknown Source)
at ru.podgorny.carcall.MainActivity.<init>(MainActivity.java:35)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1606)
at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
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:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
03-23 08:35:33.827 5682-5695/ru.podgorny.carcall I/art: Background sticky concurrent mark sweep GC freed 2567(255KB) AllocSpace objects, 0(0B) LOS objects, 30% free, 773KB/1117KB, paused 18.376ms total 73.744ms
Try this
GoogleSignInOptions gso ;
GoogleSignInClient mGSC ;
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.build();
mGSC = GoogleSignIn.getClient(this, gso);
findViews();
}

Error inflating class MaterialEditText

I am new to android development. Please help me in identifying the issue in my code. My code is getting into InflateException.
Please help me.
My code is existing with error related to MaterialEditText class and I have searched for the solution but till now didn't get the working solution.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_vertical"
tools:context="com.android.appgallery.quizworld.MainActivity">
<ImageView
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/wrap_login"
/>
<RelativeLayout
android:id="#+id/wrap_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="8dp"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/info_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:com.rengwuxian.materialedittext="http://schemas.android.com/tools"
android:layout_margin="8dp"
app:cardElevation="4dp">
<LinearLayout
android:padding="16dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.rengwuxian.materialedittext:MaterialEditText
android:id="#+id/edtUser"
android:hint="User Name"
android:textColorHint="#color/colorPrimary"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:met_baseColor="#color/colorPrimary"
app:met_floatingLabel="highlight"
app:met_primaryColor="#color/colorPrimary"
app:met_singleLineEllipsis="true"
/>
<com.rengwuxian.materialedittext:MaterialEditText
android:id="#+id/edtPassword"
android:hint="Password"
android:textColorHint="#color/colorPrimary"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:met_baseColor="#color/colorPrimary"
app:met_floatingLabel="highlight"
app:met_primaryColor="#color/colorPrimary"
app:met_singleLineEllipsis="true"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_below="#id/info_login"
android:orientation="horizontal"
android:weightSum="2"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_sign_up"
android:text="Sign Up"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn_sign_in"
android:text="Sign In"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MyButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#1CB3BC</item>
</style>
</resources>
MainActivity
package com.android.appgallery.quizworld;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.android.appgallery.quizworld.BroadcastReceiver.AlarmReceiver;
import com.android.appgallery.quizworld.Common.Common;
import com.android.appgallery.quizworld.Model.User;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rengwuxian.materialedittext.MaterialEditText;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity {
MaterialEditText edtNewUser,edtNewPassword,edtNewEmail; //For Sign Up
MaterialEditText edtUser,edtPassword; //For Login
Button btnSignUp,btnSignIn;
FirebaseDatabase database;
DatabaseReference users;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
try {
setContentView(R.layout.activity_main);
}catch(Exception e){
//InflateException ex=new InflateException(parser.getPositionDescription()+" "+e.getMessage());
InflateException ex=new InflateException(e.getMessage());
ex.initCause(e);
throw ex;
}
registerAlarm();
database= FirebaseDatabase.getInstance();
users=database.getReference("Users");
edtUser=(MaterialEditText) findViewById(R.id.edtUser);
edtPassword=(MaterialEditText)findViewById(R.id.edtPassword);
btnSignIn= (Button) findViewById(R.id.btn_sign_in);
btnSignUp= (Button) findViewById(R.id.btn_sign_up);
btnSignUp.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
showSignUpDialog();
}
});
btnSignIn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
signIn(edtUser.getText().toString(),edtPassword.getText().toString());
}
});
}
private void registerAlarm() {
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,9);
calendar.set(Calendar.MINUTE,40);
calendar.set(Calendar.SECOND,0);
Intent intent=new Intent(MainActivity.this, AlarmReceiver.class);
PendingIntent pendingIntent=PendingIntent.getBroadcast(MainActivity.this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager)this.getSystemService(this.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);
}
private void signIn(final String user, final String pwd){
users.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.child(user).exists()){
if(!user.isEmpty()){
User login=dataSnapshot.child(user).getValue(User.class);
if(login.getPassword().equals(pwd)){
Intent homeActivity=new Intent(MainActivity.this,Home.class);
Common.currentUser= login;
startActivity(homeActivity);
finish();
}else{
Toast.makeText(MainActivity.this,"Wrong Password",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(MainActivity.this,"Please enter your user name.",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(MainActivity.this,"User does not exist",Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void showSignUpDialog(){
AlertDialog.Builder alertDialog= new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("Sign Up");
alertDialog.setMessage("Please fill full information");
LayoutInflater inflater=this.getLayoutInflater();
View sign_up_layout = inflater.inflate(R.layout.sign_up_layout,null);
edtNewUser=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewUserName);
edtNewPassword=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewPassword);
edtNewEmail=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewEmail);
alertDialog.setView(sign_up_layout);
//Check for the icon
alertDialog.setIcon(R.drawable.ic_account_circle_black_24dp);
alertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int i){
dialogInterface.dismiss();
}
});
alertDialog.setPositiveButton("YES",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int i) {
final User user = new User(edtNewUser.getText().toString(), edtNewPassword.
getText().toString(), edtNewEmail.getText().toString());
users.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.child(user.getUserName()).exists())
Toast.makeText(MainActivity.this, "User already exists!!!", Toast.LENGTH_SHORT).show();
else {
users.child(user.getUserName()).setValue(user);
Toast.makeText(MainActivity.this, "User registration successful!!!", Toast.LENGTH_SHORT).show();
}
}
public void onCancelled(DatabaseError databaseError) {
}
});
dialogInterface.dismiss();
}
});
alertDialog.show();
}
}
Error Snippet:
01-18 23:14:13.656 23773-23773/? I/art: Late-enabling -Xcheck:jni
01-18 23:14:13.726 23773-23773/com.android.appgallery.quizworld D/LenovoAppIconTheme: ExtraResources;cleanCachedIcon;clear cache..
01-18 23:14:14.049 23773-23773/com.android.appgallery.quizworld W/System: ClassLoader referenced unknown path:
/data/app/com.android.appgallery.quizworld-2/lib/arm
01-18 23:14:14.079 23773-23773/com.android.appgallery.quizworld D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping
initialization.
01-18 23:14:14.095 23773-23773/com.android.appgallery.quizworld W/InstanceID/Rpc: Found 10014
01-18 23:14:14.102 23773-23773/com.android.appgallery.quizworld D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping
initialization.
01-18 23:14:14.144 23773-23773/com.android.appgallery.quizworld I/FA: App measurement is starting up, version: 10298
01-18 23:14:14.144 23773-23773/com.android.appgallery.quizworld I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld V/FA: Collection enabled
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld V/FA: App package, google app id: com.android.appgallery.quizworld,
1:778477946548:android:1b7a8c110537f112
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app
com.android.appgallery.quizworld
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld D/FA: Debug-level message logging enabled
01-18 23:14:14.210 23773-23773/com.android.appgallery.quizworld V/FA: Registered activity lifecycle callback
01-18 23:14:14.212 23773-23773/com.android.appgallery.quizworld I/FirebaseInitProvider: FirebaseApp initialization successful
01-18 23:14:14.213 23773-23773/com.android.appgallery.quizworld I/InstantRun: starting instant run server: is main process
01-18 23:14:14.219 23773-23792/com.android.appgallery.quizworld V/FA: Using measurement service
01-18 23:14:14.225 23773-23792/com.android.appgallery.quizworld V/FA: Connecting to remote service
01-18 23:14:14.297 23773-23773/com.android.appgallery.quizworld W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter
android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList,
android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
01-18 23:14:14.306 23773-23773/com.android.appgallery.quizworld V/FA: onActivityCreated
01-18 23:14:14.472 23773-23773/com.android.appgallery.quizworld D/AndroidRuntime: Shutting down VM
01-18 23:14:14.473 23773-23773/com.android.appgallery.quizworld E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.appgallery.quizworld, PID: 23773
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.android.appgallery.quizworld/com.android.appgallery.quizworld.MainActivity}: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
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:865)
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
at com.android.appgallery.quizworld.MainActivity.onCreate
(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1119)
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:865) 
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755) 
Caused by: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
Caused by: android.view.InflateException: Binary XML file line
#0: Error inflating class MaterialEditText
Caused by: java.lang.ClassNotFoundException: Didn't find class
"android.view.MaterialEditText" on path: DexPathList[[zip file "/data/app/com.android.appgallery.quizworld-2/base.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_0_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_1_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_3_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_4_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_6_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_7_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.android.appgallery.quizworld-2/lib/arm, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass
(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView
(LayoutInflater.java:609)
at android.view.LayoutInflater.onCreateView
(LayoutInflater.java:700)
at
com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView
(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
01-18 23:14:14.474 23773-23773/com.android.appgallery.quizworld E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:377)
at
android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView
(AppCompatActivity.java:140)
at com.android.appgallery.quizworld.MainActivity.onCreate
(MainActivity.java:42)
at android.app.Activity.performCreate(Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1119)
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:865)
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755)

Unable to start activity ComponentInfo (LOGCAT)

I'm a new android programmer and recently, I'm getting this error in the logcat:
03-22 15:33:49.395 13639-13639/com.abaco.awser E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.abaco.awser, PID: 13639
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abaco.awser/com.abaco.awser.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.abaco.awser.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
at android.app.ActivityThread.access$800(ActivityThread.java:166) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5584) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
at dalvik.system.NativeStart.main(Native Method) 
Here's my MainActivity.java:
package com.abaco.awser;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
#Override
public void onBackPressed() {
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView myWebView = (WebView) findViewById(R.id.activity_main_webview);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("http://primopizza.com.br/eloja");
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
setContentView(R.layout.activity_main);
}
}
And here's my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context="com.abaco.abawser.MainActivity">
<WebView
android:id="#+id/activity_main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Can you please help me solving this error? I already tried everything.
You are getting NPE because your myWebView is null
place this
WebView myWebView = (WebView)findViewById(R.id.activity_main_webview);
after
setContentView(R.layout.activity_main);
Because you can actually retrive your views only after setting content View

Java error on android studio [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 7 years ago.
i am new to android app developing i am following buckys tutorials
currently i am on this part
https://www.youtube.com/watch?v=MdOxtws4DsI&index=13&list=PL6gx4Cwl9DGBsvRxJJOzG4r4k_zLKrnxl
i did everything as told but when i run the app i find this error here's my logcat
12-08 20:42:45.548 2465-2465/com.kimdevelopment.kimmmm I/art: Not late-enabling -Xcheck:jni (already on)
12-08 20:42:45.549 2465-2465/com.kimdevelopment.kimmmm I/art: Late-enabling JIT
12-08 20:42:45.552 2465-2465/com.kimdevelopment.kimmmm I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
12-08 20:42:45.630 2465-2465/com.kimdevelopment.kimmmm W/System: ClassLoader referenced unknown path: /data/app/com.kimdevelopment.kimmmm-1/lib/x86
12-08 20:42:45.696 2465-2465/com.kimdevelopment.kimmmm D/AndroidRuntime: Shutting down VM
12-08 20:42:45.696 2465-2465/com.kimdevelopment.kimmmm E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kimdevelopment.kimmmm, PID: 2465
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kimdevelopment.kimmmm/com.kimdevelopment.kimmmm.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.support.v7.widget.Toolbar.getTitle()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.support.v7.widget.Toolbar.getTitle()' on a null object reference
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:98)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:91)
at android.support.v7.app.ToolbarActionBar.<init>(ToolbarActionBar.java:73)
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:205)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:99)
at com.kimdevelopment.kimmmm.MainActivity.onCreate(MainActivity.java:27)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-08 20:42:54.014 2465-2465/? I/Process: Sending signal. PID: 2465 SIG: 9
also here's the java file that i edited
package com.kimdevelopment.kimmmm;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RelativeLayout;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout kimsLayout = new RelativeLayout(this);
Button redButton = new Button(this);
kimsLayout.addView(redButton);
setContentView(kimsLayout);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
and finally the xml file
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.kimdevelopment.kimmmm.MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
I haven't used tool bars that much so I could be off, but you're instantiating your tool bar with a R.id which usually corresponds to an XML element.
You don't actually have an element in your XML that references the toolbar. You need an element with an ID "toolbar" maybe like this:
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.kimdevelopment.kimmmm.MainActivity"
tools:showIn="#layout/activity_main">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/blue"
android:foreground="?android:attr/windowContentOverlay"
app:theme="#style/Toolbar"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
EDIT:
Also, with these lines, you are setting the Activity content to something besides your XML defined layout:
RelativeLayout kimsLayout = new RelativeLayout(this);
Button redButton = new Button(this);
kimsLayout.addView(redButton);
setContentView(kimsLayout);
You should change your XML main RelativeLayout and give it an id (like the elements within it) and then set the content view like this:
setContentView(R.layout.main_layout);

Categories