Jump to content

Hi, I have been following the guide for building my first app from the official android studio development guide, however when I want to run my app, it gives me an 2 errors. The log gives me this information;

C:\Users\awin9\AndroidStudioProjects\MyFirstApp2\app\src\main\java\acdevelopment\myfirstapp\MyActivity.java:17: error: <identifier> expected    private static final R = ;                          ^C:\Users\awin9\AndroidStudioProjects\MyFirstApp2\app\src\main\java\acdevelopment\myfirstapp\MyActivity.java:17: error: illegal start of expression    private static final R = ;                             ^2 errors FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:compileDebugJavaWithJavac'.> Compilation failed; see the compiler error output for details.* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.BUILD FAILEDTotal time: 3.996 secs

 

And here is the code where the error is on line 33;

package acdevelopment.myfirstapp;import android.content.Intent;import android.os.Bundle;import android.support.design.widget.FloatingActionButton;import android.support.design.widget.Snackbar;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.Toolbar;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.EditText;public class MyActivity extends AppCompatActivity {    public final static String EXTRA_MESSAGE = "acdevelopment.myfirstapp.MESSAGE";    private static final R = ;    @[member='OverRide']    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_my);        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);        setSupportActionBar(toolbar);        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);        fab.setOnClickListener(new View.OnClickListener() {            @[member='OverRide']            public void onClick(View view) {                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)                        .setAction("Action", null).show();            }        });    }    @[member='OverRide']    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_my, menu);        return true;    }    @[member='OverRide']    public boolean onOptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {            return true;        }        return super.onOptionsItemSelected(item);    }    /** Called when the user clicks the Send button */    public void sendMessage(View view) {        Intent intent = new Intent(this, DisplayMessageActivity.class);        EditText editText = (EditText) findViewById(R.id.edit_message);        String message = editText.getText().toString();        intent.putExtra(EXTRA_MESSAGE, message);        startActivity(intent);        //Do something in response to button    }}

        My PC Specs:          CPU: i5 4690k(stock speed of 3.50GHz)          GPU: MSI GTX 770 4GB          Storage: WD Blue 1TB HDD and 120GB Samsung 840 EVO SSD             Ram: 8GB Corsair Vengeance Pro 1600MHz           Motherboard: Z97 Asus Maximus VII Ranger          PSU: Corsair RM650 650W          CPU Cooler: Coolermaster Hyper 212 EVO                    Case: Fractal Design R4 Black Pearl with window         OS: Windows 10 Pro                                

Link to comment
https://linustechtips.com/topic/525409-android-studio-help-for-app-developemnt/
Share on other sites

Link to post
Share on other sites

Ok so the issue is that you are trying to create a variable with no value incorrectly and also did not give the variable type. It should be something like

private static final R;

 

But put the variable type between final and R

So for example an int

private static final int R

but instead of int use the correct type for your code

Link to post
Share on other sites

Ok so the issue is that you are trying to create a variable with no value incorrectly and also did not give the variable type. It should be something like

private static final R;

 

But put the variable type between final and R

So for example an int

private static final int R

but instead of int use the correct type for your code

 

I have just been trying to put in different variables, however as the code was pre-set and this is my first development im not really sure what exactly to enter and the variables i did try didn't work. The code shouldn't give me an error anyway because i've followed exactly the steps Google has said in the guide and also the guide doesn't tell me to change any lines of code that were already there, other than adding new lines of code to add new stuff into the app.

        My PC Specs:          CPU: i5 4690k(stock speed of 3.50GHz)          GPU: MSI GTX 770 4GB          Storage: WD Blue 1TB HDD and 120GB Samsung 840 EVO SSD             Ram: 8GB Corsair Vengeance Pro 1600MHz           Motherboard: Z97 Asus Maximus VII Ranger          PSU: Corsair RM650 650W          CPU Cooler: Coolermaster Hyper 212 EVO                    Case: Fractal Design R4 Black Pearl with window         OS: Windows 10 Pro                                

Link to post
Share on other sites

I have just been trying to put in different variables, however as the code was pre-set and this is my first development im not really sure what exactly to enter and the variables i did try didn't work. The code shouldn't give me an error anyway because i've followed exactly the steps Google has said in the guide and also the guide doesn't tell me to change any lines of code that were already there, other than adding new lines of code to add new stuff into the app.

 

Can you give me a link to the guide?

Link to post
Share on other sites

        My PC Specs:          CPU: i5 4690k(stock speed of 3.50GHz)          GPU: MSI GTX 770 4GB          Storage: WD Blue 1TB HDD and 120GB Samsung 840 EVO SSD             Ram: 8GB Corsair Vengeance Pro 1600MHz           Motherboard: Z97 Asus Maximus VII Ranger          PSU: Corsair RM650 650W          CPU Cooler: Coolermaster Hyper 212 EVO                    Case: Fractal Design R4 Black Pearl with window         OS: Windows 10 Pro                                

Link to post
Share on other sites

@Butter1484 could you send me a screenshot of it please as I just tried deleting that line of code but the app crashes whenever I press the send button within the app.

        My PC Specs:          CPU: i5 4690k(stock speed of 3.50GHz)          GPU: MSI GTX 770 4GB          Storage: WD Blue 1TB HDD and 120GB Samsung 840 EVO SSD             Ram: 8GB Corsair Vengeance Pro 1600MHz           Motherboard: Z97 Asus Maximus VII Ranger          PSU: Corsair RM650 650W          CPU Cooler: Coolermaster Hyper 212 EVO                    Case: Fractal Design R4 Black Pearl with window         OS: Windows 10 Pro                                

Link to post
Share on other sites

@drc00k3 I have already tried deleting that line and the app crashes when I press the send button.

        My PC Specs:          CPU: i5 4690k(stock speed of 3.50GHz)          GPU: MSI GTX 770 4GB          Storage: WD Blue 1TB HDD and 120GB Samsung 840 EVO SSD             Ram: 8GB Corsair Vengeance Pro 1600MHz           Motherboard: Z97 Asus Maximus VII Ranger          PSU: Corsair RM650 650W          CPU Cooler: Coolermaster Hyper 212 EVO                    Case: Fractal Design R4 Black Pearl with window         OS: Windows 10 Pro                                

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×