visual studio android import cant resolved after update - android

I updated Visual Studio, then my Android project had errors such as import could not be resolved. It could not be resolved to a text type. The type could not be resolved. Then I created a new project with the same settings. However, it had the same errors. It does not work because of the code, but maybe it knows who knows the code here.
package com.Android2;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class Android2 extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* Create a TextView and set its text to "Hello world" */
TextView tv = new TextView(this);
tv.setText("Hello World!");
setContentView(tv);
}
}

There is no problem with your code or imports...
I know it is hard work and a serious change when it comes to shortcuts, menus, overview, etc., but i would suggest to use android studio instead of visual studio if you only write android apps in java. I used visual studio too and switched to android studio.
Android Studio will give you more comfort than every other ide in programming android apps in java!
I know this problems you wrote about very well and had the same. Sry that this isnt a really answer of your problem and does not solves your concrete problem.
Tips for solving, you probably already know:
reboot your pc and visual studio if you not already did
delete caches or other from visual studio
rebuilt/clean your project
not easy, but reinstall visual studio
I hope i could help anyway!

Related

Android studio project could not find android.view.View

My Android project show that it is not able to find the android.view.View class but still it is being compiled and run on simulator and devices.
apart from android.view.View All other class of the package is accessible like
This is not available ==> import android.view.View;
this is available => import android.view.ViewGroup;
I have tried many things like Clean, Rebuild, restart and Invalidate cache and restart but not fixed this issue.
Please check the code and help me to fix this issue.
import android.view.View;
public class AppSettingsActivity extends BaseActivity implements View.OnClickListener, AdListener {
//Other objects
private static final String TAG = AppSettingsActivity.class.getSimpleName();
//Data objects
// //Design
private LinearLayout banner_container;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
initViews();
}
private void initViews() {
//Actionbar init
//Action bar
TextView idTvTitle = findViewById(R.id.idTvTitle);
findViewById(R.id.idTvSelectDefaultActivity).setOnClickListener(this);
findViewById(R.id.idTvSelectAppLang).setOnClickListener(this);
findViewById(R.id.idIvBack).setOnClickListener(this);
findViewById(R.id.idTvCalcSetting).setOnClickListener(this);
//Set data
//Set Actionbar Title
idTvTitle.setText(R.string.app_settings_text);
//Load Facebook ads
banner_container = findViewById(R.id.banner_container);
if (fbAdView != null) {
banner_container.addView(fbAdView);
fbAdView.loadAd();
fbAdView.setAdListener(this);
logs.e(TAG, "Face book load add called....");
}
int selectedLanguage=SessionManagement.getIntValue(AppSettingsActivity.this, AppConstant.SELECTED_LANG, AppConstant.INT_ONE);
int selectedScreen=SessionManagement.getIntValue(AppSettingsActivity.this, AppConstant.DEFAULT_SCREEN_INDEX, AppConstant.INT_ONE);
String[] languages = getResources().getStringArray(R.array.language);
String[] screens = getResources().getStringArray(R.array.screens);
((TextView)findViewById(R.id.idTvSelectDefaultActivity)).setText(screens[selectedScreen]);
((TextView)findViewById(R.id.idTvSelectAppLang)).setText(languages[selectedLanguage]);
}
I am giving this answer to my question.
I simply uninstall the Android studio and reinstall it. My previous Android studio was running with 3.5 version (Latest) and the fresh install Android studio version was also 3.5 so there was no versioning difference in it. But I don't know some How issue fixed when I reinstall AS.
After half an hour of searching, I could not found a solution that can fix my issue. Then I pass the same code to other PC and it was working well on that PC.
So This is final that no issue in the source code.
Then 2nd suspect is the android studio
I uninstall Android Studio and install it again, it took me 1 hour to set-up and make the code workable but it saves 30GB of my hard disk space so it was worth it.
But still, Android studio manage SDK and build tools very badly

TextView widget cannot be resolved

I have created a blank activity project in Android Studio choosing API 14 (4.0 ICS) as the Minimum SDK.
​In the main activity I assigned an id to the default 'hello world' TextView​ as below
<TextView
android:id="#+id/hw_1"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
​I then tried to change the default 'Hello world' message programmatically ​by doing
TextView tv = (TextView) findViewById(R.id.hw_1);
tv.setText("my new message");
However, I keep getting 'cannot resolve symbol TextView' and when trying to import I just do not see the TextView in the list of the widgets under android.widget package as depicted in the image below.
I am just starting Android and thinking that I might be missing something obvious but can't figure out what exactly cause I do see TextView inside the Android jar linked to the project etc.
Check the image below.
In case someone runs into this.
I figured there should be something on the IDE level and decided to check out how IntelliJ decides what to show in the import popup. After few minutes of digging I found the "Exclude from Import and Completion" section under IDE Settings -> Editor and there it was - the TextView import was explicitly excluded from import and completion suggestoins.
Not sure how it got there in the first place, but oh well ..

GestureDetector cannot be resolved to a type

I'm learning to use GestureDetector and following android's official developer's guide, but when I try to run a snippet of code I met a problem..
public class MainActivity extends Activity implements
GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener{}
Here Eclipse gives me a error: GestureDetector cannot be resolved to a type, I tried to fixed it by cleaning and rebuilding, re-import android support library and including it in the build path and pressing ctrl+shift+o as well..but my Eclipse is just not letting this error go away...
Please give me some advice and I really appreciate that.
P.S., I'm following codes on Android Gesture Detector Training
try writing this code in your activity
import android.view.GestureDetector;
This will do the trick.

Android/Eclipse Question - "id cannot be resolved or is not a field" error

Hello I started trying to develop Android applications today, but I have a problem:
I decided to try out making a Web View using this tutorial - http://developer.android.com/resources/tutorials/views/hello-webview.html
But when I put the code in for the OnCreate() method I get an "id connot be resolved or is not a field" error. Here is my code:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
HelloWebView.java:
package com.example.hellowebview;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class HelloWebView extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
}
}
I have tried cleaning, CTRL+SHIFT+O, and just completely restarting the project. There error is in the statement:
mWebView = (WebView) findViewById(R.id.webview);
and Eclipse just says "id cannot be resolved or is not a field"
Also, I installed everything today using the guide on developer.android.com and followed all steps correctly. I have made Java programs on this computer before so I don't think there is a problem related to the JDK/JRE.
I managed to fix the problem by simply restarting my computer. I guess in order for all the development tools to work properly a computer restart is necessary? I can't believe I didn't think about doing this before though. Thanks for those who tried to help.
There are a couple of similar questions here. Take a look at some answers:
import of android.R : this response: R cannot be resolved - Android error
java tools not building R.java: R cannot be resolved - Android error
problem with default.properties file: R cannot be resolved - Android error
and finally, something reported by several: make sure the file is main.xml and not Main.xml
Found the solution that finally worked for me after researching hours. Turns out the problem is not your R.java, All you gotta do is 'Clean' the project one last time. Save your project. And open Eclipse again. The problem is GONE!
Look into the R File Generated and see whether you see a Public Static Class called Id if so then see whether it contains a public static final int webview ( that you have created )
I also get that from time to time.
This usually (or always) does it for me:
Project - Clean - "your project"

LogCat not displaying anything after crash/reinstall

First off, as background: I am on a Mac, running OS X 10.6.7. Using Eclipse for an Android Development class I'm in (and hopefully eventually to actually develop directly for Android).
I had a nasty crash of Eclipse a few days ago, and after restarting I stopped getting any output from LogCat whatsoever. I tried everything I could think of, and I couldn't get anything at all to show up in the log. I tried a nuke-it-from-orbit reinstall of Eclipse, and it's at least made a little bit of a difference. When I run this code snippet I came up with to test things:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class LogTester extends Activity {
/** Called when the activity is first created. */
public static final String TAG = "LogTester";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "Activity was created");
Log.d(TAG, "Anybody Home?");
}
}
...it shows me this (apparently I can't post images directly as a noob), but when I actually click on the LogTester tab of LogCat, I see nothing. The same thing vice-versa when I click back over to the main log tab, which as you can see should have 11 new items in it.
I tried changing the font since maybe there was some sort of issue with displaying the font, and I've heard there are weird issues with fonts and 10.6.7. But I get a "Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench"." error and a complete refusal to change the font type. I can't figure out where Eclipse hides this preference so I can try and fiddle with it manually.
Anyone have any ideas/suggestions as to things I should try next? This is absolutely maddening. Thanks!
UPDATE (3/31 1am): I deleted and recreated my AVM for about the 15th time and LogCat suddenly started working. Hell if I know why, but I'm not questioning it.
try switching to DDMS perspective and click on your active emulator in the Device tab. Your Logcat should refresh then.
I know this post is old but a filter got turned on for some reason using Firebase which really confused me for a few mintues while I tried to figure out what was going on.
Here's where you change the filter (in the android monitor panel):

Categories

Resources