Cannot resolve method java ошибка

Android: Cannot Resolve Method

I’m trying to program custom states for programatically generated buttons in my app using the process explained here, but i’m getting the «cannot resolve method» compiler error when I try to call a method in my custom button class. The method i’m trying to call is public so I’m not sure why it’s not visible in the scope i’m trying to call it from. Thoughts?

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) < View v = inflater.inflate(R.layout.menu_fragment, container, false); typeOneArray = new boolean[21]; typeTwoArray = new int[21]; //programmatic button generation buttonHolder = (LinearLayout) v.findViewById(R.id.buttonLayoutParent); buttonHolder.setGravity(Gravity.RIGHT); for (int j = 0; j < 21; j++) < final int iteration = j; final Button btnTag = new CustomButton(getActivity()); //CUSTOM BUTTON INSTANTIATION btnTag.setId(j); btnTag.setBackgroundResource(R.drawable.custom_button); buttonHolder.addView(btnTag); btnTag.setOnTouchListener(new View.OnTouchListener() < @Override public boolean onTouch(View v, MotionEvent event) < if (event.getAction() == MotionEvent.ACTION_DOWN) < //button was clicked //clickCounter0++; typeTwoArray[iteration] = typeTwoArray[iteration] + 1; Handler handler = new Handler(); Runnable singleClickLogic = new Runnable() < @Override public void run() < if (typeTwoArray[iteration] !=0) < Toast.makeText(getActivity(), "single click", Toast.LENGTH_SHORT).show(); typeTwoArray[iteration] = 0; >> >; //Double click if (typeTwoArray[iteration] == 2) < btnTag.setButtonTypeOne(true); //THIS IS WHERE THE ERROR HAPPENS Toast.makeText(getActivity(), "double click", Toast.LENGTH_SHORT).show(); typeTwoArray[iteration] = 0; >//Single click else if (typeTwoArray[iteration] == 1) < handler.postDelayed(singleClickLogic, 250); >> else if (event.getAction() == MotionEvent.ACTION_UP) < >return false; > >); > return v; > 
public class CustomButton extends Button < private boolean stateTwo = false; private boolean stateOne = false; private static final int[] STATE_ONE = ; private static final int[] STATE_TWO = ; public CustomButton(Context context) < super(context); >public void setButtonTypeOne(boolean buttonState) < stateOne = buttonState; >public void setButtonTypeTwo(boolean buttonState) < stateTwo = buttonState; >@Override protected int[] onCreateDrawableState(int extraSpace) < final int[] drawableState = super.onCreateDrawableState(extraSpace + 2); if (stateOne) < mergeDrawableStates(drawableState, STATE_ONE); >if (stateTwo) < mergeDrawableStates(drawableState, STATE_TWO); >return drawableState; > 

Источник

Читайте также:  font-weight

Cannot resolve method android

I am getting an error «Cannot resolve method ‘maketext (android.content.Context, java.lang.String, java.lang.String, int ‘)». I assume that there is some problem with the altitude part (int). Can someone tell me how to fix this?

 @OnClick(R.id.btn_get_last_location) public void showLastKnownLocation() < if (mCurrentLocation != null) < Toast.makeText(getApplicationContext(), "Lat: " + mCurrentLocation.getLatitude() + ", Lng: " + mCurrentLocation.getLongitude(), ", Alt: " + mCurrentLocation.getAltitude(), Toast.LENGTH_LONG).show(); >else < Toast.makeText(getApplicationContext(), "Last known location is not available!", Toast.LENGTH_SHORT).show(); >> 

2 Answers 2

 Toast.makeText(getApplicationContext(), "Lat: " + mCurrentLocation.getLatitude() + ", Lng: " + mCurrentLocation.getLongitude(), ", Alt: " + mCurrentLocation.getAltitude(), Toast.LENGTH_LONG).show(); 
 Toast.makeText(getApplicationContext(), "Lat: " + mCurrentLocation.getLatitude() + ", Lng: " + mCurrentLocation.getLongitude() + ", Alt: " + mCurrentLocation.getAltitude(), Toast.LENGTH_LONG).show(); 

It took me quite some time to find what is the difference. Could you please add some explaination about that there is a missing string concatenation ( + )?

 Toast.makeText(getActivity(), "Lat: " + mCurrentLocation.getLatitude() + ", Lng: " + mCurrentLocation.getLongitude() + ", Alt: " + mCurrentLocation.getAltitude(), Toast.LENGTH_LONG).show(); 
 Toast.makeText(getApplicationContext(), "Lat: " + mCurrentLocation.getLatitude() + ", Lng: " + mCurrentLocation.getLongitude(), ", Alt: " + mCurrentLocation.getAltitude(), Toast.LENGTH_LONG).show(); 

But This is not the best approach,According to the android Documentations use string with place holder. String With Place Holders

Источник

Cannot resolve method setText/getText

So I am still learning Android and Java and I was trying to follow the code on this page: http://www.androidauthority.com/use-remote-web-api-within-android-app-617869/ The thing is that the code they provide does not work for me, and Android Studio says Cannot resolve method for both the setText and the getText methods. This is my code:

 package com.example.beldr.apitest; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ProgressBar; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import static com.example.beldr.apitest.R.id.emailText; import static com.example.beldr.apitest.R.id.responseView; public class MainActivity extends AppCompatActivity < @Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); >> class RetrieveFeedTask extends AsyncTask  < private Exception exception; private ProgressBar progressBar; protected void onPreExecute() < progressBar.setVisibility(View.VISIBLE); responseView.setText(""); >protected String doInBackground(Void. urls) < String email = emailText.getText().toString(); // Do some validation here try < URL url = new URL("https://api.fullcontact.com/v2/person.json" + "email=" + email + "&apiKey=" + "126042055"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try < BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) < stringBuilder.append(line).append("\n"); >bufferedReader.close(); return stringBuilder.toString(); > finally < urlConnection.disconnect(); >> catch(Exception e) < Log.e("ERROR", e.getMessage(), e); return null; >> protected void onPostExecute(String response) < if(response == null) < response = "THERE WAS AN ERROR"; >progressBar.setVisibility(View.GONE); Log.i("INFO", response); responseView.setText(response); > > 
TextView textView=(TextView)findViewById(R.id.responseView); 

Источник

Читайте также:  Check php settings on server

IntelliJ System.out.println() — Cannot resolve method println(java.lang.String)

nothing helps. buy running simple hello world method. It keeps showing this error:

screenshot

Is there someone able to help me?

Add: I am not using any addon, or «Marven». it simply stops to work. And normally no import should be needed for println method. This error corrupted all my previous learning projects. So it doesn’t seems to be local or connect to any single class.

@Prabesh Bhattarai in my case, I found out latter that was an user class also named System , there fore caused conflict with the java’s System class.

8 Answers 8

file -> invalidated caches / Restart

One reason for this to happen is if you have print statement somewhere on the body of the class, and not inside a method.

enter image description here

But if the print is inside a method, it should work fine.

enter image description here

I think if you have tried the method above, maybe you can consider where you use System.out.println() because this method should only used in main(String args[])<> ,the latest version of the Idea is OK. I wish what said can help you.

That’s not true. You can use it in any method you like, as long as it is not directly on class level.

If you have orcale sdk configured as your project sdk there is no way System.out.println can’t be found — besides you are using another System.out .

So my guess is that you don’t have a proper project sdk configured.

Goto to Project Settings or press Ctrl + Alt + Shift + S , go to Project Settings -> Project and check if your sdk is setup correctly.

In my case my project was set up to Java 6th and I had installed jre1.8.0_131 which I assume was causing the problem. After changing Java to level 8 problem have been solved.

Press Ctrl+Alt+Shift+s or go to File -> Project Structure -> Project, and set Project Language Level to yours.

Источник

Оцените статью