This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I'm trying to findViewById in constructor in Login class but it throws a error on object create and crash application.
Error throws only on construct in Login class not on listener.
After button clicked it should call loginAction().
What should i do to fix that (this is my first app) ?
Error:
11-26 09:13:57.592 5926-5926/com.wolfriders E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.wolfriders, PID: 5926
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wolfriders/com.wolfriders.Main}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:2563)
at com.wolfriders.Login.<init>(Login.java:13)
at com.wolfriders.Main.onCreate(Main.java:18)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Main:
package com.wolfriders;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class Main extends AppCompatActivity {
private boolean logged = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (logged == false) {
setContentView(R.layout.login_from);
final Login login = new Login();
login.login_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
login.loginAction();
}
});
} else { setContentView(R.layout.main_activity); }
}
}
Login:
package com.wolfriders;
import android.app.Activity;
import android.widget.Button;
import android.widget.EditText;
public class Login extends Activity {
public EditText login_phone, login_password;
public Button login_btn;
Login() {
this.login_phone = (EditText)findViewById(R.id.inputloginpassword);
this.login_password = (EditText)findViewById(R.id.inputloginpassword);
this.login_btn = (Button)findViewById(R.id.btnlogin);
}
public void loginAction() {
// Do something after login button clicked
}
}
If your Login Class needs to be an Activity you would need to override onCreate function since it is activity and then you need an .xml file to associate that activity class with ui represented. How did you make this Login class (I mean as an activity or just a class)? On more detailed reading and explanation about activities you can read here:
https://developer.android.com/guide/components/activities/intro-activities.html
Related
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 2 years ago.
Hi currently i am working on project including parse server,and after adding parse library to my project ,when i run it it shows this error ( java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplicationv/com.example.myapplicationv.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
at com.parse.Parse.getParseDir(Parse.java:509)
at com.parse.ParseCorePlugins.getCurrentUserController(ParseCorePlugins.java:130)
at com.parse.ParseUser.getCurrentUserController(ParseUser.java:55)
at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:883)
at com.parse.ParseObject.saveInBackground(ParseObject.java:1405)
at com.parse.ParseObject.saveInBackground(ParseObject.java:1529)
at com.example.myapplicationv.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
)
this is MainActivity here
MainActivity
package com.example.myapplicationv;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.parse.ParseAnalytics;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.SaveCallback;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseObject score = new ParseObject("Score");
score.put("username","Nalin");
score.put("score",200);
score.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null){
Log.i("success","we save the score");
}else{
e.printStackTrace();
}
}
});
ParseAnalytics.trackAppOpenedInBackground(getIntent());
}
}
StarterApplication
package com.example.myapplicationv;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseUser;
public class StarterApplication extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_starter_application);
Parse.enableLocalDatastore(this);
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("myappID")
.clientKey("nV48GY6ZE5Lw")
.server("http://18.217.199.68/parse/")
.build()
);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
defaultACL.setPublicWriteAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
You need to initialize the parser in the application class as explained in document here. Also should declare it in the Manifest file.
The problem that I encounter was that the Document that shows to Use a class App extending Application was never initialized even after adding the activity in Manifest(it gives a red line also).
So what I did was I saved the below code in the onCreate of my SplashActivity
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId(getString(R.string.back4app_app_id))
// if defined
.clientKey(getString(R.string.back4app_client_key))
.server(getString(R.string.back4app_server_url))
.enableLocalDataStore() // <--- This is important
.build());
Now After this I'm able to use it normally.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
[This is the code where the exception occurred.
package com.example.shrine;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
final TextInputLayout password1 = findViewById(R.id.password_text_input);
final TextInputEditText password = findViewById(R.id.password_edit_text);
Context ctx;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ctx=this;
MaterialButton Next=findViewById(R.id.next_button);
Next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(ctx,"This can't be happening!",Toast.LENGTH_SHORT).show();
Intent products = new Intent(MainActivity.this, products_act.class);
startActivity(products);
}
});
}
}
package com.example.shrine;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class products_act extends AppCompatActivity {
Context context;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context=this;
setContentView(R.layout.activity_products_act);
Button back=findViewById(R.id.button);
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "Back Button Clicked!!", Toast.LENGTH_SHORT).show();
Intent backToHome = new Intent(products_act.this, MainActivity.class);
startActivity(backToHome);
}
});}}
ERROR:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shrine, PID: 18243
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.shrine/com.example.shrine.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:152)
at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:157)
at android.content.Context.obtainStyledAttributes(Context.java:655)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:692)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:479)
at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:214)
at com.example.shrine.MainActivity.<init>(MainActivity.java:18)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1173)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Please look into this problem of NullPointerException as I am new to Android development and still Learning therefore please help.The attached photos [1] and [2] are the code snaps. Please check them out.
P.S.-I have removedthe code as images.Thankyou for the suggestion
at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:214)
at com.example.shrine.MainActivity.<init>(MainActivity.java:18)
This tells you're calling findViewById() too early in MainActivity's init phase e.g. when initialising its fields. Move the findViewById() calls to onCreate() after setContentView().
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am doing a challenge from Treehouse and they have given some initial project files to follow along. The problem is they're 2 years old and a lot of the code is outdated. I changed as much as I could, but apparently there still are some problems.
I try to run this code and it says it can't invoke setLayoutManager() on a null object reference. How can the object be null if I initialise it right before?
private void populate() {
StaggeredGridLayoutManager lm = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
mAlbumList.setLayoutManager(lm);
This is all the code in the file.
package com.teamtreehouse.albumcover;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import butterknife.BindView;
import butterknife.ButterKnife;
public class AlbumListActivity extends Activity {
#BindView(R.id.album_list) RecyclerView mAlbumList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_album_list);
initTransitions();
ButterKnife.bind(this);
populate();
}
private void initTransitions() {
getWindow().setExitTransition(null);
getWindow().setReenterTransition(null);
}
interface OnVHClickedListener {
void onVHClicked(AlbumVH vh);
}
static class AlbumVH extends RecyclerView.ViewHolder implements View.OnClickListener {
private final OnVHClickedListener mListener;
#BindView(R.id.album_art)
ImageView albumArt;
public AlbumVH(View itemView, OnVHClickedListener listener) {
super(itemView);
ButterKnife.bind(this, itemView);
itemView.setOnClickListener(this);
mListener = listener;
}
#Override
public void onClick(View v) {
mListener.onVHClicked(this);
}
}
private void populate() {
StaggeredGridLayoutManager lm = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
mAlbumList.setLayoutManager(lm);
final int[] albumArts = {
R.drawable.mean_something_kinder_than_wolves,
R.drawable.cylinders_chris_zabriskie,
R.drawable.broken_distance_sutro,
R.drawable.playing_with_scratches_ruckus_roboticus,
R.drawable.keep_it_together_guster,
R.drawable.the_carpenter_avett_brothers,
R.drawable.please_sondre_lerche,
R.drawable.direct_to_video_chris_zabriskie };
RecyclerView.Adapter adapter = new RecyclerView.Adapter<AlbumVH>() {
#Override
public AlbumVH onCreateViewHolder(ViewGroup parent, int viewType) {
View albumView = getLayoutInflater().inflate(R.layout.album_grid_item, parent, false);
return new AlbumVH(albumView, new OnVHClickedListener() {
#Override
public void onVHClicked(AlbumVH vh) {
int albumArtResId = albumArts[vh.getLayoutPosition() % albumArts.length];
Intent intent = new Intent(AlbumListActivity.this, AlbumDetailActivity.class);
intent.putExtra(AlbumDetailActivity.EXTRA_ALBUM_ART_RESID, albumArtResId);
startActivity(intent);
}
});
}
#Override
public void onBindViewHolder(AlbumVH holder, int position) {
holder.albumArt.setImageResource(albumArts[position % albumArts.length]);
}
#Override
public int getItemCount() {
return albumArts.length * 4;
}
};
mAlbumList.setAdapter(adapter);
}
}
This is the exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jimulabs.googlemusicmock, PID: 30956
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jimulabs.googlemusicmock/com.teamtreehouse.albumcover.AlbumListActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
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: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at com.teamtreehouse.albumcover.AlbumListActivity.populate(AlbumListActivity.java:59)
at com.teamtreehouse.albumcover.AlbumListActivity.onCreate(AlbumListActivity.java:27)
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)
Just a simple solution to this problem is, init your mAlbumLayout and pass it as a parameter in the populate() method. This will prevent it from getting null.
My app is crashing every time, I couldn't find any solution for the issue.
The code is:
package com.example.juan.sem4;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Registrarse extends AppCompatActivity {
EditText txtNom, txtCor, txtPas;
Button btnRegistrarse;
BD_Usuarios bd=new BD_Usuarios(this,"BD1",null,1);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registrarse);
txtNom=(EditText)findViewById(R.id.txtRegNom);
txtCor=(EditText)findViewById(R.id.txtRegCor);
txtPas=(EditText)findViewById(R.id.txtPas);
btnRegistrarse=(Button)findViewById(R.id.btnRegistrarse);
btnRegistrarse.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
bd.abrir();
bd.registrarUsu(txtNom.getText().toString(),txtCor.getText().toString(),txtPas.getText().toString());
bd.cerrar();
txtCor.setText("");
txtNom.setText("");
txtPas.setText("");
txtNom.findFocus();
Toast.makeText(getApplicationContext(),"Se registro con exito",Toast.LENGTH_LONG).show();
finish();
}
});
}
}
The LOGCAT shows the following problem:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.example.juan.sem4.Registrarse$1.onClick(Registrarse.java:32)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
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)
It seems that the issue is on the line 32 which is:
bd.registrarUsu(txtNom.getText().toString(),txtCor.getText().toString(),txtPas.getText().toString());
But honestly I can't see the problem in it.
I'm learning Android Studio and I decided to create a Java class and then call it in MainActivity. However, the app crashes on startup - see below. I just don't understand what the error means. Any thoughts?
MainActivity.java
package com.example.daniel.hamblaster;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
generateText obj = new generateText();
obj.generate();
}
}
Java class:
package com.example.daniel.hamblaster;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class generateText extends AppCompatActivity {
Button myButton = (Button) findViewById(R.id.myButton);
public void generate() {
myButton.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
TextView myText = (TextView) findViewById(R.id.myText);
myText.setText("blablaba");
}
}
);
}
}
Error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.daniel.hamblaster, PID: 5560
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.daniel.hamblaster/com.example.daniel.hamblaster.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:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.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.(AppCompatDelegateImplBase.java:120)
at android.support.v7.app.AppCompatDelegateImplV9.(AppCompatDelegateImplV9.java:151)
at android.support.v7.app.AppCompatDelegateImplV11.(AppCompatDelegateImplV11.java:31)
at android.support.v7.app.AppCompatDelegateImplV14.(AppCompatDelegateImplV14.java:55)
at android.support.v7.app.AppCompatDelegateImplV23.(AppCompatDelegateImplV23.java:33)
at android.support.v7.app.AppCompatDelegateImplN.(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:525)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:193)
at com.example.daniel.hamblaster.generateText.(generateText.java:9)
at com.example.daniel.hamblaster.MainActivity.onCreate(MainActivity.java:14)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Application terminated.
You are trying to make impossible stuff.
Activities are not to be created as an ordinary class.
I can see that you are starting to get a grip of what Java is. Take your time and learn Java basics before running into Android.
For short:
Activities are not to be instantiated with new Activity();
If you are trying to, please, use Intents.
Intent a = new Intent(this, ActivityB.class);
this.startActivity(a);
This is the way to open an activity from another.
And if you REALLY want to just instantiate a class, remove that extension from generateText class and just handle it just like a normal and ordinary class.
You should, as well, check some Java code standards :)
Do never create a Class with lowercase first letter.
Best of luck.
1) If you are working with UI, do it in the activity you are currently in.
2) If you want to start another activity, use:
Intent intent = new Intent(ActivityA.this, ActivityB.class);
startActivity(intent);
3) If you want to execute a method of another class, let it be
public static <return-type> method() {...} in that class. This way you even do not need to initialize you class (make it static too, btw).