How do I resolve a Redeclaration Error in Android Studio

This code is for a button that would be on the android emulator. However, when I place this code in the main activity.kt it gives me multiple errors. The first error I experience is a redeclaration error on line 9 on the main activity

package com.example.android.justjava

import android.R
import android.os.Bundle
import android.support.v7.app.ActionBarActivity
import android.view.View
import android.widget.TextView

// This activity displays an order form to order coffee.
class MainActivity : ActionBarActivity() {
    protected fun onCreate(savedInstanceState: Bundle) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
    }

    // this method is called when the order button is clicked.
    fun submitOrder(view: View) {
      display(1)
    }

    // This method displays the given quantity value on the screen.
    private fun display(number: Int) {
      val quantityTextView = findViewById(R.id.quantity_text_view as TextView
      quantityTextView.text = "" + number
    }
}

This activity displays an order form to order coffee.

public class MainActivity extends ActionBarActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
   }

   // This method is called when the order button is clicked.
   public void submitOrder(View view) {
       display(1);
   }

   // This method displays the given quantity value on the screen.
   private void display(int number) {
      TextView quantityTextView =(TextView) findViewById (R.id.quantity_text_view);
      quantityTextView.setText("" + number);
   }
}

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

The problem you face is that you have 2 activities with the same name MainActivity – one in Java, and second in Koltin. Both classes (activities in this case) are compiled into the same application – you have 2 symbols with the same name.

yes, Koltin and Java look the same after the compiler finish with them 🙂