Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8953693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:09:22+00:00 2026-06-15T14:09:22+00:00

i have some trouble with my android code here is my MainActivity.java public class

  • 0

i have some trouble with my android code

here is my MainActivity.java

public class MainActivity extends MapActivity {

        MapView mapView; 
        MapController mc;
        GeoPoint p;
        Button b;
        EditText e;
        TextView t;
        String x;
        String longi ;
        String lati ;
        Spinner naja;

        String[] jalan = {"A.Yani","Ambengan", "Anjasmoro","Baliwerti","Basuki Rahmat","Bintoro","Ciliwung","Darmo Raya","Darmokali","Diponegoro Raya","Dharmawangsa","Dinoyo","Embong Kemiri","Embong Malang"};
        class MapOverlay extends com.google.android.maps.Overlay
        {
            @Override
            public boolean draw(Canvas canvas, MapView mapView, 
            boolean shadow, long when) 
            {
                super.draw(canvas, mapView, shadow);                   

                //---translate the GeoPoint to screen pixels---
                Point screenPts = new Point();
                mapView.getProjection().toPixels(p, screenPts);

                //---add the marker---
                Bitmap bmp = BitmapFactory.decodeResource(
                    getResources(), R.drawable.bawah);            
                canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
                return true;
            }
        } 
        public boolean onKeyDown(int keyCode, KeyEvent event) 
        {
            MapController mc = mapView.getController(); 
            switch (keyCode) 
            {
                case KeyEvent.KEYCODE_3:
                    mc.zoomIn();
                    break;
                case KeyEvent.KEYCODE_1:
                    mc.zoomOut();
                    break;
            }
            return super.onKeyDown(keyCode, event);
        }    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            mapView = (MapView) findViewById(R.id.mapview);
            LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
            View zoomView = mapView.getZoomControls(); 

            naja=(Spinner)findViewById(R.id.simpleGM_adress);
            ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, jalan);
            aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
             naja.setAdapter(aa);
            t=(TextView)findViewById(R.id.simpleGM_tv);
            e=(EditText)findViewById(R.id.simpleGM_adress);
            zoomLayout.addView(zoomView, 
                new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, 
                    LayoutParams.WRAP_CONTENT)); 
            mapView.displayZoomControls(true);
            /*
            mc = mapView.getController();
            String coordinates[] = {longi, lati};
            double lat = Double.parseDouble(coordinates[0]);
            double lng = Double.parseDouble(coordinates[1]);

            p = new GeoPoint(
                (int) (lat * 1E6), 
                (int) (lng * 1E6));

            mc.animateTo(p);
            mc.setZoom(17); 
            mapView.invalidate();
            mc.animateTo(p);
            mc.setZoom(17); 

            //---Add a location marker---
            MapOverlay mapOverlay = new MapOverlay();
            List<Overlay> listOfOverlays = mapView.getOverlays();
            listOfOverlays.clear();
            listOfOverlays.add(mapOverlay);        

            mapView.invalidate();*/
        }


        public void clickHandler(View view){
            switch (view.getId()){
            case R.id.simpleGM_btn_search:
                x = jalan[naja.getSelectedItemPosition()];
                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("nama_jalan", x));
                /*            String valid = "1";*/ 
             String response = null;

             try {

                response = CustomHttpClient.executeHttpPost("http://192.168.1.4/android/kordinat.php", postParameters);


                String result = response.toString();  
                //parse json data

                   try{
                           longi = "";
                           lati = "";

                     JSONArray jArray = new JSONArray(result);
                           for(int i=0;i<jArray.length();i++){

                                   JSONObject json_data = jArray.getJSONObject(i);
                                   Log.i("log_tag","nama_jalan: "+json_data.getString("nama_jalan")+
                                           ", latitude: "+json_data.getString("latitude")+
                                           ", longitude: "+json_data.getString("longitude")
                                   );
                                   if(result.equals(null)){
                                   //Get an output to the screen
                                  longi += "Data tidak ada";
                                   }
                                   else{
                                   lati += json_data.getString("latitude");
                                   longi += json_data.getString("longitude");
                                   }
                           }
                   }


                   catch(JSONException e){
                           Log.e("log_tag", "Error parsing data "+e.toString());
                   }

                   try{
                       mc = mapView.getController();
                    String coordinates[] = {longi, lati};
                    double lat = Double.parseDouble(coordinates[0]);
                    double lng = Double.parseDouble(coordinates[1]);

                    p = new GeoPoint(
                        (int) (lat * 1E6), 
                        (int) (lng * 1E6));

                    mc.animateTo(p);
                    mc.setZoom(17); 
                    mapView.invalidate();
                    mc.animateTo(p);
                    mc.setZoom(17); 

                    //---Add a location marker---
                    MapOverlay mapOverlay = new MapOverlay();
                    List<Overlay> listOfOverlays = mapView.getOverlays();
                    listOfOverlays.clear();
                    listOfOverlays.add(mapOverlay);        

                    mapView.invalidate();
                   }


                   catch(Exception e){

                    Log.e("log_tag","Error in Display!" + e.toString());;          

                   }   

              }

                    catch (Exception e) {

               Log.e("log_tag","Error in http connection!!" + e.toString());     

              }
             break;
            }
        }

        @Override
        protected boolean isRouteDisplayed() {
            // TODO Auto-generated method stub
            return false;
        }
    }

here is my main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/simpleGM_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
    <TextView
android:id="@+id/simpleGM_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tentukan Jalanmu"
android:layout_x="11px"
android:layout_y="5px"
>
</TextView>
<Spinner
                android:id="@+id/simpleGM_adress" 
                android:layout_width="240px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="12px"
android:layout_y="30px"
></Spinner>
<Button
android:id="@+id/simpleGM_btn_search"
android:layout_width="59px"
android:layout_height="wrap_content"
android:layout_x="256px"
android:layout_y="30px"
android:text="find"
android:onClick="clickHandler"
>
</Button>

<com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_x="2px"
android:layout_y="100px"
android:clickable="true"
        android:apiKey="00j2bA4ivSvH0cSDJJ4aiPiVCq_OSH0adwf6I2w"
    />
    <LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        /> 

</AbsoluteLayout>

and here is my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="udin.googlemaps"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <uses-library android:name="com.google.android.maps" />
    </application>
    <uses-permission android:name="android.permission.INTERNET" />   
</manifest>

when i run my program , it shows error like this

“java.lang.RuntimeException: Unable to start activity
ComponentInfo{udin.googlemaps/udin.googlemaps.MainActivity} :
java.lang.ClassCastException: android.widget.Spinner “

can anyone help me to solve this error?

why this is happening?

any help will much appreciate.

Thank You.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:09:23+00:00Added an answer on June 15, 2026 at 2:09 pm

    The problem is because of

       naja = (Spinner)findViewById(R.id.simpleGM_adress);
    

    and

       e = (EditText)findViewById(R.id.simpleGM_adress);
    

    The first one is a Spinner, not an EditText, you can’t cast it to an EditText.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm have some trouble with the fulltext CONTAINS operator. Here's a quick script to
I have trouble with some inline assembly code. I'm trying to load items from
good day we are developing game for android and have some trouble with resource
I have some trouble sending an Intent from a Service to an Activity. Here's
I have some trouble to connect a USB smart card reader on my Android
I am having some trouble getting an options menu working in Android. I have
im new on Android. I have some trouble with the insert statement in the
I have Mono for Android trial version and am having some trouble with the
I'm trying to make a java android application with bluetooth and I have some
I have some trouble when I try to map object to int . My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.