-1
    this is what the android monitor is showing:

08-26 19:04:17.456 10081-10089/? E/art: Failed sending reply to debugger: Broken pipe 08-26 19:04:17.456 10081-10089/? I/art: Debugger is no longer active 08-26 19:04:17.582 10081-10081/? I/InstantRun: starting instant run server: is main process 08-26 19:04:17.628 10081-10081/? 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 08-26 19:04:17.736 10081-10081/? D/AndroidRuntime: Shutting down VM 08-26 19:04:17.736 10081-10081/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sayandeep.notepad, PID: 10081
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sayandeep.notepad/com.example.sayandeep.notepad.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 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 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference
at com.example.sayandeep.notepad.MainActivity.onCreate(MainActivity.java:38) at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 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)  08-26 19:04:26.858 10081-10081/com.example.sayandeep.notepad I/Process: Sending signal. PID: 10081 SIG: 9

Main Activity

package com.example.sayandeep.notepad;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;

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.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class MainActivity extends AppCompatActivity {
EditText content;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        content=(EditText)findViewById(R.id.content);
        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)   {
               Save("Note1.txt");
            }
        });
        content.setText((Open("Note1.txt")));

    }
    public void Save(String filename)  {
        try {
            OutputStreamWriter out = new OutputStreamWriter(openFileOutput(filename, 0));
            out.write(content.getText().toString());
            out.close();
            Toast.makeText(this, "Note saved!", Toast.LENGTH_SHORT).show();
        } catch (Throwable t) {
            Toast.makeText(this, "Exception: " + t.toString(), Toast.LENGTH_LONG).show();
        }
    }
    public boolean FileExists(String filename) {
        File file=getBaseContext().getFileStreamPath(filename);
        return file.exists();
    }
    public String Open(String filename)  {
        String temp="";
        if(FileExists(filename))
        {
            try
            {
                InputStream in=openFileInput(filename);
                if(in!=null)
                {
                    InputStreamReader tmp=new InputStreamReader(in);
                    BufferedReader reader=new BufferedReader(tmp);
                    String str;
                    StringBuilder buf=new StringBuilder();
                    while((str=reader.readLine())!=null)
                    {buf.append(str+"\n");}in.close();
                    temp=buf.toString();

                }

            }catch(java.io.FileNotFoundException e){}catch(Throwable t){
                Toast.makeText(this, "Exception: " + t.toString(), Toast.LENGTH_LONG).show();}

    }return temp;
    }
    @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);
    }

}

#Activity_main.xml#
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="com.example.sayandeep.notepad.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_menu_save"
        android:onClick="onClick"/>
</android.support.design.widget.CoordinatorLayout>

# Content_main.xml#

<?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.sayandeep.notepad.MainActivity"
tools:showIn="@layout/activity_main">
<EditText android:id="@+id/content"
android:layout_width="391dp"
android:layout_height="523dp"
android:hint="Type here..."
android:gravity="top"
android:inputType="textPersonName"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />

</android.support.constraint.ConstraintLayout>
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79

1 Answers1

0

You should include your content_main.xml on your main layout. Add this to your main layout before floating action button. Read here

<include layout="@layout/content_main"/>
  • May you please move some of the content of the webpage you link to here. Links may die overtime, so it's ideal to put it here, and everyone else can see. –  Sep 03 '17 at 03:37