This is the log when I run the app on the emulator, I'm new to app development can someone please help? Ill post the code if needed but its divided into multiple activities.
10-17 08:45:43.269 2696-2696/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
10-17 08:45:43.269 2696-2696/? I/art﹕ Late-enabling JIT
10-17 08:45:43.273 2696-2696/? I/art﹕ JIT created with code_cache_capacity=2MB compile_threshold=1000
10-17 08:45:43.304 2696-2696/? W/System﹕ ClassLoader referenced unknown path: /data/app/com.victorioussecrets.nwureferencegenerator-2/lib/x86
10-17 08:45:43.427 2696-2696/com.victorioussecrets.nwureferencegenerator D/AndroidRuntime﹕ Shutting down VM
10-17 08:45:43.427 2696-2696/com.victorioussecrets.nwureferencegenerator E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.victorioussecrets.nwureferencegenerator, PID: 2696
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.victorioussecrets.nwureferencegenerator/com.victorioussecrets.nwureferencegenerator.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: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 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.victorioussecrets.nwureferencegenerator.MainActivity.onCreate(MainActivity.java:31)
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)
10-17 08:45:47.140 2696-2696/? I/Process﹕ Sending signal. PID: 2696 SIG: 9
I've fixed the null error and this is now the new log afterwards.
10-17 09:28:23.871 3195-3195/com.victorioussecrets.nwureferencegenerator E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.victorioussecrets.nwureferencegenerator, PID: 3195
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.widget.Spinner.getSelectedItem()' on a null object reference
at com.victorioussecrets.nwureferencegenerator.MainActivity.onItemSelected(MainActivity.java:70)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:922)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:911)
at android.widget.AdapterView.-wrap1(AdapterView.java)
at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:881)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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)
Here is my MainActivity.java
package com.victorioussecrets.nwureferencegenerator;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
Spinner spinnerStyles;
Button btnExit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnExit = (Button)findViewById(R.id.btnExit);
Spinner spinner = (Spinner)findViewById(R.id.spinnerStyles);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.arrStyles,android.R.layout.simple_spinner_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
btnExit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
@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);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String spinVal = "";
spinVal = spinnerStyles.getSelectedItem().toString();
if(spinVal.equals("NWU Harvard")) {
startActivity(new Intent(MainActivity.this, nwu_harvard.class));
}
if(spinVal.equals("LAW")) {
startActivity(new Intent(MainActivity.this, law.class));
}
if(spinVal.equals("APA")) {
startActivity(new Intent(MainActivity.this, apa.class));
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
My last error when i run the app and get to nwu_harvard_book.java activity i don't get a crash or error, but when i try the nwu_harvard_article.java activity i get this error.
10-17 10:35:42.499 28256-28256/com.victorioussecrets.nwureferencegenerator E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.victorioussecrets.nwureferencegenerator, PID: 28256
java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.victorioussecrets.nwureferencegenerator.nwu_harvard_article$2.onClick(nwu_harvard_article.java:43)
at android.view.View.performClick(View.java:5156)
at android.view.View$PerformClick.run(View.java:20755)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
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)
This is the first nwu_harvard_book activity package com.victorioussecrets.nwureferencegenerator;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class nwu_harvard_book extends AppCompatActivity {
Button btnBack,btnGenerate;
String stringf= "",value1= "",value3= "",value2= "",value4= "",value5= "";
EditText inputTxt = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nwu_harvard_book);
btnGenerate = (Button) findViewById(R.id.btngenerate);
btnBack = (Button) findViewById(R.id.btnBack);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
btnGenerate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
inputTxt = (EditText) findViewById(R.id.edtAuthor);
value1 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtTitle);
value2 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtDate);
value3 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtEdition);
value4 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtTown);
value5 = inputTxt.getText().toString();
stringf = (value1+". "+value3+". "+value2+". "+value4+". "+value5+".");
Intent intent = new Intent(nwu_harvard_book.this, output.class);
intent.putExtra("output", stringf);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.nwu_harvard_book, 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);
}
}
This is the second nwu_harvard_article activity
package com.victorioussecrets.nwureferencegenerator;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class nwu_harvard_article extends AppCompatActivity {
Button btnBack,btnGenerate;
String stringf= "",value1= "",value3= "",value2= "",value4= "",value5= "",value6= "";
EditText inputTxt = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nwu_harvard_book);
btnGenerate = (Button) findViewById(R.id.btngenerate);
btnBack = (Button) findViewById(R.id.btnBack);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
btnGenerate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
inputTxt = (EditText) findViewById(R.id.edtAuthor);
value1 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtTitle);
value2 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtDate);
value3 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtpages);
value4 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtmagtitle);
value5 = inputTxt.getText().toString();
inputTxt = (EditText) findViewById(R.id.edtVolume);
value6 = inputTxt.getText().toString();
stringf = (value1+". "+value3+". "+value2+" "+value5+". "+value6+".");
Intent intent = new Intent(nwu_harvard_article.this, output.class);
intent.putExtra("output", stringf);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.nwu_harvard_book, 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);
}
}