[Q]Error at setting up a larger library project Android - Android Q&A, Help & Troubleshooting

Since I can not post links but they are necessary to not post a lot of code, I removed the prefixes in the beginning. They begin with the URL:
Want to start a standalone android project with a button in another project. First made a simple main app with a button that was referring to another project with Hello World with "is Library in Preferences". All according URL: developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject and it worked without problems.
Did the same thing with an open soruce project (puzzle) URL: code.google.com/p/androidsoft/source/browse/#svn%2Ftrunk%2Fpuzzle but get an error message in LogCat and my appa crashes when I click the button in my main app.
Guess I may have missed something in AndroidManifest.xml According to the documentation it says
Code:
Declaring library components in the manifest file: You must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as <permission>, <uses-library>.
I can compile puzzle as their own project without any problems. If the puzzle is a library will not work.
My main app with a button that will start the second project
Code:
public class AppActivity extends Activity {
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, org.androidsoft.games.puzzle.kids.MainActivity.class);
startActivity(intent);
}
});
}
}
AndroidManifest.xml in my main app with android:name="org.androidsoft.games.puzzle.kids.MainActivity
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="schemas.android.com/apk/res/android"
package="com.mkyong.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".AppActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.androidsoft.games.puzzle.kids.MainActivity">
</activity>
</application>
</manifest>
AndroidManifest.xml in puzzle that I want to use as a library URL: code.google.com/p/androidsoft/source/browse/trunk/puzzle/AndroidManifest.xml
LogCat error
Code:
08-08 12:44:31.607: E/AndroidRuntime(780): FATAL EXCEPTION: main
08-08 12:44:31.607: E/AndroidRuntime(780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mkyong.android/org.androidsoft.games.puzzle.kids.MainActivity}: java.lang.NullPointerException
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.os.Handler.dispatchMessage(Handler.java:99)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.os.Looper.loop(Looper.java:137)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-08 12:44:31.607: E/AndroidRuntime(780): at java.lang.reflect.Method.invokeNative(Native Method)
08-08 12:44:31.607: E/AndroidRuntime(780): at java.lang.reflect.Method.invoke(Method.java:511)
08-08 12:44:31.607: E/AndroidRuntime(780): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-08 12:44:31.607: E/AndroidRuntime(780): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-08 12:44:31.607: E/AndroidRuntime(780): at dalvik.system.NativeStart.main(Native Method)
08-08 12:44:31.607: E/AndroidRuntime(780): Caused by: java.lang.NullPointerException
08-08 12:44:31.607: E/AndroidRuntime(780): at org.androidsoft.games.puzzle.kids.AbstractMainActivity.onCreate(AbstractMainActivity.java:81)
08-08 12:44:31.607: E/AndroidRuntime(780): at org.androidsoft.games.puzzle.kids.MainActivity.onCreate(MainActivity.java:57)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.Activity.performCreate(Activity.java:5008)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-08 12:44:31.607: E/AndroidRuntime(780): ... 11 more

Related

[DEV] Low Level System functions - permission problems

Hi
I'm trying to write an application that puts my device into sleep since my powerbutton is broken. (Thanks no option to return etc.)
Now when i try to tell my phone to go to sleep using:
Code:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
pm.goToSleep(0);
I'm getting the below error. How can I make it work?
I was told I need to sign the app with the rom key to use such low level system functionality. How can I do that, where can I get the key?
Is this possible for stock rom, CM6?
Thanks for you help
Code:
I/ActivityManager( 111): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.myapp.sl33p/.sl33p }
W/ActivityManager( 111): Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.myapp.sl33p/.sl33p } from ProcessRecord{4415
cd90 14332:android.process.acore/10068} (pid=14332, uid=10068) requires android.permission.DEVICE_POWER
E/Launcher(14332): Launcher does not have the permission to launch Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.myapp.sl33p/.sl33p }. Make sure
to create a MAIN intent-filter for the corresponding activity or use the exported attribute for this activity.
E/Launcher(14332): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.myapp.sl33p/.sl33p } f
rom ProcessRecord{4415cd90 14332:android.process.acore/10068} (pid=14332, uid=10068) requires android.permission.DEVICE_POWER
E/Launcher(14332): at android.os.Parcel.readException(Parcel.java:1247)
E/Launcher(14332): at android.os.Parcel.readException(Parcel.java:1235)
E/Launcher(14332): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
E/Launcher(14332): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
E/Launcher(14332): at android.app.Activity.startActivityForResult(Activity.java:2817)
E/Launcher(14332): at com.fede.launcher.Launcher.startActivityForResult(Launcher.java:2783)
E/Launcher(14332): at android.app.Activity.startActivity(Activity.java:2923)
E/Launcher(14332): at com.fede.launcher.Launcher.startActivity(Launcher.java:3751)
E/Launcher(14332): at com.fede.launcher.Launcher.startActivitySafely(Launcher.java:3736)
E/Launcher(14332): at com.fede.launcher.AllAppsGridView.onItemClick(AllAppsGridView.java:1096)
E/Launcher(14332): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/Launcher(14332): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
E/Launcher(14332): at android.os.Handler.handleCallback(Handler.java:587)
E/Launcher(14332): at android.os.Handler.dispatchMessage(Handler.java:92)
E/Launcher(14332): at android.os.Looper.loop(Looper.java:123)
E/Launcher(14332): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/Launcher(14332): at java.lang.reflect.Method.invokeNative(Native Method)
E/Launcher(14332): at java.lang.reflect.Method.invoke(Method.java:521)
E/Launcher(14332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/Launcher(14332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/Launcher(14332): at dalvik.system.NativeStart.main(Native Method)
i was wondering the same, since my power button is dead, but was told by some devs that the system wont allow apps to put system into a sleep state.
the error says it all: android.permission.DEVICE_POWER
put this permission in your manifest and it should be fine.
Adding the permission isn't enough in this case, I think.
Isn't this permission granted to the system only ?
If it is, you'll need to sign the application with the CyanogenMod SDK key.
And it'll work only on CM.
Zappletoo said:
Adding the permission isn't enough in this case, I think.
Isn't this permission granted to the system only ?
If it is, you'll need to sign the application with the CyanogenMod SDK key.
And it'll work only on CM.
Click to expand...
Click to collapse
Yes that's exactly what I think and have been told. Can you give me a hint where I find this key and how I have to sign the app?
The only thing I could find is here:
http://wiki.cyanogenmod.com/index.php?title=How_to_build_a_kernel_port_for_CM6
but that's related to kernel and zip signing?
Thx
PS: And just for the records the manifest
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.sl33p"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:permission="android.permission.DEVICE_POWER">
<activity android:name=".sl33p"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="1" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
</manifest>
<uses-permission android:name="android.permission.DEVICE_POWER" />
well, the other choice perhaps is to compile your app with the Android ROM tree.

[Q] My code throws exceptions

Hello, i am new to development for android and i am trying to make a simple app for me to learn how to code in java.
The idea was to make an app that you can use to send a text (yes, i could just use the messaging app, but that's no fun) and after fiddling with my code quite a bit i made it run on the emulator.
everything works other than when i send the message; an error is thrown (sending a message using the messaging app works though, and the message appears on the other emulator)
The emulators are both running 4.0.3, only one has the app installed
here is the error:
Thread [<1> main] (Suspended (exception IllegalArgumentException))
and for the full stack you can visit this link: http://pastebin.com/Sdc4RshX
and for the code please go here: http://pastebin.com/4xXDTbD1
what would have caused the issue, and what should i do to fix it?
Thanks
Have you added the user permission in the android manifest for sending SMS?
Code:
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
learning Java under Android is a really bad idea, just learn how to use Java with the JDK under a desktop OS.
dillonr, check this:
cheznutts said:
Have you added the user permission in the android manifest for sending SMS?
Code:
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
Click to expand...
Click to collapse
Also, you need to provide a PendingIntent as fourth argument to sendTextMessage method (as described here).
i did/do have the permission in the android manifest
should edit the first post, i am trying to make a simple app to learn how to code in java for android...i have a few ideas for better apps, gotta learn the basics first.
i understand how the views work, and how the files are placed...so i'm learning some things, and it is similar to when i used to code a few years ago in flash (like classes, variables, if...etc.)
EDIT: i un-commented the parts i commented out previously (including the PendingIntent)
http://pastebin.com/cH4NMTwM
still throwing the same error
Thread [<1> main] (Suspended (exception IllegalArgumentException))
I also noticed this
SmsManager.sendTextMessage(String, String, String, PendingIntent, PendingIntent) line: 77
but i do not have a line 77, and nothing seems to be wrong with my code (that i can see, anyway)
Could you post your AndroidManifest.xml and layout XML would like to see the declarations.
manifest
http://pastebin.com/L6VU7bJV
layout
http://pastebin.com/yAB6ia4Q
ho[e this helps you help me
I went ahead and made a project using your code. I commented out the pending intent, I opened up two emulators. One with port 5554 and another with 5556. Now I compiled your code on 5556 and then text to 5554 and it went through fine, no exceptions. Here is what Im looking at in the Activity:
Code:
package com.example.test;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.telephony.SmsManager;
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;
}
public void csend(View view) {
String _number = this.getString(R.string.number);
String _message = this.getString(R.string.message);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(_number, null, _message, null, null);
}
}
Here is my Android Manifest:
Code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<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 left the layout alone. I say try it again. Check SDK is up to date and try creating new emulator using a different API level.
i updated and made new emulators (google api level 16, and google api level 15)
then i made a new "android application project" with the name 'multisender'
i copied the code from the previous application and pasted it into the correct files in the new one
what eclipse should i be running for android development? (on a mac)
running the application causes errors on sending the text (to phone number 15555215556 or 5556; the number shown when a text is recieved, and the port number)
it says "unfortunately, multisender has stopped." on the screen and i get errors in the LogCat
here is a copy of the LogCat errors
Code:
07-11 12:23:57.177: E/Trace(919): error opening trace file: No such file or directory (2)
07-11 12:29:33.907: E/Trace(954): error opening trace file: No such file or directory (2)
07-11 12:32:11.908: E/AndroidRuntime(954): FATAL EXCEPTION: main
07-11 12:32:11.908: E/AndroidRuntime(954): java.lang.IllegalStateException: Could not execute method of the activity
07-11 12:32:11.908: E/AndroidRuntime(954): at android.view.View$1.onClick(View.java:3591)
07-11 12:32:11.908: E/AndroidRuntime(954): at android.view.View.performClick(View.java:4084)
07-11 12:32:11.908: E/AndroidRuntime(954): at android.view.View$PerformClick.run(View.java:16966)
07-11 12:32:11.908: E/AndroidRuntime(954): at android.os.Handler.handleCallback(Handler.java:615)
07-11 12:32:11.908: E/AndroidRuntime(954): at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 12:32:11.908: E/AndroidRuntime(954): at android.os.Looper.loop(Looper.java:137)
07-11 12:32:11.908: E/AndroidRuntime(954): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-11 12:32:11.908: E/AndroidRuntime(954): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:32:11.908: E/AndroidRuntime(954): at java.lang.reflect.Method.invoke(Method.java:511)
07-11 12:32:11.908: E/AndroidRuntime(954): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-11 12:32:11.908: E/AndroidRuntime(954): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-11 12:32:11.908: E/AndroidRuntime(954): at dalvik.system.NativeStart.main(Native Method)
07-11 12:32:11.908: E/AndroidRuntime(954): Caused by: java.lang.reflect.InvocationTargetException
07-11 12:32:11.908: E/AndroidRuntime(954): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:32:11.908: E/AndroidRuntime(954): at java.lang.reflect.Method.invoke(Method.java:511)
07-11 12:32:11.908: E/AndroidRuntime(954): at android.view.View$1.onClick(View.java:3586)
07-11 12:32:11.908: E/AndroidRuntime(954): ... 11 more
07-11 12:32:11.908: E/AndroidRuntime(954): Caused by: java.lang.IllegalArgumentException: Invalid destinationAddress
07-11 12:32:11.908: E/AndroidRuntime(954): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:77)
07-11 12:32:11.908: E/AndroidRuntime(954): at com.dillonregi.multisender.multisender.csend(multisender.java:71)
07-11 12:32:11.908: E/AndroidRuntime(954): ... 14 more
it seems like i have an "invalid destination address" but sending a text to those numbers works in the default sms app
and what would be the "method of the activity"?
sorry for all these questions, but maybe one day someone else will also have this problem
EDIT: so i found the problem...kind of...when i replaced the line
sms.sendTextMessage(_number, null, _message, sentPI, null);
with
sms.sendTextMessage("5556", null, "test", null, null);
and ran it on the emulator (on port 5554) it sent "test" to the one on port 5556 with no errors!
Still wondering why i was getting errors with the variables there though
second edit: if either of the _number or _message variables are on that line it breaks...sentPI does not break it
okay, so i found the problem with the _number and _message
they were not defined in my strings.xml
the only problem is i cannot change who i send it to, or what the message is, even when i change what the text boxes say in the application...so my new question is how can i change a variable using an editable text box? (or how can i check what is in the text box before sending the text?)
EDIT: okay, i think i fixed it....
"
EditText number = (EditText)findViewById(R.id.pnumber);
EditText message = (EditText)findViewById(R.id.pmessage);
String _number = number.getText().toString();
String _message = message.getText().toString();
"
then
" sms.sendTextMessage(_number, null, _message, sentPI, null);
"
hope this helps other people
thanks everyone

Making a simple android app?

Hello.
I would like to make a very simple Android app, with no UI. Kind of a shortcut. I tried searching the web, and I didn't find what I was looking for.
The question is: Can I make a simple app, that only launches an activity?
I want to make an app to launch the following activity : "com.cyanogenmod.trebuchet.preference.Preferences". Kind of how the app "QuickShortcutMaker" works.
Thanks in advance for future answers.
I haven't much experience on android developer, but I think that this can do what you want.
Start a new project with an empty activity and put this inside the activity.java file:
Code:
public class MainActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.cyanogenmod.trebuchet.preference.Preferences");
startActivity(intent);
finish();
}
}
dancer_69 said:
I haven't much experience on android developer, but I think that this can do what you want.
Start a new project with an empty activity and put this inside the activity.java file:
Code:
public class MainActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.cyanogenmod.trebuchet.preference.Preferences");
startActivity(intent);
finish();
}
}
Click to expand...
Click to collapse
Thanks a lot for your help!
This line is giving me an error upon debug:
Code:
Intent intent = pm.getLaunchIntentForPackage("com.cyanogenmod.trebuchet.preference.Preferences");
The commands 'Intent intent" and "PackageManager" are not recognized. Eclipse suggests changing them, importing them, or creating a class. What should I do?
This is the logcat:
Code:
I/ActivityManager( 524): START u0 {act=android.intent.action.MAIN cat=[android.
intent.category.LAUNCHER] flg=0x10200000 cmp=com.AB.launchersettings/.MainActivi
ty} from pid 876
D/ALSAModule( 175): setHardwareParams: reqBuffSize 1024 channels 2 sampleRate 4
8000
D/ALSAModule( 175): setHardwareParams: buffer_size 2048, period_size 1024, peri
od_cnt 2
D/dalvikvm(26747): Late-enabling CheckJNI
I/ActivityManager( 524): Start proc com.AB.launchersettings for activity com.AB
.launchersettings/.MainActivity: pid=26747 uid=10046 gids={50046, 1028}
D/overlay ( 172): FROM_STATE = OV_BYPASS_3_LAYER TO_STATE = OV_CLOSED
E/Trace (26747): error opening trace file: No such file or directory (2)
D/AndroidRuntime(26747): Shutting down VM
W/dalvikvm(26747): threadid=1: thread exiting with uncaught exception (group=0x4
0a4a888)
E/AndroidRuntime(26747): FATAL EXCEPTION: main
E/AndroidRuntime(26747): java.lang.RuntimeException: Unable to start activity Co
mponentInfo{com.AB.launchersettings/com.AB.launchersettings.MainActivity}: java.
lang.NullPointerException
E/AndroidRuntime(26747): at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2307)
E/AndroidRuntime(26747): at android.app.ActivityThread.handleLaunchActivi
ty(ActivityThread.java:2357)
E/AndroidRuntime(26747): at android.app.ActivityThread.access$600(Activit
yThread.java:153)
E/AndroidRuntime(26747): at android.app.ActivityThread$H.handleMessage(Ac
tivityThread.java:1247)
E/AndroidRuntime(26747): at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime(26747): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(26747): at android.app.ActivityThread.main(ActivityThrea
d.java:5231)
E/AndroidRuntime(26747): at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(26747): at java.lang.reflect.Method.invoke(Method.java:5
11)
E/AndroidRuntime(26747): at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:794)
E/AndroidRuntime(26747): at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:561)
E/AndroidRuntime(26747): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(26747): Caused by: java.lang.NullPointerException
E/AndroidRuntime(26747): at android.app.Instrumentation.execStartActivity
(Instrumentation.java:1410)
E/AndroidRuntime(26747): at android.app.Activity.startActivityForResult(A
ctivity.java:3376)
E/AndroidRuntime(26747): at android.app.Activity.startActivityForResult(A
ctivity.java:3337)
E/AndroidRuntime(26747): at android.app.Activity.startActivity(Activity.j
ava:3572)
E/AndroidRuntime(26747): at android.app.Activity.startActivity(Activity.j
ava:3540)
E/AndroidRuntime(26747): at com.AB.launchersettings.MainActivity.onCreate
(MainActivity.java:16)
E/AndroidRuntime(26747): at android.app.Activity.performCreate(Activity.j
ava:5110)
E/AndroidRuntime(26747): at android.app.Instrumentation.callActivityOnCre
ate(Instrumentation.java:1080)
E/AndroidRuntime(26747): at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2261)
E/AndroidRuntime(26747): ... 11 more
W/ActivityManager( 524): Force finishing activity com.AB.launchersettings/.Ma
inActivity
D/dalvikvm( 524): GC_FOR_ALLOC freed 1154K, 23% free 26363K/33812K, paused 86ms
, total 86ms
W/BackupManagerService( 524): dataChanged but no participant pkg='com.android.p
roviders.settings' uid=10031
W/ActivityManager( 524): Activity pause timeout for ActivityRecord{40cbfcc8 u0
com.AB.launchersettings/.MainActivity}
D/alsa_ucm( 175): snd_use_case_set(): uc_mgr 0x2a0092a0 identifier _verb value
Inactive
D/alsa_ucm( 175): Set mixer controls for HiFi Lowlatency enable 0
D/alsa_ucm( 175): snd_use_case_set(): uc_mgr 0x2a0092a0 identifier _disdev valu
e Speaker
D/alsa_ucm( 175): Set mixer controls for Speaker enable 0
W/ActivityManager( 524): Activity destroy timeout for ActivityRecord{40cbfcc8 u
0 com.AB.launchersettings/.MainActivity}
What I did:
Created a new project ( Filled up the name, icon and stuff)
Went straight to MainActivity.java, and put what you gave me in it.
Debugged the app by installing it on my Nexus 4.
Import them.
EDIT:
Seems that the above code doesn't work. So replace all content on your activity, except the first line(com... what you have as name) with this:
Code:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
public class MainActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent();
intent.setClassName("com.cyanogenmod.trebuchet", "com.cyanogenmod.trebuchet.preference.Preferences");
startActivity(intent);
finish();
}
}
dancer_69 said:
Import them.
EDIT:
Seems that the above code doesn't work. So replace all content on your activity, except the first line(com... what you have as name) with this:
Code:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
public class MainActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent();
intent.setClassName("com.cyanogenmod.trebuchet", "com.cyanogenmod.trebuchet.preference.Preferences");
startActivity(intent);
finish();
}
}
Click to expand...
Click to collapse
This worked. Thanks a lot!!

[Q] How to set as wallpaper the current image displayed in the ImageView ?

Hello guys
I am trying to build an application with 2 activities one is the main activity and the second activity which contain ImageView, and a 3 button’s. I want when I press the button to set as wallpaper the current image displayed in the ImageView . The problem is when I set the code for the Set Wallpaper button the first main activity is accessed without problems, but when I try to access the second activity the app crashes as you can see in the log. If I don’t configure the Set Wallpaper button, the code for the next and previous buttons runs smoothly. I tried several options and methods to configure the onClick for the Set Wallpaper button. Please help me with this problem. Here is my code:
Code:
public class Castles extends Activity {
protected static InputStream is;
public int currentImage = 0;
int[] imageIds = {
R.drawable.cas1,R.drawable.cas2,R.drawable.cas3,R.drawable.cas4,R.drawable.cas5,R.drawable.cas6,
R.drawable.cas7, R.drawable.cas8, R.drawable.cas9,R.drawable.cas10,R.drawable.cas11,R.drawable.cas12,
R.drawable.cas13,R.drawable.cas14,R.drawable.cas15,R.drawable.cas16, R.drawable.cas17,R.drawable.cas18,
R.drawable.cas19,R.drawable.cas20,R.drawable.cas21};
private Button BNatNext;
private Button BNatPri;
private Button BSetWallNat;
private ImageView IVNat;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.castles);
IVNat = (ImageView)findViewById(R.id.IVNat);
BNatNext=(Button)findViewById(R.id.BNatNext);
BNatPri=(Button)findViewById(R.id.BNatPri);
BNatNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
currentImage++;
currentImage=currentImage%imageIds.length;
IVNat.setImageResource(imageIds[currentImage]);
}
});
BNatPri.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentImage--;
currentImage=(currentImage+imageIds.length)%imageIds.length;
IVNat.setImageResource(imageIds[currentImage]);
}
});
BSetWallNat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
} catch(IOException e){
Log.e("Tag", "couldn't set wallpaper", e);
}
}
And this is the LogCat:
Code:
12-04 21:44:15.205: D/dalvikvm(1223): GC_EXTERNAL_ALLOC freed 44K, 51% free 2670K/5379K, external 1527K/1559K, paused 418ms
12-04 21:44:18.282: D/dalvikvm(1223): GC_EXTERNAL_ALLOC freed 1K, 51% free 2669K/5379K, external 4560K/5695K, paused 486ms
12-04 21:44:24.043: D/gralloc_goldfish(1223): Emulator without GPU emulation detected.
12-04 21:44:27.853: D/dalvikvm(1223): GC_EXTERNAL_ALLOC freed 11K, 50% free 2698K/5379K, external 7974K/7974K, paused 201ms
12-04 21:44:32.223: D/dalvikvm(1223): GC_EXTERNAL_ALLOC freed 2K, 50% free 2702K/5379K, external 11198K/11388K, paused 321ms
12-04 21:44:34.903: D/AndroidRuntime(1223): Shutting down VM
12-04 21:44:34.903: W/dalvikvm(1223): threadid=1: thread exiting with uncaught exception (group=0xb609d4f0)
12-04 21:44:34.963: E/AndroidRuntime(1223): FATAL EXCEPTION: main
12-04 21:44:34.963: E/AndroidRuntime(1223): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Roapps.wallpaperhd/com.Roapps.wallpaperhd.Castles}: java.lang.NullPointerException
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.os.Looper.loop(Looper.java:130)
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-04 21:44:34.963: E/AndroidRuntime(1223): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 21:44:34.963: E/AndroidRuntime(1223): at java.lang.reflect.Method.invoke(Method.java:507)
12-04 21:44:34.963: E/AndroidRuntime(1223): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-04 21:44:34.963: E/AndroidRuntime(1223): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-04 21:44:34.963: E/AndroidRuntime(1223): at dalvik.system.NativeStart.main(Native Method)
12-04 21:44:34.963: E/AndroidRuntime(1223): Caused by: java.lang.NullPointerException
12-04 21:44:34.963: E/AndroidRuntime(1223): at com.Roapps.wallpaperhd.Castles.onCreate(Castles.java:63)
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-04 21:44:34.963: E/AndroidRuntime(1223): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-04 21:44:34.963: E/AndroidRuntime(1223): ... 11 more
12-04 21:44:38.963: I/Process(1223): Sending signal. PID: 1223 SIG: 9

[Q] don't understand logcat errors for plugin between Eclipse and Unity

Hi,
I am trying to debug an Eclipse project linked to Unity with a plugin. The Eclipse project works on my device (Alcatel One Touch 997), it connects to facebook and shows the user name. But once connected as a plugin to Unity, it does not work anymore. I don't understand the errors from the logcat, or the weird message from Unity about the "portrait" mode (the orientation is set to portrait in the unity settings and in the manifest) :
from Unity :
Code:
Unable to find unity activity in manifest. You need to make sure orientation attribut is set to portrait manually.
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
from the logcat :
Code:
V/ActivityManager( 250): New app record ProcessRecord{41d57940 20062:com.firstandroidapp/10114} [email protected] pid=20062
D/PowerManagerService( 250): setKeyboardVisibility: false
V/ActivityManager( 250): ACT-Launching: ActivityRecord{41d4f3a8 com.firstandroidapp/.MainActivity}
D/NetworkPolicy( 250): onRecv: MSG_FOREGROUND_ACTIVITIES_CHANGED pid:uid:act=20062:10114:true
V/WindowManager( 250): Changing focus from Window{4199c6c8 com.jrdcom.launcher/com.jrdcom.launcher.Launcher paused=false} to null
I/WindowManager( 250): Losing focus: Window{4199c6c8 com.jrdcom.launcher/com.jrdcom.launcher.Launcher paused=false}
D/OpenGLRenderer( 515): Flushing caches (mode 1)
D/OpenGLRenderer( 515): Flushing caches (mode 0)
D/ActivityThread(20062): BIND_APPLICATION handled : 0 / AppBindData{appInfo=ApplicationInfo{418319c8 com.firstandroidapp}}
I/dalvikvm(20062): Failed resolving Lcom/firstandroidapp/MainActivity$1; interface 103 'Lcom/facebook/Session$StatusCallback;'
W/dalvikvm(20062): Link of class 'Lcom/firstandroidapp/MainActivity$1;' failed
E/dalvikvm(20062): Could not find class 'com.firstandroidapp.MainActivity$1', referenced from method com.firstandroidapp.MainActivity.<init>
W/dalvikvm(20062): VFY: unable to resolve new-instance 113 (Lcom/firstandroidapp/MainActivity$1;) in Lcom/firstandroidapp/MainActivity;
D/dalvikvm(20062): VFY: replacing opcode 0x22 at 0x0003
W/dalvikvm(20062): VFY: unable to find class referenced in signature (Lcom/facebook/Session;)
W/dalvikvm(20062): VFY: unable to find class referenced in signature (Lcom/facebook/SessionState;)
W/dalvikvm(20062): VFY: unable to find class referenced in signature (Lcom/facebook/Session;)
W/dalvikvm(20062): VFY: unable to find class referenced in signature (Lcom/facebook/SessionState;)
W/dalvikvm(20062): VFY: unable to find class referenced in signature (Lcom/facebook/model/GraphUser;)
W/dalvikvm(20062): VFY: unable to find class referenced in signature (Lcom/facebook/Session;)
W/dalvikvm(20062): VFY: unable to find class referenced in signature (Lcom/facebook/SessionState;)
I/dalvikvm(20062): Could not find method com.facebook.Session.getActiveSession, referenced from method com.firstandroidapp.MainActivity.updateUI
W/dalvikvm(20062): VFY: unable to resolve static method 264: Lcom/facebook/Session;.getActiveSession ()Lcom/facebook/Session;
D/dalvikvm(20062): VFY: replacing opcode 0x71 at 0x0000
I/dalvikvm(20062): Could not find method com.facebook.UiLifecycleHelper.onActivityResult, referenced from method com.firstandroidapp.MainActivity.onActivityResult
W/dalvikvm(20062): VFY: unable to resolve virtual method 267: Lcom/facebook/UiLifecycleHelper;.onActivityResult (IILandroid/content/Intent;Lcom/facebook/widget/FacebookDialog$Callback;)V
D/dalvikvm(20062): VFY: replacing opcode 0x6e at 0x0007
E/dalvikvm(20062): Could not find class 'com.facebook.UiLifecycleHelper', referenced from method com.firstandroidapp.MainActivity.onCreate
W/dalvikvm(20062): VFY: unable to resolve new-instance 106 (Lcom/facebook/UiLifecycleHelper;) in Lcom/firstandroidapp/MainActivity;
D/dalvikvm(20062): VFY: replacing opcode 0x22 at 0x0005
I/dalvikvm(20062): Could not find method com.facebook.UiLifecycleHelper.onDestroy, referenced from method com.firstandroidapp.MainActivity.onDestroy
W/dalvikvm(20062): VFY: unable to resolve virtual method 269: Lcom/facebook/UiLifecycleHelper;.onDestroy ()V
D/dalvikvm(20062): VFY: replacing opcode 0x6e at 0x0005
I/dalvikvm(20062): Could not find method com.facebook.UiLifecycleHelper.onPause, referenced from method com.firstandroidapp.MainActivity.onPause
W/dalvikvm(20062): VFY: unable to resolve virtual method 270: Lcom/facebook/UiLifecycleHelper;.onPause ()V
D/dalvikvm(20062): VFY: replacing opcode 0x6e at 0x0005
I/dalvikvm(20062): Could not find method com.facebook.UiLifecycleHelper.onResume, referenced from method com.firstandroidapp.MainActivity.onResume
W/dalvikvm(20062): VFY: unable to resolve virtual method 271: Lcom/facebook/UiLifecycleHelper;.onResume ()V
D/dalvikvm(20062): VFY: replacing opcode 0x6e at 0x0005
I/dalvikvm(20062): Could not find method com.facebook.UiLifecycleHelper.onSaveInstanceState, referenced from method com.firstandroidapp.MainActivity.onSaveInstanceState
W/dalvikvm(20062): VFY: unable to resolve virtual method 272: Lcom/facebook/UiLifecycleHelper;.onSaveInstanceState (Landroid/os/Bundle;)V
D/dalvikvm(20062): VFY: replacing opcode 0x6e at 0x0005
I/dalvikvm(20062): Failed resolving Lcom/firstandroidapp/MainActivity$1; interface 103 'Lcom/facebook/Session$StatusCallback;'
W/dalvikvm(20062): Link of class 'Lcom/firstandroidapp/MainActivity$1;' failed
D/dalvikvm(20062): DexOpt: unable to opt direct call 0x0113 at 0x05 in Lcom/firstandroidapp/MainActivity;.<init>
I/dalvikvm(20062): Failed resolving Lcom/firstandroidapp/MainActivity$2; interface 108 'Lcom/facebook/widget/FacebookDialog$Callback;'
W/dalvikvm(20062): Link of class 'Lcom/firstandroidapp/MainActivity$2;' failed
D/dalvikvm(20062): DexOpt: unable to opt direct call 0x0115 at 0x0c in Lcom/firstandroidapp/MainActivity;.<init>
D/dalvikvm(20062): DexOpt: unable to opt direct call 0x010a at 0x09 in Lcom/firstandroidapp/MainActivity;.onCreate
I/dalvikvm(20062): Failed resolving Lcom/firstandroidapp/MainActivity$3; interface 110 'Lcom/facebook/widget/LoginButton$UserInfoChangedCallback;'
W/dalvikvm(20062): Link of class 'Lcom/firstandroidapp/MainActivity$3;' failed
D/dalvikvm(20062): DexOpt: unable to opt direct call 0x0118 at 0x2f in Lcom/firstandroidapp/MainActivity;.onCreate
D/AndroidRuntime(20062): Shutting down VM
W/dalvikvm(20062): threadid=1: thread exiting with uncaught exception (group=0x40f10258)
D/dalvikvm(20051): threadid=0: all daemons have suspended
D/dalvikvm(20051): VM cleaning up
E/AndroidRuntime(20062): FATAL EXCEPTION: main
E/AndroidRuntime(20062): java.lang.NoClassDefFoundError: com.firstandroidapp.MainActivity$1
E/AndroidRuntime(20062): at com.firstandroidapp.MainActivity.<init>(MainActivity.java:27)
E/AndroidRuntime(20062): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(20062): at java.lang.Class.newInstance(Class.java:1319)
E/AndroidRuntime(20062): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
E/AndroidRuntime(20062): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2011)
E/AndroidRuntime(20062): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2124)
E/AndroidRuntime(20062): at android.app.ActivityThread.access$600(ActivityThread.java:135)
E/AndroidRuntime(20062): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
E/AndroidRuntime(20062): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(20062): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(20062): at android.app.ActivityThread.main(ActivityThread.java:4645)
E/AndroidRuntime(20062): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(20062): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(20062): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
E/AndroidRuntime(20062): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
E/AndroidRuntime(20062): at dalvik.system.NativeStart.main(Native Method)
D/dalvikvm(20051): threadid=4: freeing
D/dalvikvm( 250): threadid=77: interp stack at 0x4d273000
W/ActivityManager( 250): Force finishing activity com.firstandroidapp/.MainActivity
D/dalvikvm( 250): threadid=77: calling run()
W/AES ( 250): Exception Log handling...
D/dalvikvm(20051): LinearAlloc 0x0 used 1005804 of 8388608 (11%)
D/ADB_SERVICES( 6920): closing because is_eof=1 r=-1 s->fde.force_eof=0
D/PowerManagerService( 250): acquireWakeLock flags=0x1 tag=ActivityManager-Launch
D/AES ( 250): ExceptionLog: notify aed
D/AES ( 250): process : com.firstandroidapp
D/AES ( 250): module : com.firstandroidapp v1 (1.0)
D/AES ( 250):
D/AES ( 250): cause : data_app_crash
This is the manifest file in Unity :
Code:
//in Unity, the Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="(i cannot post links)res/android" package="com.firstandroidapp">
<application
android:allowBackup="true"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:screenOrientation="portrait" >
<activity
android:name="com.firstandroidapp.MainActivity"
android:label="MyApp" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:value="(numbersHidden)" android:name="com.facebook.sdk.ApplicationId"/>
<activity android:name="com.facebook.LoginActivity"></activity>
</application>
</manifest>
This is how I call the plugin (the project is set as a library, and I pasted the .jar from the bin folder in the folder Plugins/Android in my project in Unity) :
Code:
if(GUI.Button(new Rect(20,250,150,150), "TEST")) {
Debug.Log("hello facebook");
using (AndroidJavaClass javaClass = new AndroidJavaClass("com.firstandroidapp.MainActivity"))
{
using (AndroidJavaObject activity = javaClass.GetStatic<AndroidJavaObject>("ctx"))
{
activity.Call("testFunc");
}
}
}
and the simple method in Eclipse :
Code:
public class MainActivity extends UnityPlayerActivity {
public void testFunc(){
Log.i("test func","test func");
}
The only thing I did was importing the classes.jar (to allow to extend UnityPlayerActivity) in the Eclipse project (Properties > Java Build Path) and I added the FacebookSDK folder as a library (below the checkbox use as a Library in Eclipse, where you can add a folder to add other libraries).
Without facebook, the connection between Unity and Eclipse works fine. But with facebook, the errors above show up.
If anyone would have a slight idea how to debug this, i would really appreciate, I cannot manage to fix this problem.
Thanks

Categories

Resources