[Q] My code throws exceptions - Android Q&A, Help & Troubleshooting

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

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.

[help] .m3u8 sound lost because of seekTo()

Hello
I have the source code of an appli that plays .mp4 and i have to make it works with HLS.
The video and the sound are played but i have 2 problems ONLY WITH .m3u8 :
1) When seekTo() is activated (commentaries deleted) the sound is disabled and when i want to quit the player, it makes a long time to do and it makes crash the appli
2) setLooping doesn't work and return Error (-38,0), Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0 (below the code)
REMEMBER : THOSE PROBLEMS ARE JUST FOR .M3U8
Here's the code of the player :
Code:
private void playVideo() {
doCleanUp();
try {
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(mFilePath);
mMediaPlayer.setDisplay(mSurfaceHolder);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setOnPreparedListener(this);
//mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mMediaPlayer.seekTo(mResumePosition);
//mMediaPlayer.setLooping(true);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage(), e);
showErrorMessage(mErrorPlayingVideo);
// Toast.makeText(this, "Impossible de jouer la vidéo",
// 5000).show();
}
}
Here's a few of logs when setLooping is activated under setDataSource() :
Code:
error (-38, 0)
prepareAsync called in wrong state 0
prepareAsync_l return error =-38
error: null
java.lang.IllegalStateException
at android.media.MediaPlayer.prepare(Native Method)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.playVideo(BroadpeakDemoPlayer.java:409)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.onRequestFinished(BroadpeakDemoPlayer.java:585)
at fr.niji.lib.dataproxy.service.DataManager.handleResult(DataManager.java:262)
at fr.niji.lib.dataproxy.service.DataManager.onRequestFinished(DataManager.java:292)
at fr.niji.lib.dataproxy.service.ServiceHelper.handleResult(ServiceHelper.java:297)
at fr.niji.lib.dataproxy.service.ServiceHelper$EvalReceiver.onReceiveResult(ServiceHelper.java:119)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4126)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
and below the code :
Code:
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
error (-38, 0)
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
thank you for the help !
up
Ok I found the problem.
When you use seekTo() with a .m3u8 file and the value between the parentheses is set to 0, it doesn't work so I added a condition into playBackVideo() method :
Code:
if (mResumePosition > 0)
mMediaPlayer.seekTo(mResumePosition);
So mResumePosition will never be set to 0 and play at the beginning of the file.
Also, i resolved the setLooping() problem, in
Code:
public void onCompletion(final MediaPlayer mediaPlayer)
I added
Code:
mMediaPlayer.release();
playVideo();
and the looping works very well !
A new problem is arrived.
When i click on Resume button, the video goes to the last place when I stopped the player but there is no sound...
If someone has ideas...

[Q]Error at setting up a larger library project Android

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

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!!

NullPointerException

How do I make it not null? here is the error on my logcat:
02-05 13:59:14.764 26351-26351/com.example.milespc.funfacts2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.milespc.funfacts2, PID: 26351
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.milespc.funfacts2.MainActivity$1.onClick(MainActivity.java:34)
here is the string of code:
factLabel.setText(fact);

Categories

Resources