Some sort of error - android

Something is wrong with my java file, but I don't know what it is. Can someone please tell me.
BTW, I'm new to this
Thank You
Screenshot

Closing braces are missing as far as i can see.

you need to give 2 closing braces after super statement

you are missing closing } braces.
put the 2 closing } braces after your onCreate() callback .
Example:-
package com.example;
import..
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Related

Logcat is not Printing

I am trying to Print some messages using Log.i but it doesn't print anything, the problem starts after I updated the Android studio.
How can I solve the problem?
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("check","**************checking");
setContentView(R.layout.activity_main);
}
}
An alternate solution, but it's not the best.
System.out.print();
Make sure you select the device you are using, you can do it on the top left side of the Logcat.
for example if you used an emulator and than a device make sure the device is selected.
Try using the tag constant
public static final string TAG = "MainActivity"
Then do
Log.d(TAG, YOURMESSAGE)
Also as an alternative you can use System.out

Compilation Error: onActivityResult(int,int,Intent) in 'package.fool' clashes with onActivityResult in 'android.support.v4.app.FragmentActivity'

I have a simple Activity that i need to implement the method 'onActivityResult' but when I do that it's returned this message about the method i've implemented.
onActivityResult(int,int,Intent) in 'package.fool' clashes with 'onActivityResult(int,int,Intent)' in 'android.support.v4.app.FragmentActivity';
My Activity:
public class Agenda extends AppCompatActivity implements RecycleViewAdapter.Listener, FragmentDrawer.FragmentDrawerListener, PreferenceManager.OnActivityResultListener {
protected void onCreate(Bundle savedInstanceState) {
Log.d("OnCreate", "----------------------------------------");
super.onCreate(savedInstanceState);
}
}
I think that there are the same override method for more than two classes, according to this information:
Overrided Methods
I would be thankfull if someone help me =D.
Problem Solved!
Actually there was no need to implement:
PreferenceManager.OnActivityResultListener
Because this method is already implicity in the Activity and the fact that i implemented again the same method was causing the error.
Anyway, thanks for the comunity help.

Context Argument in Toast.maketext()

this is my first post here. I used the search function and could not find a complete answer,so I hope this is not a redundant question.
I should note that I m really new to coding so maybe I did find an answer but did not realise it.
I have been asked in class to find two different ways to fill the argument in the code below.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Toast.makeText(???,"Clicked!", Toast.LENGTH_LONG).show();
the first way i suppose would be toast.makeText(MainActivity.this.getActivity(),....).show();
the second one?
Use the MainActivity context.
Toast.makeText(MainActivity.this,"Clicked!", Toast.LENGTH_LONG).show();
v.getContext() and this both can be used

Butterknife not detecting the source of event

I have just started working with Butterknife library and written the following code:
class myActivity extends AppCompatActivity
{
#BindView(R.id.button) Button app1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
public void selectApp(View b)
{
Button clicked=(Button)b;
if(clicked==app1)
Toast.makeText(this,"First App clicked",Toast.LENGTH_LONG).show();
}
}
here selectApp is attached through onClick in the xml view file.
But the problem is clicked==app1 is returning false even when pressing app1. The method is being called but the if condition is coming false.
Can anybody clarify.
Thanks
I think this would work:
if(clicked.getId()==R.id.button)
Also, you can use View b and not parse into a button:
if(b.getId()==R.id.button)
¿Is this your actual code? seems to lack an annotation on the method.

Initialize boolean value "no such instance field"

I get an error in debugging and I can't set this boolean value. I attached a screenshot of the error.
I call DeviceUpdateManager in my mainActivity like this:
public class MainActivity extends AppCompatActivity implements DeviceUpdateManager.OnDataCOM {
DeviceUpdateManager deviceUpdateManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.deviceUpdateManager = new DeviceUpdateManager(this.serverCOM,this.getApplicationContext(),this);
}
etc...
}
I cannot find the error... Is it related to the passing Context in another class?
EDIT:SOLVED
I reboot the PC and restarted Android Studio and everything worked great.
It happens when you changed variable name in code and running application with older name in code.
Remove below snippet from Project/build.gradle file.
minifyEnabled true
Please have a look at this link for more info.
https://stackoverflow.com/a/45281798/5870824

Categories

Resources