1

I have two classes, Syros1Activity and MapActivity . In the first activity (Syros1Activity) I have some buttons. The second is Map. I want to connect one of these buttons and when I select it start MapActivity. Here is my code:

MapActivity:

import android.os.Bundle;
import com.view.View;
import com.google.android.maps.MapView;

public class  MapActivity {

public void onCreate(Bundle savedInstanceState) {
     super.**onCreate**(savedInstanceState); --->Here i get a mistake The method onCreate(Bundle) is undefined for the type Object
     setContentView(R.layout.maplayout);
     MapView mapView = (MapView) findViewById(R.id.mapview);
     mapView.setBuiltInZoomControls(true);
}

protected boolean isRouteDisplayed(){ return false;}
private void setBuiltInZoomControls(boolean b) {
     throw new UnsupportedOperationException("Not yet implemented");
}

private void setBuiltInZoomControls(boolean b) {
    throw new UnsupportedOperationException("Not yet implemented");
 }

private MapView findViewById(int mapview) {
    // TODO Auto-generated method stub
return null;
}

private void setContentView(int maplayout) {
    // TODO Auto-generated method stub
}
}

Syros1Activity:

import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.view.View;
import android.view.View.OnClickListener;


public class Syros1Activity extends Activity implements OnClickListener{
    private static final int PROGRESS = 0x1;
    private ProgressBar mProgress;
    private int mProgressStatus = 0;

    private static final String DEBUG_TAG = null;
    private static final OnClickListener OnClickListener = null;

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

        Button btn11 = (Button) findViewById(R.id.Button11);
               btn11.setOnClickListener(this);


        Button btn12 = (Button) findViewById(R.id.Button12);
               btn12.setOnClickListener(this);

        Button btn13 = (Button) findViewById(R.id.Button13);
               btn13.setOnClickListener(this);

        Button btn21 = (Button) findViewById(R.id.Button21);
               btn21.setOnClickListener(this);

        Button btn22 = (Button) findViewById(R.id.Button22);
               btn22.setOnClickListener(this);

        Button btn23 = (Button) findViewById(R.id.Button23);
               btn23.setOnClickListener(this);

    }


    public void  getLocation (Location location  ) { 
        try { 
            LocationManager locMgr = (LocationManager)
                getSystemService(LOCATION_SERVICE);
            Location recentLoc = locMgr.
                getLastKnownLocation(LocationManager.GPS_PROVIDER);
            Log.i(DEBUG_TAG, "loc: " + recentLoc.toString());

            }
    catch (Exception e) {
        Log.e(DEBUG_TAG,"Location failed", e);

    }

    }

    public void onClick(View v) {
        if (v.getId() == R.id.Button11){
            Toast.makeText(this, "Loading Google Map", Toast.LENGTH_SHORT)
            .show();
            Intent intent =new Intent();
            intent.setClass(getApplicationContext(),MapActivity.class);
            startActivity(intent);  
        }



         else if(v.getId() == R.id.Button12){
            Toast.makeText(this, "Loading Sights", Toast.LENGTH_SHORT)
            .show();
        }
         else if(v.getId() == R.id.Button13){
            Toast.makeText(this, "Loading Beach", Toast.LENGTH_SHORT)
            .show();
    }
        else if(v.getId() == R.id.Button21){
            Toast.makeText(this, "Loading Bars", Toast.LENGTH_SHORT)
            .show();
    }
        else if(v.getId() == R.id.Button21){
        Toast.makeText(this, "Loading Bars", Toast.LENGTH_SHORT)
        .show();
    }
        else if(v.getId() == R.id.Button22){
            Toast.makeText(this, "Loading Restaurant", Toast.LENGTH_SHORT)
            .show();
    }  
        else if(v.getId() == R.id.Button23){
           Toast.makeText(this, "Loading Developer Information", Toast.LENGTH_SHORT)
           .show();
    } 
    }



    public static OnClickListener getOnclicklistener() {
        return OnClickListener;
    }   
}   
Martin G
  • 17,357
  • 9
  • 82
  • 98
Baggelisrouk
  • 11
  • 1
  • 4

2 Answers2

0

Rename your MapActivity class, call it MyMapActivity

then define the class like this, public class MyMapActivity extends MapActivity

+

Make sure you use one of the Google APIs so you can use the Google Maps Library

+

Make sure you add this code in your AndroidManifest.xml (under application tag) file in order to use Google Maps

<uses-library android:required="true" android:name="com.google.android.maps" />
Hesham Saeed
  • 5,358
  • 7
  • 37
  • 57
  • Thanks now is ok this problem. – Baggelisrouk Apr 22 '12 at 20:27
  • You welcome, you can mark this as answer, to be useful for other people have the same as your problem, Good luck in coding! – Hesham Saeed Apr 22 '12 at 20:29
  • Now when i select button which i have put mymapactivity to start i get Unfortunately, has stop. Any help about this? – Baggelisrouk Apr 22 '12 at 20:30
  • Open the activity like this, Intent intent = new Intent(this,MyMapActivity.class); startActivity(intent); – Hesham Saeed Apr 22 '12 at 20:39
  • if you can get the stack trace / error log from LogCat, would be helpful to debug. – Hesham Saeed Apr 22 '12 at 20:56
  • 04-22 23:54:09.507: W/dalvikvm(12297): threadid=1: thread exiting with uncaught exception (group=0x40c341f8) 04-22 23:54:09.507: E/AndroidRuntime(12297): FATAL EXCEPTION: main – Baggelisrouk Apr 22 '12 at 21:00
  • 04-22 23:54:09.507: E/AndroidRuntime(12297): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.bountouris/com.bountouris.MyMapActivity}; have you declared this activity in your AndroidManifest.xml? 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1511) – Baggelisrouk Apr 22 '12 at 21:00
  • 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1387) 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.app.Activity.startActivityForResult(Activity.java:3190) 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.app.Activity.startActivity(Activity.java:3297) – Baggelisrouk Apr 22 '12 at 21:01
  • 04-22 23:54:09.507: E/AndroidRuntime(12297): at com.bountouris.Syros1Activity.onClick(Syros1Activity.java:74) 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.view.View.performClick(View.java:3591) 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.view.View$PerformClick.run(View.java:14263) 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.os.Handler.handleCallback(Handler.java:605) – Baggelisrouk Apr 22 '12 at 21:01
  • 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.os.Handler.dispatchMessage(Handler.java:92) 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.os.Looper.loop(Looper.java:137) 04-22 23:54:09.507: E/AndroidRuntime(12297): at android.app.ActivityThread.main(ActivityThread.java:4507) 04-22 23:54:09.507: E/AndroidRuntime(12297): at java.lang.reflect.Method.invokeNative(Native Method) – Baggelisrouk Apr 22 '12 at 21:02
  • 04-22 23:54:09.507: E/AndroidRuntime(12297): at java.lang.reflect.Method.invoke(Method.java:511) 04-22 23:54:09.507: E/AndroidRuntime(12297): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 04-22 23:54:09.507: E/AndroidRuntime(12297): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 04-22 23:54:09.507: E/AndroidRuntime(12297): at dalvik.system.NativeStart.main(Native Method) – Baggelisrouk Apr 22 '12 at 21:02
  • This 6 posts are all the Errors – Baggelisrouk Apr 22 '12 at 21:03
  • Declare the map activity in your manifest, or if you already declared it, change the name of it in the manifest, if you don't know how, tell me and I will tell you. – Hesham Saeed Apr 22 '12 at 21:04
  • Now i fix it thanks. When mymapactivity opens it appears only box. and does not loading map. can you help me? – Baggelisrouk Apr 22 '12 at 21:11
  • You have to use debug key (from google), if you will only be debugging, if you will publish the application in the market you have to use release key (from google), inside the apiKey of MapView in your maplayout.xml file. – Hesham Saeed Apr 22 '12 at 21:16
  • I have one more question. I want to add at the startup of my app a video 5 sec. How can i do this? I have to create a new activity? and a new layout? – Baggelisrouk Apr 22 '12 at 21:23
  • Please post that in another question, its unrelated to this question, and mark my answer. Thanks. – Hesham Saeed Apr 22 '12 at 21:26
0

did you used this permission in Manifest file

<uses-permission android:name="android.permission.INTERNET" />

if not mention it in your Manifest File out side the application tag

Ravi1187342
  • 1,247
  • 7
  • 14