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++) {
....
....
}
Related
I wrote some code for removing items from a recycler view objects. That is inside an array list
It works until the size and the index become equal or index become bigger. I really can't find the problem
public void deleteSelectedItems(){
if (selectedItemList.size() < 1)
return;
for(int i = 0 ; i < selectedItemList.size() ; i++){
int index = selectedItemList.get(i) ;
Log.e("AAA",index + "");
guitaristsList.remove(index);
}
selectedItemList.clear();
notifyDataSetChanged();
}
public void onClick(View v) {
if (isOnActionMode) {
if (chxDelete.isChecked())
selectedItemList.add(getAdapterPosition());
else
selectedItemList.remove((Object)getAdapterPosition());
if (onCheckboxClickListener != null)
onCheckboxClickListener.onCheckboxCheckedChanged(selectedItemList.size());
}
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.amehrvarz.mycontextual, PID: 12492
java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
at java.util.ArrayList.remove(ArrayList.java:503)
at com.amehrvarz.mycontextual.GuitaristAdapter.deleteSelectedItems(GuitaristAdapter.java:120)
at com.amehrvarz.mycontextual.MainActivity$3.onActionItemClicked(MainActivity.java:71)
at androidx.appcompat.app.AppCompatDelegateImpl$ActionModeCallbackWrapperV9.onActionItemClicked(AppCompatDelegateImpl.java:2452)
at androidx.appcompat.app.WindowDecorActionBar$ActionModeImpl.onMenuItemSelected(WindowDecorActionBar.java:1123)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:981)
at androidx.appcompat.widget.ActionMenuView.invokeItem(ActionMenuView.java:625)
at androidx.appcompat.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:151)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process: Sending signal. PID: 12492 SIG: 9
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 following class
public class Settings extends RealmObject {
private String something;
}
I want to add the following field
public class AndroidBuild extends RealmObject {
int one;
int two;
}
so it looks like
public class Settings extends RealmObject {
private String something;
private AndroidBuild androidBuild;
}
So, my migration looks like
if (oldVersion == 1) {
RealmObjectSchema settingsSchema = schema.get("Settings");
RealmObjectSchema androidBuildSchema = schema.get("AndroidBuild");
if (settingsSchema != null) {
settingsSchema.addRealmObjectField("androidBuild", androidBuildSchema);
oldVersion++;
}
}
and it crashes
07-11 15:05:06.384 9046-9046/com.cassby.terminal.cassby E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cassby.terminal.cassby, PID: 9046
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cassby.terminal.cassby/com.cassby.terminal.cassby.UserStories.Launch.LaunchActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String io.realm.RealmObjectSchema.getClassName()' 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 'java.lang.String io.realm.RealmObjectSchema.getClassName()' on a null object reference
at io.realm.MutableRealmObjectSchema.addRealmObjectField(MutableRealmObjectSchema.java:126)
at com.cassby.terminal.cassby.Services.Database.RealmMigrations.migrate(RealmMigrations.java:36)
at io.realm.BaseRealm$6.onMigrationNeeded(BaseRealm.java:714)
at io.realm.internal.OsSharedRealm.runMigrationCallback(OsSharedRealm.java:520)
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Native Method)
at io.realm.internal.OsSharedRealm.<init>(OsSharedRealm.java:184)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:254)
at io.realm.BaseRealm.<init>(BaseRealm.java:124)
at io.realm.BaseRealm.<init>(BaseRealm.java:93)
at io.realm.Realm.<init>(Realm.java:153)
at io.realm.Realm.createInstance(Realm.java:424)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:342)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:282)
at io.realm.Realm.getDefaultInstance(Realm.java:332)
at com.cassby.terminal.cassby.UserStories.Launch.LaunchActivity.resolveStartingActivity(LaunchActivity.java:35)
at com.cassby.terminal.cassby.UserStories.Launch.LaunchActivity.onCreate(LaunchActivity.java:29)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
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)
What am I doing wrong ?
You need to add Table first, so
Realm.setDefaultConfiguration(new RealmConfiguration.Builder()
.name(DB_NAME)
.schemaVersion(SCHEMA_VERSION)
.migration((realm, oldVersion, newVersion) -> {
RealmSchema schema = realm.getSchema();
if (oldVersion == OLD_VERSION) {
schema.create("AndroidBuild")
.addField("one", int.class)
.addField("two", int.class);
schema.get("Settings")
.addRealmObjectField("androidBuild", schema.get("AndroidBuild"))
oldVersion++;
}
})
);
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)
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);
}
}