Attempt to invoke virtual method java.lang.String com.activeandroid.TableInfo.getIdName() - android

I am trying to copy values of one class1 object to class2 object using active android. I have written a clone function for this. When I instantiate class2 object, I get above mentioned exception. Here is my model
#Table(name = "table_config")
public class ConfigurationForServerSEND extends Model implements Serializable, Cloneable
{
// bunch of variables and getters/setters
}
Whenever I call this clone method, exception gets thrown. Here is the first line of code
ConfigurationForServerSEND config = new ConfigurationForServerSEND();
Here is what I get
class package_name.views.fragments.MyFragment
java.lang.NullPointerException: Attempt to invoke virtual
method 'java.lang.String com.activeandroid.TableInfo.getIdName()'
on a null object reference
at com.activeandroid.Model.<init>(Model.java:55)
Please note that I add this class configuration builder of active android, like this configurationBuilder.addModelClasses(MatchConfigurationForServerSEND.class);
What could be wrong? Why am I getting this exception when trying to instantiate class2 object. It was working yesterday (I use both Android 7, Android 8 with API level 26). Thanks for anything you share.

Related

Android Studio (Kotlin) GsonBuilder.registerTypeAdapter() gives 2 errors

I am using the Kotlin plugin and trying to create a gson variable using GsonBuilder.
This used to work without problems in Java, but now in I get the two errors when trying to use registerTypeAdapter(), as shown below:
val gson = GsonBuilder().registerTypeAdapter(DateTime.class, DateTimeTypeConverter()).create()
For the first parameter (type), I get "name expected" error.
For the second parameter (typeAdapter), I get "expecting an expression" error
DateTime.class should be changed to Date::class.java
Maybe it will resolve your second issue as well, otherwise please post your DateTimeTypeConverter source code
Class References
The most basic reflection feature is getting the runtime reference to
a Kotlin class. To obtain the reference to a statically known Kotlin
class, you can use the class literal syntax:
val c = MyClass::class The reference is a value of type KClass.
Note that a Kotlin class reference is not the same as a Java class
reference. To obtain a Java class reference, use the .java property on
a KClass instance.
Reference: https://kotlinlang.org/docs/reference/reflection.html

XLabs WebView giving Error System.NullReferenceException: Object reference not set to an instance of an object

I'm trying to get the Sample Project
XLabs.Sample.Droid
running on my machine but it gives me the error
System.NullReferenceException: Object reference not set to an instance
of an object
on the following line in MainActivity.OnCreate():
Android.Webkit.WebView.SetWebContentsDebuggingEnabled(true);
The error is thrown somewhere inside the WebView.SetWebContentsDebuggingEnabled Code. What can I do?

Error using getView() with a Listview

I'm am a newbie with Android development and using the following example to do something similar: https://stackoverflow.com/a/11626706/5724649
But am getting the following error: "Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference"when I try to set one of the radio button. Also mSource (which is an ArrayList) is null within getView(), so I see why I could get this error, but not sure as to how I should pass the arraylist to getView(). Please help.
The error is about you calling a method on an object which currently "null".
This will also throw the same error:
String a = null;
a.length(); // <<< This will cause an error, because a is null.
You should make sure the following line:
mSource = new ArrayList<RowObject>();
is running before any of these lines:
mSource.get(position).setFirstChecked(true);
mSource.get(position).setFirstChecked(false);
if (mSource.get(position).isFirstChecked()) {

FindClass and GetMethodID failes on android jni

I have c++ lib used with my application. I passed java object to jni and saved it to global reference. Then, I wish to call method of this java object from jni from antoher thread (I use pthread).
Java class is:
public class WaitingServiceReadyCallback {
public void ready(String serviceName) throws Exception { ... // some code }
}
To call java method I use next code:
jvm->AttachCurrentThread(&env, 0);
cls = env->GetObjectClass(__obj__); // __obj__ is global reference to object.
if (!cls)
goto detach;
mid = env->GetMethodID(cls, "ready", "(Ljava/lang/String;)V");
There GetMethodID fails to find method.
When I use
cls = env->FindClass("com/mypackage/WaitingServiceReadyCallback");
instead of GetObjectClass, FindClass fails to find this class.
I tried to check class name of the object referencd by my __obj__ global reference (used getName from com/java/Class, made call to getName in the same place of my code as above call to ready), I got right class name - com.mypackage.WaitingServiceReadyCallback.
I am sure that class exists and loaded (java code executed before jni and instance of this class is created there), I am sure that method exists in the class.
So, I can't understand, what I done wrong?
I met this problem. The reason in short: within another thread VM does not provide us an info about loaded classes. I've solved this by storing the classloader of some sample java object and then using it for manual loading of needed classes from another threads.

Calling a method from another class in TextToSpeech API

I am using the TextToSpeech API and I want to seperate some logic into another class.
In the separate class I have put the following method:
public static void sayHello() {
// Select a random hello.
int helloLength = SoundGameScore.Questions.length;
String hello = SoundGameScore.Questions[currentHelloIndex];
currentHelloIndex = (currentHelloIndex + 1) % helloLength;
mTts.speak(hello, TextToSpeech.QUEUE_FLUSH, // Drop all pending entries
// in the playback queue.
null);
I have then created a variable in the main class: static mainclass object;
Within a button in the main class I call the method through this object by using:
object.sayHello();
I am quite new to android, and I know I am doing something wrong as this gives me a process closed error in the emulator. This also shows a nullexception error in logcat. Please help me, thanks.
I think you are getting a NullPointerException because the reference object is null. You would need to initialise the object in order to call an instance method on it.
However since sayHello() is a static method, you do not need to create an instance of the class in order to call the method. Just use mainclass.sayHello().
Your question and code suggests to me that you do not have much experience with Java. Perhaps you should do some tutorials to brush up on your Java coding before jumping into Android development. For example, Java convention is for class names to be capitalised (MainClass) and for references to have meaningful names (i.e. not things like object).

Categories

Resources