startActivity fails

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

startActivity fails

Postby cre » Mon Nov 03, 2008 2:54 pm

I have a HelloAndroid.java and a find.java. I am trying to pass control to find.java when the Find button is clicked. When findx is executed the application aborts with this message: ...application has stopped unexpectedly. The activity find is defined in Manifest.xml. Any other code I put into findx executes without a problem.

Here is the code:

btnfind = (Button)findViewById(R.id.find);
btnfind.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ findx(); }});

private void findx()
{

Intent i = new Intent(this,find.class);
startActivity(i);
}

Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.hello"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".find"/>
</application>
</manifest>
cre
Freshman
Freshman
 
Posts: 5
Joined: Mon Nov 03, 2008 3:04 am

Top

Postby Quetzalcoatl » Mon Nov 03, 2008 4:57 pm

I've had a look at where I've done the same and it does look almost identical, is it definately getting into the onCreate() in find.java?
Maybe it's something that happens in find.java that's causing the problem? would explain why anything else you put in findx() is executed ok.
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby cre » Mon Nov 03, 2008 5:38 pm

Que,
Thanks. I'll look around... Haven't gotten the hand of using the debugger yet!

If onCreate() in find was working shouldn't I see the find view that I set with setContextView? I don't appear to get that far. Basically, I'm trying to get the screen transitions working before I build the content.

Here's my code in find:

package com.android.hello;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class find extends Activity {
private Button btnmenu;
private Button btnfound;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.find);

initControls();


}


private void initControls()

{
btnfound = (Button)findViewById(R.id.find);
btnfound.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ found(); }});
btnmenu = (Button)findViewById(R.id.put);
btnmenu.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ found(); }});

}
private void found()
{
setContentView(R.layout.main);
}
}
cre
Freshman
Freshman
 
Posts: 5
Joined: Mon Nov 03, 2008 3:04 am

Postby Quetzalcoatl » Mon Nov 03, 2008 5:58 pm

If you're running from Eclipse then highlight the 'setContentView(R.layout.find);' line of code and press CTRL+SHIFT+B to insert a breakpoint (there should now be a little blue icon on the left margin). Apologies if you know all of this, I'm not trying to insult your intelligence).
When you click on the little debug icon your app will start but will drop into the code at the breakpoint you've inserted (if it gets that far). You can then press F5/F6 to move onto the next line, when it goes wrong you will know which line of code is the problem.
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby MrSnowflake » Mon Nov 03, 2008 6:19 pm

What does your Log(cat) say?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Quetzalcoatl » Mon Nov 03, 2008 6:29 pm

Hunch time:

comment out all the code from within initControls(), I've got a feeling it might not be finding one of the buttons. You search for the same button in both classes:

Code: Select all
btnfound = (Button)findViewById(R.id.find);


Not sure how you've defined your buttons in the xml files but it might just be a copy and paste error, is there a R.id.find in R.layout.find? If you're trying to find the same one as in your main activity then it might be returning null.
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Top

log(cat) file

Postby cre » Mon Nov 03, 2008 7:08 pm

Here's the file. It looks like the thing just blows up when I hit the find button. Is there something fundamental that would cause this?

11-03 12:49:29.982: ERROR/mountd(19): could not read initial mass storage state

11-03 12:49:30.322: ERROR/flash_image(28): can't find recovery partition

11-03 12:49:39.712: ERROR/MemoryHeapBase(52): error opening /dev/pmem: No such file or directory

11-03 12:49:39.722: ERROR/SurfaceFlinger(52): Couldn't open /sys/android_power/wait_for_fb_sleep or /sys/android_power/wait_for_fb_wake

11-03 12:49:39.782: ERROR/GLLogger(52): couldn't load <libhgl.so> library (Cannot find library)

11-03 12:49:39.912: ERROR/GLLogger(52): couldn't load <libhgl.so> library (Cannot find library)

11-03 12:49:42.793: ERROR/BatteryService(52): Could not open '/sys/class/power_supply/usb/online'

11-03 12:49:42.802: ERROR/BatteryService(52): Could not open '/sys/class/power_supply/battery/batt_vol'

11-03 12:49:42.816: ERROR/BatteryService(52): Could not open '/sys/class/power_supply/battery/batt_temp'

11-03 12:49:43.112: ERROR/EventHub(52): could not get driver version for /dev/input/mouse0, Not a typewriter

11-03 12:49:43.142: ERROR/EventHub(52): could not get driver version for /dev/input/mice, Not a typewriter

11-03 12:49:43.182: ERROR/System(52): Failure starting core service

11-03 12:49:43.182: ERROR/System(52): java.lang.SecurityException

11-03 12:49:43.182: ERROR/System(52): at android.os.BinderProxy.transact(Native Method)

11-03 12:49:43.182: ERROR/System(52): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)

11-03 12:49:43.182: ERROR/System(52): at android.os.ServiceManager.addService(ServiceManager.java:72)

11-03 12:49:43.182: ERROR/System(52): at com.android.server.ServerThread.run(SystemServer.java:155)

11-03 12:49:43.202: ERROR/AndroidRuntime(52): Crash logging skipped, no checkin service

11-03 12:49:43.582: ERROR/SystemServer(52): Failure starting StatusBarService

11-03 12:49:43.582: ERROR/SystemServer(52): java.lang.NullPointerException

11-03 12:49:43.582: ERROR/SystemServer(52): at com.android.server.status.StatusBarPolicy.updateBluetooth(StatusBarPolicy.java:749)

11-03 12:49:43.582: ERROR/SystemServer(52): at com.android.server.status.StatusBarPolicy.<init>(StatusBarPolicy.java:282)

11-03 12:49:43.582: ERROR/SystemServer(52): at com.android.server.status.StatusBarPolicy.installIcons(StatusBarPolicy.java:337)

11-03 12:49:43.582: ERROR/SystemServer(52): at com.android.server.ServerThread.run(SystemServer.java:186)

11-03 12:49:43.592: ERROR/AndroidRuntime(52): Crash logging skipped, no checkin service

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): Could not open GPS configuration file /etc/gps.conf

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): java.io.FileNotFoundException: /etc/gps.conf

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:227)

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): at java.io.FileInputStream.<init>(FileInputStream.java:76)

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): at com.android.internal.location.GpsLocationProvider.<init>(GpsLocationProvider.java:179)

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): at com.android.server.LocationManagerService._loadProvidersNoSync(LocationManagerService.java:356)

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): at com.android.server.LocationManagerService.loadProvidersNoSync(LocationManagerService.java:340)

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): at com.android.server.LocationManagerService.loadProviders(LocationManagerService.java:333)

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): at com.android.server.LocationManagerService.<init>(LocationManagerService.java:447)

11-03 12:49:43.922: ERROR/GpsLocationProvider(52): at com.android.server.ServerThread.run(SystemServer.java:230)

11-03 12:49:43.933: ERROR/AndroidRuntime(52): Crash logging skipped, no checkin service

11-03 12:49:57.812: ERROR/dalvikvm(137): pthread_setspecific failed, err=22

11-03 12:49:50.967: ERROR/dalvikvm(148): pthread_setspecific failed, err=22

11-03 12:49:54.457: ERROR/NetworkStateTracker(52): Can't set tcp buffer sizes:java.io.FileNotFoundException: /sys/kernel/ipv4/tcp_rmem_min

11-03 12:50:18.846: ERROR/NetworkStateTracker(52): Can't set tcp buffer sizes:java.io.FileNotFoundException: /sys/kernel/ipv4/tcp_rmem_min
cre
Freshman
Freshman
 
Posts: 5
Joined: Mon Nov 03, 2008 3:04 am

Hutch Time Wins!!!!!!!

Postby cre » Mon Nov 03, 2008 7:19 pm

Que..., your a genius!!!!!!!!!!

Commented out the buttons with the duplicate find and it works!

Thanks to all!

Cre
cre
Freshman
Freshman
 
Posts: 5
Joined: Mon Nov 03, 2008 3:04 am

Postby Quetzalcoatl » Mon Nov 03, 2008 7:19 pm

MrSnowflake or someone else might be able to help you with the log file, did you try commenting out the code in onCreate()? That will happen really quickly, so if there's a problem there then it'll go BOOM!! :D
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby Quetzalcoatl » Mon Nov 03, 2008 7:20 pm

Sweet, after doing Symbian programming finding errors in Android is definately a lot easier :D
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests