so im doing a school project on a movie review app. so heres my code for the next and previous button. The next button works fine without crashing. when i press back it works but once it reaches the very first movie and i press back again the app crashes.
private Movie movies[]= new Movie[5];
public MovieCollection(){
prepareMovies();
}
public Movie searchById(String id){
Movie movie = null;
for(int index=0; index < movies.length; index++){
movie = movies[index];
if(movie.getId().equals(id)){
return movie;
}
}
return movie;
}
public Movie getNextMovie(String currentMovieId){
Movie movie = null;
for(int index = 0; index < movies.length; index++) {
String tempMovieId = movies[index].getId();
if (tempMovieId.equals(currentMovieId) && (index < movies.length - 1)) {
movie = movies[index + 1];
break;
}
}
return movie;
}
public Movie getPrevMovie(String currentMovieId){
Movie movie = null;
for(int index = 0; index < movies.length; index++){
String tempMovieId = movies[index].getId();
if(tempMovieId.equals(currentMovieId) && (index > 0)){
movie = movies[index - 1];
break;
}
}
return movie;
}
my code for the button.
public void goNext(View view){
Movie nextMovie = movieCollection.getNextMovie(movieId);
if(nextMovie != null){
movieId = nextMovie.getId();
title = nextMovie.getTitle();
plot = nextMovie.getPlot();
movieArt = nextMovie.getMovieArt();
rating = nextMovie.getRating();
review1 = nextMovie.getReview1();
review2 = nextMovie.getReview2();
displayMovie(title , plot, movieArt, rating, review1, review2);
}
}
public void goPrevious(View view){
Movie prevMovie = movieCollection.getPrevMovie(movieId);
if (prevMovie != null){
movieId = prevMovie.getId();
title = prevMovie.getTitle();
plot = prevMovie.getPlot();
movieArt = prevMovie.getMovieArt();
rating = prevMovie.getRating();
review1 = prevMovie.getReview1();
review2 = prevMovie.getReview2();
displayMovie(title , plot, movieArt, rating, review1, review2);
}
}
error report can anyone tell me what is wrong with my code. thanks
07-06 14:19:36.635 3782-3782/com.example.growt.lucascomt E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.growt.lucascomt, PID: 3782
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.view.View$DeclaredOnClickListener.onClick(View.java:4452)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.growt.lucascomt.Movie.getId()' on a null object reference
at com.example.growt.lucascomt.MovieCollection.getPrevMovie(MovieCollection.java:38)
at com.example.growt.lucascomt.MovieInfo.goPrevious(MovieInfo.java:86)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Related
I have different tables according to the level the user is in, my code should set the rows of every active table to Visible. So if the user is in level 5, all rows are set as visible until we reach the tablelevel5. The problem is that when I get the row whit getChildAt I get a NullPointerException. Why is that?
for (int i = 0; i<=sharedPreferences.getInt("tableCurrentNumber",1); i++){
for (int n = 1; i <= verticalLayout.getChildCount(); n++){
String tableID = "tableLevel" + Integer.toString(n);
int resID = getResources().getIdentifier(tableID, "id", getPackageName());
tableFor = ((TableLayout) findViewById(resID));
for (int z = 1; z<=tableFor.getChildCount(); z++){
tableFor.getChildAt(z).setVisibility(View.VISIBLE);
}
}
}
logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.root.exercicis/com.example.root.exercicis.SettingsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.TableLayout.getChildCount()' 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 'int android.widget.TableLayout.getChildCount()' on a null object reference
at com.example.root.exercicis.SettingsActivity.onCreate(SettingsActivity.java:200)
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)
your for loop starts with 1 , it should start with 0
for (int z = 0; z < tableFor.getChildCount(); z++){
tableFor.getChildAt(z).setVisibility(View.VISIBLE);
}
for (int n = 0; i < verticalLayout.getChildCount(); n++){
}
This is for app android, running Android studio, db realm and sql server. i need help
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_employee);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
realm = Realm.getDefaultInstance();
preferences = getSharedPreferences(PREFS_LOGIN, Context.MODE_PRIVATE);
recyclerView = findViewById(R.id.recyclerview);
singleItem = new ArrayList<>();
RealmResults<MdtmMandoranEmployeeDetail> resultEmployeeDetails = realm.where(MdtmMandoranEmployeeDetail.class)
.findAll().sort("employeename");
adapterListPemanen = new AdapterListPemanen(this, singleItem, this);
initVerticalRecycler();
for (int i = 0; i < 50; i++) {
DataPemanen data = realm.where(DataPemanen.class)
.equalTo("nik", resultEmployeeDetails.get(i).getEmployeeid())
.findFirst();
if (data == null) {
singleItem.add(new MdtmMandoranEmployeeDetail(resultEmployeeDetails.get(i).getMandoranemployeeid(),
resultEmployeeDetails.get(i).getEmployeeid(),
resultEmployeeDetails.get(i).getEmployeename()));
}
}
}
Error Log
E/REALM_JNI: jni: ThrowingException 2, Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0), .
Exception has been thrown: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hpi.android.bkm, PID: 16623
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hpi.android.bkm/com.hpi.android.bkm.ui.main.input_pengiriman_hasil_panen.ListEmployeeActivity}: java.lang.ArrayIndexOutOfBoundsException: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2805)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
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:857)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
at io.realm.internal.OsResults.nativeGetRow(Native Method)
at io.realm.internal.OsResults.getUncheckedRow(OsResults.java:325)
at io.realm.OrderedRealmCollectionImpl.get(OrderedRealmCollectionImpl.java:124)
at io.realm.RealmResults.get(RealmResults.java:62)
at com.hpi.android.bkm.ui.main.input_pengiriman_hasil_panen.ListEmployeeActivity.onCreate(ListEmployeeActivity.java:64)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
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:857)
You for loop should be,
for (int i = 0; i < resultEmployeeDetails.size(); i++) {
....
....
}
I want to predict hand written words using pre-trained model which is trained using CNN and RNN Combination. offline handwritten words recognizer without using server.
public void pickImage(View view) {
bitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.img1);
img.setImageBitmap(bitmap);
Toast.makeText(getApplicationContext(),"Width:- "+bitmap.getWidth()+" Height "+bitmap.getHeight(),Toast.LENGTH_SHORT).show();
convertBitmapToByte();
}
private void convertBitmapToByte()
{
if (mdata == null)
{
Toast.makeText(getApplicationContext(),"Return",Toast.LENGTH_SHORT).show();
return;
}
mdata.rewind();
bitmap.getPixels(getPixels,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
int pixel =0;
for(int i=0;i<748;++i)
{
for(int j=0;j<294;++j)
{
final int val = getPixels[pixel++];
mdata.putFloat(convertToGreyScale(val));
}
}
}
private float convertToGreyScale(int colour)
{
return (((colour >> 16) & 0xFF)+((colour >>8) & 0xFF)+((colour & 0xFF)))/3.0f/255.0f;
}
public void predAndSet(View view) {
tv.setText("Temp");
if(mdata == null)
{
Toast.makeText(getApplicationContext(),"Return",Toast.LENGTH_SHORT).show();
return;
}
interpreter.run(mdata,mResult);
tv.setText(Arrays.toString(mResult[0]));
}
}
Stacktrace
Process: com.soham.s.charrecongizer, PID: 29211
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6669)
at android.view.View.performClickInternal(View.java:6638)
at android.view.View.access$3100(View.java:789)
at android.view.View$PerformClick.run(View.java:26145)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6669)
at android.view.View.performClickInternal(View.java:6638)
at android.view.View.access$3100(View.java:789)
at android.view.View$PerformClick.run(View.java:26145)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.tensorflow.lite.Interpreter.run(java.lang.Object, java.lang.Object)' on a null object reference
at com.soham.s.charrecongizer.MainActivity.predAndSet(MainActivity.java:103)
I want to see the text in the image to be predicted and to be shown in a textbox
I have a problem when I try to delete elements on an arrayList. I need to put some elements on other array and then delete this elements from the original array. I put the code below:
private void setOrderAnswers(int position) {
for (int i = 0; i < 4; i++) {
listAnswersAux.add(listAnswers.get((position * 4) + i));
}
for (int i = 0; i < 4; i++) {
listAnswers.remove((position * 4) + i);
}
}
The error I have is an IndexOutOfBounds exception:
Caused by: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
I don't know why I have this exception when I try to remove this index, but when I go to the index to copy the element, there is no problem. I mean, the index is OK because I can see the element before delete it.
And I always have the exception on Index value = 10, I can do all this operations before going to index=10 (position = 2).
Can anyone helps me? Thanks a lot!
06-14 09:58:58.455 31337-31337/com.prodintec.am_motion E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.prodintec.am_motion, PID: 31337
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.prodintec.am_motion/com.prodintec.am_motion.QuizActivity}: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
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.IndexOutOfBoundsException: Index: 10, Size: 10
at java.util.ArrayList.get(ArrayList.java:411)
at com.prodintec.am_motion.QuizActivity.setOrderAnswers(QuizActivity.java:201)
at com.prodintec.am_motion.QuizActivity.randomQuestions(QuizActivity.java:168)
at com.prodintec.am_motion.QuizActivity.onCreate(QuizActivity.java:48)
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)
try this
private void setOrderAnswers(int position) {
for (int i = 0; i < 4; i++) {
listAnswersAux.add(listAnswers.get((position * 4) + i));
listAnswers.remove((position * 4) + i);
}
}
I have Firebase fully installed into Android Studio, and I've tested it with a couple 1 activity applications, but on the only application with more than one activity, it's not working.
When I try to do the following in my 'Sign up' code:
private void makeStudent(String email, String password) {
Student s = new Student(email, password);
Firebase ref = new Firebase("MYAPP.firebaseio.com/");
//took out my app name
Firebase studentlocation = ref.child("Student");
studentlocation.setValue(s); //this is the line on which I get the error
//also, when I go on my firebase site, it hasn't created the Student
//directory
}
The Firebase page said:
If your Android app has multiple activities, add this code to your Application Class. Otherwise add it in your main activity.
So, I looked around, and this is what I created:
I made a MyApplication.java file, which contained:
import com.firebase.client.Firebase;
public class MyApplication extends android.app.Application {
#Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this);
}
}
Then I placed the following into AndroidManifest.xml:
android:name=".MyApplication"
Yet, I still receive an error on the exact same line.
How do I fix this Firebase issue? I appreciate any help I can get, please!
ERROR RECEIVED (scroll to the right in the code box):
FATAL EXCEPTION: main
Process: professionalgrader.professionalgrader, PID: 3827
com.firebase.client.FirebaseException: Failed to parse to snapshot
at com.firebase.client.Firebase.setValueInternal(Firebase.java:347)
at com.firebase.client.Firebase.setValue(Firebase.java:238)
at professionalgrader.professionalgrader.SignUp.makeStudent(SignUp.java:94)
at professionalgrader.professionalgrader.SignUp.access$500(SignUp.java:16)
at professionalgrader.professionalgrader.SignUp$1.onClick(SignUp.java:45)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Caused by: java.lang.IllegalArgumentException: length=0; index=0 (through reference chain: professionalgrader.professionalgrader.Student["listofTermClasses"])
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2615)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2542)
at com.firebase.client.Firebase.setValueInternal(Firebase.java:336)
at com.firebase.client.Firebase.setValue(Firebase.java:238)
at professionalgrader.professionalgrader.SignUp.makeStudent(SignUp.java:94)
at professionalgrader.professionalgrader.SignUp.access$500(SignUp.java:16)
at professionalgrader.professionalgrader.SignUp$1.onClick(SignUp.java:45)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: length=0; index=0 (through reference chain: professionalgrader.professionalgrader.Student["listofTermClasses"])
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:184)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:605)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:142)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:118)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2593)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2542)
at com.firebase.client.Firebase.setValueInternal(Firebase.java:336)
at com.firebase.client.Firebase.setValue(Firebase.java:238)
at professionalgrader.professionalgrader.SignUp.makeStudent(SignUp.java:94)
at professionalgrader.professionalgrader.SignUp.access$500(SignUp.java:16)
at professionalgrader.professionalgrader.SignUp$1.onClick(SignUp.java:45)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at professionalgrader.professionalgrader.Student.getListofTermClasses(Student.java:252)
at java.lang.reflect.Method.invoke(Native Method)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:679)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:534)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:597)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:142)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:118)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2593)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2542)
at com.firebase.client.Firebase.setValueInternal(Firebase.java:336)
at com.firebase.client.Firebase.setValue(Firebase.java:238)
at professionalgrader.professionalgrader.SignUp.makeStudent(SignUp.java:94)
at professionalgrader.professionalgrader.SignUp.access$500(SignUp.java:16)
at professionalgrader.professionalgrader.SignUp$1.onClick(SignUp.java:45)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
THE SECOND ERROR:
06-15 04:13:34.902 3089-3089/professionalgrader.professionalgrader E/AndroidRuntime: FATAL EXCEPTION: main
Process: professionalgrader.professionalgrader, PID: 3089
com.firebase.client.FirebaseException: Failed to parse to snapshot
at com.firebase.client.Firebase.setValueInternal(Firebase.java:347)
at com.firebase.client.Firebase.setValue(Firebase.java:238)
at professionalgrader.professionalgrader.SignUp.makeStudent(SignUp.java:94)
at professionalgrader.professionalgrader.SignUp.access$500(SignUp.java:16)
at professionalgrader.professionalgrader.SignUp$1.onClick(SignUp.java:45)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Caused by: java.lang.IllegalArgumentException: Attempt to invoke virtual method 'double professionalgrader.professionalgrader.Class.getGPA()' on a null object reference (through reference chain: professionalgrader.professionalgrader.Student["totalGPA"])
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2615)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2542)
at com.firebase.client.Firebase.setValueInternal(Firebase.java:336)
at com.firebase.client.Firebase.setValue(Firebase.java:238)
at professionalgrader.professionalgrader.SignUp.makeStudent(SignUp.java:94)
at professionalgrader.professionalgrader.SignUp.access$500(SignUp.java:16)
at professionalgrader.professionalgrader.SignUp$1.onClick(SignUp.java:45)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Attempt to invoke virtual method 'double professionalgrader.professionalgrader.Class.getGPA()' on a null object reference (through reference chain: professionalgrader.professionalgrader.Student["totalGPA"])
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:184)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:605)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:142)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:118)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2593)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2542)
at com.firebase.client.Firebase.setValueInternal(Firebase.java:336)
at com.firebase.client.Firebase.setValue(Firebase.java:238)
at professionalgrader.professionalgrader.SignUp.makeStudent(SignUp.java:94)
at professionalgrader.professionalgrader.SignUp.access$500(SignUp.java:16)
at professionalgrader.professionalgrader.SignUp$1.onClick(SignUp.java:45)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double professionalgrader.professionalgrader.Class.getGPA()' on a null object reference
at professionalgrader.professionalgrader.Student.getTotalGPA(Student.java:199)
at java.lang.reflect.Method.invoke(Native Method)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:679)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:534)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:597)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:142)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:118)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2593)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2542)
at com.firebase.client.Firebase.setValueInternal(Firebase.java:336)
at com.firebase.client.Firebase.setValue(Firebase.java:238)
at professionalgrader.professionalgrader.SignUp.makeStudent(SignUp.java:94)
at professionalgrader.professionalgrader.SignUp.access$500(SignUp.java:16)
at professionalgrader.professionalgrader.SignUp$1.onClick(SignUp.java:45)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
Possible source of error because it told me it couldn't obtain the Snapshot at the line in makeStudent(), but makeStudent() doesn't use Snapshot. Only userExists() does. Note: The variable 'exists' is defined as a static boolean in the SignUp class.
private boolean userExists() {
Firebase ref = new Firebase("MYAPPNAME.firebaseio.com");
ref.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapShot: snapshot.getChildren()) {
Student s = postSnapShot.getValue(Student.class);
if(s.getEmail().equals(mEmailView.getText().toString())) {
exists = true;
}
}
}
#Override
public void onCancelled(FirebaseError firebaseError) {
exists = true;
}
});
return exists;
}
SOLUTION TO MY ISSUE:
I realized that Snapshot was never used in makeStudent(), and that was where the error started. Thus, I looked in the only place it was used... userExists(), and it turned out that I was correct! The error was produced by trying to identify Student s as a nonexistent student! Thus, I actually needed a try like such:
private boolean userExists() {
Firebase ref = new Firebase("MYAPPNAME.firebaseio.com");
ref.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot snapshot) {
Student s;
for (DataSnapshot postSnapShot: snapshot.getChildren()) {
try {
s = postSnapShot.getValue(Student.class);
if(s.getEmail().equals(mEmailView.getText().toString())) {
System.out.println(snapshot.getValue());
exists = true;
}
} catch(Exception e) {
exists = false;
}
}
}
#Override
public void onCancelled(FirebaseError firebaseError) {
exists = true;
}
});
return exists;
}