Cannot resolve symbol image_view in Wear OS project - android

I am getting a "cannot resolve symbol 'image_view'" and cannot figure out why.
Here is my main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dark_grey"
android:padding="#dimen/box_inset_layout_padding"
tools:context=".MainActivity"
tools:deviceIds="wear">
<android.support.v7.widget.FrameLayout
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/inner_frame_layout_padding"
app:boxedEdges="all" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/image_view" />
</android.support.v7.widget.FrameLayout>
</androidx.wear.widget.BoxInsetLayout>
and my the beginning part of my MainActivity.java:
package com.example.weartest3;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.android.gms.wearable.Asset;
import com.google.android.gms.wearable.CapabilityClient;
import com.google.android.gms.wearable.CapabilityInfo;
import com.google.android.gms.wearable.DataClient;
import com.google.android.gms.wearable.DataEvent;
import com.google.android.gms.wearable.DataEventBuffer;
import com.google.android.gms.wearable.DataItem;
import com.google.android.gms.wearable.DataMap;
import com.google.android.gms.wearable.DataMapItem;
import com.google.android.gms.wearable.MessageClient;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.Wearable;
import java.io.InputStream;
import java.util.concurrent.ExecutionException;
public class MainActivity extends WearableActivity implements DataClient.OnDataChangedListener,
MessageClient.OnMessageReceivedListener,
CapabilityClient.OnCapabilityChangedListener {
private TextView mTextView;
private ImageView mImageView;
private static final String IMAGE_KEY = "image";
private static final String TEXT_KEY = "text";
private static final String TAG="MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.text);
mImageView = (ImageView) findViewById(R.id.image_view);
// Enables Always-on
setAmbientEnabled();
}
The line:
mImageView = (ImageView) findViewById(R.id.image_view); is showing image_view in red and that's where the error is.
I notice it does not autofind .text in:
mTextView = (TextView) findViewById(R.id.text);
but it is not showing in red.
I also had problems with:
app:boxedEdges="all"
until I added:
android.support.v7.widget
in:
Which seems strange to me, but that will be a different post.

Related

Android application that downloads images from bing image search not having the correct image

I have an android application that has a button and an image view
when clicking the button the application goes to bing image search and search for images then get the url of the first image and make it the source of the image view so that it has the first image of the search
When I do the image search using the explorer (I use chrome) I find that the first image displayed in my browser is not the same displayed in the image view
when I search for (facebook.com logo) or (google.com logo) the image view is the same of the first image shown in the search result but if I change the search to (yahoo.com logo) the image view is the second
If I change the search to (outlook.com logo) it takes the 10th image of the search and if I search for (hotmail.com logo) it does not show an image related to hotmail at all
I use JSOUP library to parse the HTML of the web page of the search results
here is the xml of the project:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="arb.myapplication.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:layout_alignParentBottom="true"
android:layout_marginBottom="131dp"
android:id="#+id/imageView" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="39dp"
android:layout_marginEnd="39dp"
android:layout_marginTop="11dp"
android:id="#+id/button3"
android:elevation="0dp" />
</RelativeLayout>
and this is the Java file of the project:
package arb.myapplication;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
class DownloadIcon extends AsyncTask<Object, Object, Integer>
{
#Override
protected Integer doInBackground(Object... objects) {
Connection connecion= Jsoup.connect("http://www.bing.com/images/search?q=outlook.com+logo");
try {
Document document=connecion.get();
Elements element=document.select("img.mimg");
String url=element.get(0).absUrl("src");
InputStream inputStream= new URL(url).openStream();
Bitmap bitmap=BitmapFactory.decodeStream(inputStream);
publishProgress(bitmap);
} catch (IOException e1) {
publishProgress(-1);
}
return 0;
}
#Override
protected void onProgressUpdate(Object... values) {
ImageView imageView=(ImageView) findViewById(R.id.imageView);
Bitmap bitmap=(Bitmap) values[0];
imageView.setImageBitmap(bitmap);
}
#Override
protected void onPostExecute(Integer integer) {
Toast.makeText(getBaseContext(),"done",Toast.LENGTH_SHORT).show();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button3=(Button) findViewById(R.id.button3);
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new DownloadIcon().execute();
}
});
}
}
Help me please

Use Glide to Show Large Vector Drawable on Lollipop and above Devices

I'm able to use BumpTech Glide to show a large Vector Drawable on pre-lollipop devices but unable to do so on lollipop and above...The activity starts but the Imageview is not shown.
Here is the layout file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF5722"
tools:context=".Main.SplashScreen2.SplashScreen2">
<ImageView
android:id="#+id/imageViewSplashScreen2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/image_of_ahilya_ghat_river_bank_of_varanasi" />
</FrameLayout>
here is the java file
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.example.raviseth.searchviewtrials.Main.MainActivityListViewPage.activities.MainActivity;
import com.example.raviseth.searchviewtrials.R;
import uk.co.senab.photoview.PhotoViewAttacher;
public class SplashScreen2 extends AppCompatActivity {
FloatingActionButton fabSplashScreen2;
ImageView imageViewSpashScreen2;
PhotoViewAttacher photoViewAttacher = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashsreen2);
imageViewSpashScreen2 = (ImageView) findViewById(R.id.imageViewSplashScreen2);
if (imageViewSpashScreen2 != null) {
photoViewAttacher = new PhotoViewAttacher(imageViewSpashScreen2);
Glide.with(getApplicationContext())
.load(R.drawable.ghat)
.into(imageViewSpashScreen2);
photoViewAttacher.update();
}
}
}

Android - Spinner, onItemSelected(...) not being called

Here's the code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONObject;
import com.project.locationapp.model.Device;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class SelectDevice extends Activity implements OnItemSelectedListener {
private Spinner deviceSpinner;
private List<Device> deviceList;
private ArrayAdapter<Device> deviceAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_device);
deviceList = new ArrayList<Device>();
try {
deviceSpinner = (Spinner) findViewById(R.id.select_device_spinner);
deviceAdapter = new DeviceAdapter(this, android.R.layout.simple_spinner_dropdown_item, deviceList);
deviceSpinner.setAdapter(deviceAdapter);
deviceSpinner.setOnItemSelectedListener(this);
DataAsyncTask loadDevices = new DataAsyncTask();
loadDevices.execute(new String[] { WebServiceURL.WEB_SERVICE + WebServiceURL.DEVICES + WebServiceURL.ALL });
} catch (Exception e){
Log.e(TAG, e.getLocalizedMessage(), e);
}
}
#Override
public void onItemSelected(AdapterView<?> a, View v, int position,
long id) {
Log.d(TAG, "called!");
Intent intent = new Intent(this, ViewTrips.class);
intent.putExtra("device_id", deviceAdapter.getItem(position).getId());
startActivity(intent);
}
}
DeviceAdapter class:
import java.util.List;
import com.project.locationapp.model.Device;
import android.content.Context;
import android.widget.ArrayAdapter;
public class DeviceAdapter extends ArrayAdapter<Device> {
public DeviceAdapter(Context context, int textViewResourceId,
List<Device> objects) {
super(context, textViewResourceId, objects);
}
}
Activity layout xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SelectDevice" >
<TextView
android:id="#+id/instructions_device_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/select_device_instructions"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp" />
<Button
android:id="#+id/start_service_button"
android:layout_below="#id/instructions_device_select"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="thisDevice"
android:text="#string/this_device"
android:layout_marginTop="10dp"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp" />
<Spinner
android:id="#+id/select_device_spinner"
android:layout_below="#id/start_service_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/select_device"
android:layout_marginTop="20dp"
android:layout_marginLeft="5dp"
android:drawSelectorOnTop = "true" />
</RelativeLayout>
I am waiting to get this working properly, then I am going to customise DeviceAdapter further.
The Activity implements OnItemSelectedListener, hence the override of onItemSelected(...), which isn't being called at all. No errors in LogCat. Spinner is defined in the Activity's layout xml and displays and populates fine. Any advice to fix this would be great.
Thank you.
It might be the spinner layouts, I can see you didn't set a dropdown view for the adapter.
Could you try to initialize your spinner like this:
deviceAdapter = new DeviceAdapter(this, android.R.layout.simple_spinner_item, deviceList);
deviceSpinner.setAdapter(deviceAdapter);
deviceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
deviceSpinner.setOnItemSelectedListener(this);
I was facing the same problem today. Then I realized I am testing on emulator. When I tested the same app it worked. I am posting this if someone is trying to get call back for spinner over emulator it did not work for me. you may also check the same. It works on real device

Java null pointer exception while using google maps in Android

package com.crumbin.tabs;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.http.client.HttpClient;
import android.content.Context;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.webkit.WebView;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class ExploreActivity extends MapActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(com.app.main.R.layout.user_main_tab_explore);
MapView mv = (MapView)findViewById(com.app.main.R.id.myMapView);
mv.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/myMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="Mykey"/>
</LinearLayout>
This code gives me a java null pointer exception. I debugged it and found out that Mapview mv is null.
Shouldn't this code just display the map and no overlay/data on it? Or am I missing something here?
This line
MapView mv = (MapView)findViewById(com.app.main.R.id.myMapView);
needs to be
MapView mv = (MapView)findViewById(R.id.myMapView);
To explain more, you are requesting an ID of a View that is on the R class in the package com.app.main, when you need to request it from the R class in your own package, which can be omitted.

android call log

With the following codes, the call log displayed is empty.Why is that soo??
package fypj.c;
import java.security.Provider;
import java.util.ArrayList;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public class c extends ListActivity {
private SimpleCursorAdapter myAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] column = new String[] {android.provider.CallLog.Calls.CACHED_NAME, android.provider.CallLog.Calls.DURATION, android.provider.CallLog.Calls.TYPE};
int[] names = new int[] {R.id.CLName, R.id.CLDuration, R.id.CLType};
myAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2, cursor, column, names);
setListAdapter(myAdapter);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/list"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CLName"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CLType"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CLDuration"
/>
</LinearLayout>
According to SimpleCursorAdapter,
"This constructor is deprecated.
This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader. "
Try an alternative to rule out any problem with your code.

Categories

Resources