I am trying to make an app that has several features based off of features of a website I already have. Basically I am creating a companion app. That being said, the app crashes when I press a button on the main page to launch the feature. I have scoured the internet trying every single solution I could find but so far none have worked. The strange part is that it works as long as there is no additional code except for code generated upon creating the class.
Here is my Main Activity:
package com.example.nicole.signal;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import com.example.nicole.signal.R;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Button Calls
Button forumbtn = (Button) findViewById(R.id.forum_btn);
forumbtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View view)
{
startActivity(new Intent(MainActivity.this, ForumActivity.class));
}
});
Button webbtn = (Button) findViewById(R.id.Web_btn);
webbtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View view)
{
startActivity(new Intent(MainActivity.this, WebActivity.class));
}
});
Button chatbtn = (Button) findViewById(R.id.Chat_btn);
chatbtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View view)
{
startActivity(new Intent(MainActivity.this, ChatActivity.class));
}
});
Button videobtn = (Button) findViewById(R.id.Video_btn);
videobtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View view)
{
startActivity(new Intent(MainActivity.this, VideoActivity.class));
}
});
}
@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 one of the classes I am calling that crash:
package com.example.nicole.signal;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class WebActivity extends MainActivity
{
private final WebView mWebView = (WebView) findViewById(R.id.activity_web);
@Override
protected void onCreate(Bundle savedInstanceState) {
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(true);
Uri uri = Uri.parse("http://hnsignal.ca");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
}
}
here is the logcat error :
02-26 17:33:37.895 29086-29086/? E/Zygote: MountEmulatedStorage()
02-26 17:33:37.895 29086-29086/? E/Zygote: v2
02-26 17:33:37.915 29086-29086/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
02-26 17:33:48.976 29086-29086/com.example.nicole.signal E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.nicole.signal, PID: 29086
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.nicole.signal/com.example.nicole.signal.WebActivity}: 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:2546)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
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.AppCompatDelegate.create(AppCompatDelegate.java:205)
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 com.example.nicole.signal.WebActivity.<init>(WebActivity.java:14)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1650)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2536)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Any help would be greatly appreciated. During build no errors are thrown up so i imagine it is somewhere in my code... i just cant find it. Thank you