• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps New Problem

Marker88

Newbie
yeah, now i have a new problem with this when i put this code in it crashes
Code:
package Android.sdk;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.location.Location;
import android.location.LocationManager;
import android.location.GpsStatus;
import android.location.LocationListener;
import android.os.Parcelable.Creator;
public class Android extends Activity {
    /** Called when the activity is first created. */
    Location locat = new Location((Location) this.getSystemService(LOCATION_SERVICE)); // something like this. google 'initializing location variables'

            //LocationManager locatman = (LocationManager)
    @Override
    public void onCreate(Bundle savedInstanceState) {

 // holy shit its a string!

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    	final TextView tv = new TextView(this);
        final Button button = (Button) findViewById(R.id.Button);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if(locat.hasAltitude()) //i
                {
                    tv.setText(locat.getAltitude() + "");// remeber i spent 2 hours just trying to make a button
                    setContentView(tv);
                    // Perform action on click
                }
            }
        });
    }
}
//we wait for this disgrace of an operating system
// wanna have a joke race and install the telenet client on my vps and see
//which installs faster XD
// no and i want you to call it telnet lol
//same thing XD
and the manifest file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="Android.sdk">
         <uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
         <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
         <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <application>
         <activity android:name=".Android" android:label="Android">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
Please ignore my random comments to my friend XD
 
Without going into the details of Java I don't think you can do that in the declarations. You need to declare locat, and then initialize it in the onCreate method like this:

package Android.sdk;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.location.Location;
import android.location.LocationManager;
import android.location.GpsStatus;
import android.location.LocationListener;
import android.os.Parcelable.Creator;
public class Android extends Activity {
/** Called when the activity is first created. */
Location locat;

//LocationManager locatman = (LocationManager)
@Override
public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locat; = new Location((Location) this.getSystemService(LOCATION_SERVICE)); // something like this. google 'initializing location variables'
final TextView tv = new TextView(this);
final Button button = (Button) findViewById(R.id.Button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(locat.hasAltitude()) //i
{
tv.setText(locat.getAltitude() + "");// remeber i spent 2 hours just trying to make a button
setContentView(tv);
// Perform action on click
}
}
});
}
}

I can't get it to show as code, so I emboldened the change I was talking about.
 
Back
Top Bottom