i am working on Android project in Android Studio 1.1.0 and i can't pass the message to the handler with Bundle class.
Well, this is my code
...
Bundle mUIMessageBundle = new Bundle(newUser.getName());
mUIMessageBundle.putInt("Name", newUser.getName());
mUIMessageBundle.putString("Tag", null);
handler.sendMessage(new android.os.Message());
...
The newUser is well defined but i have a problem on putInt and putString methods. Those methods execute well, but when i read the message in handler getInt and getString return null. So i debugged a bit and the attached pic will show you the problem. Value-key pairs are added, but on their value places are exceptions like this:
java.lang.ClassNotFoundException: Didn't find class "Object" on path: DexPathList[[zip file "/data/app/com.example.mile.voicenc-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.mile.voicenc-1, /vendor/lib, /system/lib]]
I have researched a lot, but i cannot find the solution...
All suggestions will be great, thanks!
Edit 1:
Finally i tried to open whole new blank project and i added two lines for intent init:
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent("make.your.own.intent");
intent.putExtra("Name", "asd");
}
...
And this code in blank project returned exactly the same exception. It makes me go insane...
Any ideas? Thanks
It doesn't look like you're actually attaching the bundle to the message before sending it. Also, call Handler.obtainMessage() to get a message, don't create it with new:
Bundle mUIMessageBundle = new Bundle(newUser.getName());
mUIMessageBundle.putInt("Name", newUser.getName());
mUIMessageBundle.putString("Tag", null);
Message msg = handler.obtainMessage(); // get a message
// msg.what = 1; // set type of message
msg.setData(mUIMessageBundle); // attach bundle
handler.sendMessage(msg);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With