error "unable to instantiate activity" [closed] - android

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I know there are many people who have the problem. I've tried many ways I can find, however still get the error.
there's only one activity and it's registered.
tried to complete .MainActivity by com.hermione.woodenfish.MainActivity, no use
clean and rebuild don't work either
really need help, thanks!!
LogCat:
08-01 12:09:33.944: E/Trace(1032): error opening trace file: No such file or directory (2)
08-01 12:09:34.384: D/AndroidRuntime(1032): Shutting down VM
08-01 12:09:34.424: W/dalvikvm(1032): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08-01 12:09:34.465: E/AndroidRuntime(1032): FATAL EXCEPTION: main
08-01 12:09:34.465: E/AndroidRuntime(1032): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hermione.woodenfish/com.hermione.woodenfish.MainActivity}: java.lang.NullPointerException
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.os.Looper.loop(Looper.java:137)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-01 12:09:34.465: E/AndroidRuntime(1032): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 12:09:34.465: E/AndroidRuntime(1032): at java.lang.reflect.Method.invoke(Method.java:511)
08-01 12:09:34.465: E/AndroidRuntime(1032): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-01 12:09:34.465: E/AndroidRuntime(1032): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-01 12:09:34.465: E/AndroidRuntime(1032): at dalvik.system.NativeStart.main(Native Method)
08-01 12:09:34.465: E/AndroidRuntime(1032): Caused by: java.lang.NullPointerException
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.media.MediaPlayer.create(MediaPlayer.java:824)
08-01 12:09:34.465: E/AndroidRuntime(1032): at com.hermione.woodenfish.MainActivity.<init>(MainActivity.java:24)
08-01 12:09:34.465: E/AndroidRuntime(1032): at java.lang.Class.newInstanceImpl(Native Method)
08-01 12:09:34.465: E/AndroidRuntime(1032): at java.lang.Class.newInstance(Class.java:1319)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
08-01 12:09:34.465: E/AndroidRuntime(1032): ... 11 more
08-01 12:33:02.784: E/Trace(1171): error opening trace file: No such file or directory (2)
08-01 12:33:03.125: D/AndroidRuntime(1171): Shutting down VM
08-01 12:33:03.125: W/dalvikvm(1171): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08-01 12:33:03.154: E/AndroidRuntime(1171): FATAL EXCEPTION: main
08-01 12:33:03.154: E/AndroidRuntime(1171): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hermione.woodenfish/com.hermione.woodenfish.MainActivity}: java.lang.NullPointerException
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.os.Looper.loop(Looper.java:137)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.reflect.Method.invoke(Method.java:511)
08-01 12:33:03.154: E/AndroidRuntime(1171): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-01 12:33:03.154: E/AndroidRuntime(1171): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-01 12:33:03.154: E/AndroidRuntime(1171): at dalvik.system.NativeStart.main(Native Method)
08-01 12:33:03.154: E/AndroidRuntime(1171): Caused by: java.lang.NullPointerException
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.media.MediaPlayer.create(MediaPlayer.java:824)
08-01 12:33:03.154: E/AndroidRuntime(1171): at com.hermione.woodenfish.MainActivity.<init>(MainActivity.java:23)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.Class.newInstanceImpl(Native Method)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.Class.newInstance(Class.java:1319)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
08-01 12:33:03.154: E/AndroidRuntime(1171): ... 11 more
MainActivity.java
package com.hermione.woodenfish;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private MediaPlayer mp = MediaPlayer.create(this, R.raw.knok);
public void sendKnok(View view) {
if (mp.isPlaying()){
mp.stop();
}
mp.start();
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hermione.woodenfish"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

I think the problem is here in this line,
private MediaPlayer mp = MediaPlayer.create(this, R.raw.knok);
You have tried to initialize the Context object before the onCreate(). This might be creating the problem. How about you Initialize your MediaPlayer inside your onCreate(),
private MediaPlayer mp =null; //Global Declaration
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mp = MediaPlayer.create(this, R.raw.knok);
}

Your problem is here:
08-01 12:33:03.154: E/AndroidRuntime(1171): Caused by: java.lang.NullPointerException
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.media.MediaPlayer.create(MediaPlayer.java:824)
08-01 12:33:03.154: E/AndroidRuntime(1171): at com.hermione.woodenfish.MainActivity.<init>(MainActivity.java:23)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.Class.newInstanceImpl(Native Method)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.Class.newInstance(Class.java:1319)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
08-01 12:33:03.154: E/AndroidRuntime(1171): ... 11 more
You're getting a NullPointerException. Look at line 23 in MainActivity in debug and see what's happening.

Related

android arduino usb communication

I'm trying to establish communication between Arduino UNO R3 and Galaxy SII on Android 4.1 cross usb. The code sample i am following i here: http://androidgurusolutions.blogspot.com/2012/07/arduino-adk-board-blink-led-with-your.html . Unfortunately, i am getting this message 'app has stopped' and here is LogCat error
LogCat:
E/AndroidRuntime(535): FATAL EXCEPTION: main
E/AndroidRuntime(535): java.lang.NoClassDefFoundError: com.android.future.usb.UsbManager
E/AndroidRuntime(535): at com.example.mypro.MainActivity.onCreate(MainActivity.java:123)
E/AndroidRuntime(535): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(535): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
E/AndroidRuntime(535): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime(535):at android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime(535):at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime(535):at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(535):at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(535):at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(535):at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(535):at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(535):at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(535):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(535):at dalvik.system.NativeStart.main(Native Method)
please can anybody help me. thanks in advance.....

IBM Worklight 5.x - Android app stops and terminates unexpectedly

I have tried to develop a test application using Worklight for the Android environment. When I run the app using an AVD it throws an error message like:
"Sorry The application Test (process com.AccorFintech) has stopped
unexpectedly. Please try again."
and the application terminates.
I am using Eclipse 4.2 and android version for AVD is Android 2.2.
Here Is My Logcat:
07-01 16:19:33.510: W/dalvikvm(403): Unable to resolve superclass of Lcom/AccordFintech/AccordFintech; (12)
07-01 16:19:33.510: W/dalvikvm(403): Link of class 'Lcom/AccordFintech/AccordFintech;' failed
07-01 16:19:33.540: D/AndroidRuntime(403): Shutting down VM
07-01 16:19:33.540: W/dalvikvm(403): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-01 16:19:33.570: E/AndroidRuntime(403): FATAL EXCEPTION: main
07-01 16:19:33.570: E/AndroidRuntime(403): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.AccordFintech/com.AccordFintech.AccordFintech}: java.lang.ClassNotFoundException: com.AccordFintech.AccordFintech in loader dalvik.system.PathClassLoader[/data/app/com.AccordFintech-2.apk]
07-01 16:19:33.570: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
07-01 16:19:33.570: E/AndroidRuntime(403): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-01 16:19:33.570: E/AndroidRuntime(403): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-01 16:19:33.570: E/AndroidRuntime(403): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-01 16:19:33.570: E/AndroidRuntime(403): at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 16:19:33.570: E/AndroidRuntime(403): at android.os.Looper.loop(Looper.java:123)
07-01 16:19:33.570: E/AndroidRuntime(403): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-01 16:19:33.570: E/AndroidRuntime(403): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 16:19:33.570: E/AndroidRuntime(403): at java.lang.reflect.Method.invoke(Method.java:521)
07-01 16:19:33.570: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-01 16:19:33.570: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-01 16:19:33.570: E/AndroidRuntime(403): at dalvik.system.NativeStart.main(Native Method)
07-01 16:19:33.570: E/AndroidRuntime(403): Caused by: java.lang.ClassNotFoundException: com.AccordFintech.AccordFintech in loader dalvik.system.PathClassLoader[/data/app/com.AccordFintech-2.apk]
07-01 16:19:33.570: E/AndroidRuntime(403): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-01 16:19:33.570: E/AndroidRuntime(403): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-01 16:19:33.570: E/AndroidRuntime(403): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-01 16:19:33.570: E/AndroidRuntime(403): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-01 16:19:33.570: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
07-01 16:19:33.570: E/AndroidRuntime(403): ... 11 more
Are you using ADT v22?
See if this helps you: IBM Worklight - "Unfortunately, HelloWorkLight has stopped" error message
Right-click on the native Android project in Worklight Studio
and choose 'Properties'.
Select 'Java Build Path' and go to the 'Order and Export'
tab.
Mark the check-box for 'Android Private Libraries'
Refresh/clean/rebuild the android project.
You will need to do the above per-project.
This is fixed in Worklight 6.0.

Starting FragmentActivity from Activity with Intent

I'm getting a force close every time I try to start a FragmentActivity from an Activity using an Intent. Here's the code from the Activity:
Intent intent = new Intent(getApplicationContext(), OrgHome.class);
intent.putExtra("Username", organization_name.getText().toString());
startActivity(intent);
And here's the logcat:
08-01 16:52:45.823: E/AndroidRuntime(600): FATAL EXCEPTION: main
08-01 16:52:45.823: E/AndroidRuntime(600): java.lang.NoClassDefFoundError: com.project3.organizations.OrgHome
08-01 16:52:45.823: E/AndroidRuntime(600): at com.project3.organizations.MainActivity$1$1.mobDBResponse(MainActivity.java:76)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.mobdb.android.MobDBRequest.onPostExecute(MobDBRequest.java:78)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.mobdb.android.MobDBRequest.onPostExecute(MobDBRequest.java:1)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask.finish(AsyncTask.java:417)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask.access$300(AsyncTask.java:127)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.Looper.loop(Looper.java:123)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 16:52:45.823: E/AndroidRuntime(600): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 16:52:45.823: E/AndroidRuntime(600): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 16:52:45.823: E/AndroidRuntime(600): at dalvik.system.NativeStart.main(Native Method)
08-01 16:52:48.053: I/Process(600): Sending signal. PID: 600 SIG: 9
OrgHome.class is defined in the manifest correctly. What's going on here?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project3.organizations"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="OrgHome"></activity>
</application>
</manifest>
Change the manifest:
Use this if OrgHome is in the same place as MainActivity
<activity android:name=".OrgHome" />
Use this if it's in a sub-folder
<activity android:name=".sub.path.to.OrgHome" />
Or specify the whole path
<activity android:name="entire.path.to.OrgHome" />
for addressing the Fragment activities you should write (getactivity(),nameofOtherActivity.class); and you should be all right.

How to properly name native functions when using the NDK

I am trying to run my application, but whenever I make a call to a native function it gives me an error and the program crashes. I'm sure it has to do with how I am naming something either in Java or in C.
Here is my call to the functions in Java :
package my.commander;
public class RelayAPIModel {
public static class NativeCalls {
static {
System.loadLibrary( "RelayAPI");
}
public native static byte InitRelayJava();
public native static void FreeRelayJava();
}
Here are the functions in the .c file:
void Java_my_commander_RelayAPIModel_FreeRelayJava( JNIEnv * env, jobject this ) {
RelayAPI_DataValid = 0;
RelayAPI_SetBaud = 0;
RelayAPI_get = 0;
RelayAPI_put = 0;
RelayAPI_flush = 0;
RelayAPI_delay = 0;
RelayAPI_initilized = 0;
}
BYTE Java_my_commander_RelayAPIModel_InitRelayJava( JNIEnv *env, jobject obj ) {
...
...
}
Here they are in the .h file :
void Java_my_commander_RelayAPIModel_FreeRelayJava( JNIEnv * env, jobject obj );
BYTE Java_my_commander_RelayAPIModel_InitRelayJava( JNIEnv *env, jobject obj );
Here is my LogCat:
08-01 09:58:21.933: E/AndroidRuntime(17170): FATAL EXCEPTION: main
08-01 09:58:21.933: E/AndroidRuntime(17170): java.lang.UnsatisfiedLinkError: InitRelayJava
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava(Native Method)
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.MainMenu.initMain(MainMenu.java:241)
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.MainMenu.onCreate(MainMenu.java:81)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.os.Looper.loop(Looper.java:130)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 09:58:21.933: E/AndroidRuntime(17170): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 09:58:21.933: E/AndroidRuntime(17170): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 09:58:21.933: E/AndroidRuntime(17170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 09:58:21.933: E/AndroidRuntime(17170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 09:58:21.933: E/AndroidRuntime(17170): at dalvik.system.NativeStart.main(Native Method)
I would like to clarify now, that I have tried changing the C method names to Java_my_commander_RelayAPIModel_NativeCalls_FreeRelayJava and Java_my_commander_RelayAPIModel_NativeCalls_InitRelayJava. The application still failed to launch and this was the LogCat for that:
08-01 11:22:10.735: E/AndroidRuntime(17441): FATAL EXCEPTION: main
08-01 11:22:10.735: E/AndroidRuntime(17441): java.lang.UnsatisfiedLinkError: InitRelayJava
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava(Native Method)
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.MainMenu.initMain(MainMenu.java:241)
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.MainMenu.onCreate(MainMenu.java:81)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.os.Looper.loop(Looper.java:130)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 11:22:10.735: E/AndroidRuntime(17441): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 11:22:10.735: E/AndroidRuntime(17441): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 11:22:10.735: E/AndroidRuntime(17441): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 11:22:10.735: E/AndroidRuntime(17441): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 11:22:10.735: E/AndroidRuntime(17441): at dalvik.system.NativeStart.main(Native Method)
Now, I think that the error lies in the code above. If you all think there is nothing wrong with it, I'm going to add some more information down here just in case the problem lies elsewhere.
This application that I'm creating, uses the functions above to call a library that has been being used for a while. This library was previously used to call functions in a Palm Pilot program which utilize the Palm's bluetooth capabilities. Since Android devices have different bluetooth libraries/capabilities, I am adding code to the native library to call BACK to the java code, to access the Android device's bluetooth capabilities. I do not want to post all of the code pertaining to this here, but if someone feels that it needs to be posted I will.
The error message says it's at:
my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava (Native Method)
So make sure that:
the native method declaration is indeed inside the RelayAPIModel class, not insude the RelayAPIModel.NativeCalls nested class.
the package name on Java side is my.commander as opposed to my.eti.commander
EDIT: or you can fix that on the C side. If you want to create native methods in the nested class, the proper name for it would be:
Java_my_commander_RelayAPIModel_00024NativeCalls_InitRelayJava()
The 00024 is the code of the $ character, which is the nested class delimiter in Java internals. Also, the meaning of the of second parameter (jobject Obj) will be different - instead of this pointer/class pointer for RelayAPIModel, it will be the one for the RelayAPIModel.NativeCalls. You won't be able to use it to resolve/call methods in the RelayAPIModel.
You can use javah to generate a .h file with the correctly named native files:
javah -jni -classpath bin/classes com.example.app.MyClass

Cannot use a Tablelayout within a widget?

Here is the xml file of my Android widget:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<!-- Some views -->
</TableRow>
<TableRow>
<!-- Some views -->
</TableRow>
</TableLayout>
</LinearLayout>
(full code here: http://pastebin.com/Kqxs5t9E)
This code is showing me some good results in Eclipse, but as soon as I sent the file to my device and try to add the widget to my homescreen I get this error code and the widget showing: "Problem Loading the Widget":
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): updateAppWidget couldn't find any view, using error view
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): android.view.InflateException: Binary XML file line #20: Error inflating class android.widget.TableLayout
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.widget.RemoteViews.apply(RemoteViews.java:930)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:155)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:218)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher.bindAppWidgets(Launcher.java:3652)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher.access$22(Launcher.java:3639)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher$DesktopBinder.handleMessage(Launcher.java:4625)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.os.Looper.loop(Looper.java:123)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at java.lang.reflect.Method.invoke(Method.java:521)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at dalvik.system.NativeStart.main(Native Method)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): Caused by: android.view.InflateException: Binary XML file line #20: Class not allowed to be inflated android.widget.TableLayout
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:525)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createView(LayoutInflater.java:472)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): ... 20 more
So what? I cannot use a Tablelayout within a widget????
What is the best solution so? I can create a lot of relativelayout but I guess that's not a good idea.
I cannot use a Tablelayout within a
widget????
If by "widget" you mean "app widget", then, no, you cannot use a TableLayout in an app widget. There are only a few widgets that can be used in an app widget.
I can create a lot of relativelayout
but I guess that's not a good idea.
I do not know why you think RelativeLayout is bad. You may be able to replace your LinearLayout, TableLayout, and TableRow widgets with a single RelativeLayout.

Categories

Resources