/MainActivity.java Secret
-
-
Save twhetzel/40d5a3307da03baf1fa37428cec73e5d to your computer and use it in GitHub Desktop.
// Add your package below | |
/* package com.example.android.justjava; */ | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.TextView; | |
/** | |
* This app displays an order form to order coffee. | |
*/ | |
public class MainActivity extends AppCompatActivity { | |
@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); | |
} | |
} |
MohammedOsama717
commented
Jun 27, 2019
via email
@Natarior
thank you! worked by changing it to ->
import androidx.appcompat.app.AppCompatActivity
didn't change anything else
only solution that worked for me
@Natarior
thank you! worked by changing it to ->
import androidx.appcompat.app.AppCompatActivity
didn't change anything elseonly solution that worked for me
Yes especially when you are using the latest version of Android Studio
hello friends i think that i have the working code
first the XML code
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Quantity"
android:textAllCaps="true" />
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="16sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Order"
android:textAllCaps="true"
android:onClick="submitOrder" />
the MainActivity.java code
package com.example.android.justjava;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
/**
This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
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(10);
}
/**
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);
}
}
AndroidManifest.xml code
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
it showed work using these firends good luck :)
Thanks @Natarior, I finally run the app the successfully by replacing android.support.v7.app.AppCompatActivity; with import androidx.appcompat.app.AppCompatActivity;
USE THE BELOW FOR activity_main.xml
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="16sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Order"
android:textAllCaps="true"
android:onClick="submitOrder" />
NOW USE THE BELOW FOR MainActivity.java
package com.example.android.justjava.;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
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);
}
}
I had the same error. I replaced the line of code, 'import android.support.v7.app.AppCompatActivity;' in line 4 or 5 with 'import androidx.appcompat.app.AppCompatActivity'. All the 6 errors i had eventually vanished including the one about "Cannot resolve v7". i'm still not totally certain that the changes are executable but it is worth a try!!
Thank you Natarior, It worked!
error: cannot find symbol variable quantity_text_view
i have this error please help.
@ashwanisng - two solutions I've seen for the error "error: cannot find symbol variable quantity_text_view" are to:
- clean and rebuild the project
- make sure the package name in the manifest.xml is the same as your package name and not an example package name
Thanks bro, Resolved already ,‘;’ semicolon was missing.
Appreciate your assist
On Thu, Jun 27, 2019 at 4:06 PM Natarior @.***> wrote:
Share your last error.I will be happy to help.On Wed, 26 Jun 2019 at 06:42, MohammedOsama717 @.***>
wrote:Thank you Natarior After I replace 'import
android.support.v7.app.AppCompatActivity;' in line 4 or 5 with 'import
androidx.appcompat.app.AppCompatActivity' the errors reduced from 6 to 1
error only.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<
https://gist.github.com/40d5a3307da03baf1fa37428cec73e5d?email_source=notifications&email_token=AMMP6IFTUHLONUQ3DUZE6OTP4L6VPA5CNFSM4HWRBMS2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFUJVC#gistcomment-2954065
,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/AMMP6IHD7DLGU6GGBUXCIQ3P4L6VPANCNFSM4HWRBMSQ.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://gist.github.com/40d5a3307da03baf1fa37428cec73e5d?email_source=notifications&email_token=AMOPYIBDJLKTEHBGD2OBY53P4SUNXA5CNFSM4HWRBMS2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFUMRE#gistcomment-2955538,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMOPYIDMIA56OVC3GWSMDV3P4SUNXANCNFSM4HWRBMSQ
.--
Regards
Mohammed Osama
IT EngineerMobile No. *+*971 52 758 1781
WhatsApp: *+*971 56 178 9919
what did you do actually I didn't get you, how did you resolve this!!!!
I had the same error. I replaced the line of code, 'import android.support.v7.app.AppCompatActivity;' in line 4 or 5 with 'import androidx.appcompat.app.AppCompatActivity'. All the 6 errors i had eventually vanished including the one about "Cannot resolve v7". i'm still not totally certain that the changes are executable but it is worth a try!!
Thanks Ikenna it worked like a gem
thank you very much is work thes code 🥇 :-)
package com.example.android.justjava;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
/**
This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
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(10);
}
/**
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);
}
}
This was what worked for me;
- under "activity_main.xml"
Add
android:id="@+id/quantity_text_view" to TextView 0
2. Ensure that the package name in "AndroidManifestxml" is the same with "MainActivity.java
3. Under MainAcitivity.java, change "import android.support.v7.app.AppCompatActivity;" to
"import android.appcompat.app.AppCompatActivity;"
@udacityandroid PLease update the errors in the Course ,it is too much time consuming ! OR don't mention that this course is free, it is just waste of time !
- If you get an error when copying this code into Android studio, update it to match teh package name found in the project's AndroidManifest.xml file.>>>>Its important step
- then in java >>import android.support.v7.app.AppCompatActivity;<< this import line of code has been updated to another one ,
- so delete this.& drag your mouse to AppCompatActivity text of this line of code. >>public class MainActivity extends ### AppCompatActivity
- now press
alt+enter
- and select import.
- the issue will be fixed& error will be gone.
- `/**
- IMPORTANT: Make sure you are using the correct package name.
- This example uses the package name:
- package com.example.android.justjava
- If you get an error when copying this code into Android studio, update it to match teh package name found
- in the project's AndroidManifest.xml file.
**/
package com.example.justjava;
import android.os.Bundle;
//import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
/**
-
This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {@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);
}
}`
- This method is called when the order button is clicked.
I had the same error. I replaced the line of code, 'import android.support.v7.app.AppCompatActivity;' in line 4 or 5 with 'import androidx.appcompat.app.AppCompatActivity'. All the 6 errors i had eventually vanished including the one about "Cannot resolve v7". i'm still not totally certain that the changes are executable but it is worth a try!!
thankyou,
works wor me
This was what worked for me;
- under "activity_main.xml"
Add
android:id="@+id/quantity_text_view" to TextView 02. Ensure that the package name in "AndroidManifestxml" is the same with "MainActivity.java 3. Under MainAcitivity.java, change "import android.support.v7.app.AppCompatActivity;" to "import android.appcompat.app.AppCompatActivity;"
thanksss, works