I am working in mobile application (android) and start to learn litho framework, I write a click handler for particular widget inside component. But the error is displayed
"Builder cannot be applied to void" why this issue is came for a reason?
How to resolve that issue. I need another issue. how to retrieve the text input value Thanks for your response
package com.hotfoot.rapid.aubank.sbl.fragment.qde;
import android.graphics.Color;
import android.os.Build;
import android.text.InputType;
import android.text.Layout;
import androidx.annotation.RequiresApi;
import com.facebook.litho.Border;
import com.facebook.litho.ClickEvent;
import com.facebook.litho.Column;
import com.facebook.litho.Component;
import com.facebook.litho.ComponentContext;
import com.facebook.litho.Handle;
import com.facebook.litho.annotations.LayoutSpec;
import com.facebook.litho.annotations.OnCreateLayout;
import com.facebook.litho.annotations.OnEvent;
import com.facebook.litho.annotations.Param;
import com.facebook.litho.annotations.Prop;
import com.facebook.litho.widget.Text;
import com.facebook.litho.widget.TextInput;
import com.facebook.yoga.YogaEdge;
import com.hotfoot.rapid.au.msme.app.pojo.caf.Assessment;
import com.hotfoot.rapid.aubank.sbl.R;
import java.util.ArrayList;
import java.util.List;
#LayoutSpec
public class CAFAssessmentListItem {
#RequiresApi(api = Build.VERSION_CODES.P)
#OnCreateLayout
static Component onCreateLayout(
ComponentContext c,
CAFAssessmentFragment cafFragment,
Assessment assessment,
#Prop String n) {
List<String> districtNames = new ArrayList();
districtNames.add("Chennai");
districtNames.add("Erode");
districtNames.add("Coimbatore");
districtNames.add("Tirunelveli");
final Handle textInputHandle = new Handle();
return Column.create(c)
.child(
Text.create(c)
.text(cafFragment.getActivity().getResources().getString(R.string.ro_assessment))
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_LEFT)
.textSizeSp(18.0f)
.textStyle(1)
.textColor(
cafFragment.getActivity().getResources().getColor(R.color.input_text_color)))
.child(
Text.create(c)
.text("CUSTOMER NAME")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
TextInput.create(c)
.hint("")
.marginDip(YogaEdge.ALL, 10.0f)
.inputType(InputType.TYPE_CLASS_TEXT)
.background(
cafFragment.getActivity().getResources().getDrawable(R.drawable.ic_apply_line))
.multiline(false)
.maxLines(1))
.child(
Text.create(c)
.text("CUSTOMER ADDRESS")
.paddingDip(YogaEdge.ALL, 1.0f)
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
TextInput.create(c)
.hint("")
.marginDip(YogaEdge.ALL, 10.0f)
.inputType(InputType.TYPE_CLASS_TEXT)
.multiline(true)
.maxLines(5)
.background(
cafFragment.getActivity().getResources().getDrawable(R.drawable.bg_edt_popup)))
.child(
Text.create(c)
.text("CUSTOMER CONTACT NO")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
TextInput.create(c)
.hint("")
.marginDip(YogaEdge.ALL, 10.0f)
.inputType(InputType.TYPE_CLASS_PHONE)
.background(
cafFragment.getActivity().getResources().getDrawable(R.drawable.ic_apply_line))
.multiline(false)
.maxLines(1))
.child(
Text.create(c)
.text("CUSTOMER BUSINESS")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
TextInput.create(c)
.hint("")
.marginDip(YogaEdge.ALL, 10.0f)
.inputType(InputType.TYPE_CLASS_TEXT)
.background(
cafFragment.getActivity().getResources().getDrawable(R.drawable.ic_apply_line))
.multiline(false)
.maxLines(1))
.child(
Text.create(c)
.text("LOAN AMOUNT APPLIED")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
TextInput.create(c)
.hint("")
.marginDip(YogaEdge.ALL, 10.0f)
.inputType(InputType.TYPE_CLASS_NUMBER)
.background(
cafFragment.getActivity().getResources().getDrawable(R.drawable.ic_apply_line))
.multiline(false)
.maxLines(1))
.child(
Text.create(c)
.text("TENURE")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
TextInput.create(c)
.hint("")
.marginDip(YogaEdge.ALL, 10.0f)
.inputType(InputType.TYPE_CLASS_NUMBER)
.background(
cafFragment.getActivity().getResources().getDrawable(R.drawable.ic_apply_line))
.multiline(false)
.maxLines(1))
.child(
Text.create(c)
.text("EMi")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
TextInput.create(c)
.hint("")
.marginDip(YogaEdge.ALL, 10.0f)
.inputType(InputType.TYPE_CLASS_NUMBER)
.background(
cafFragment.getActivity().getResources().getDrawable(R.drawable.ic_apply_line))
.multiline(false)
.maxLines(1))
.child(
Text.create(c)
.text("PD WITH")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
com.facebook.litho.widget.Spinner.create(c)
.marginDip(YogaEdge.ALL, 10.0f)
.options(districtNames)
.selectedOption(districtNames.get(1))
.border(
Border.create(c)
.widthDip(YogaEdge.ALL, 1)
.color(YogaEdge.ALL, Color.BLACK)
.build()))
.child(
Text.create(c)
.text("PLACE OF PD-ADDRESS")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
com.facebook.litho.widget.Spinner.create(c)
.marginDip(YogaEdge.ALL, 10.0f)
.options(districtNames)
.selectedOption(districtNames.get(1))
.border(
Border.create(c)
.widthDip(YogaEdge.ALL, 1)
.color(YogaEdge.ALL, Color.BLACK)
.build()))
.child(
Text.create(c)
.text("PURPOSE OF LOAN")
.marginDip(YogaEdge.ALL, 10.0f)
.textAlignment(Layout.Alignment.ALIGN_NORMAL)
.textSizeSp(12.0f)
.textColor(cafFragment.getActivity().getResources().getColor(R.color.text_color)))
.child(
com.facebook.litho.widget.Spinner.create(c)
.marginDip(YogaEdge.ALL, 10.0f)
.options(districtNames)
.selectedOption(districtNames.get(1))
.border(
Border.create(c)
.widthDip(YogaEdge.ALL, 1)
.color(YogaEdge.ALL, Color.BLACK)
.build()))
.child(
Text.create(c)
.text("SAVE")
.textSizeSp(14.0f)
.paddingDip(YogaEdge.ALL, 12.0f)
.textAlignment(Layout.Alignment.ALIGN_CENTER)
.marginDip(YogaEdge.ALL, 10.0f)
.backgroundColor(cafFragment.getActivity().getResources().getColor(R.color.orange))
.textColor(cafFragment.getActivity().getResources().getColor(R.color.white))
.border(
Border.create(c)
.widthDip(YogaEdge.ALL, 1)
.color(YogaEdge.ALL, Color.parseColor("#F36F21"))
.build()))
.child(
Text.create(c)
.text("NEXT")
.textSizeSp(14.0f)
.paddingDip(YogaEdge.ALL, 12.0f)
.textAlignment(Layout.Alignment.ALIGN_CENTER)
.marginDip(YogaEdge.ALL, 10.0f)
.backgroundColor(cafFragment.getActivity().getResources().getColor(R.color.purple))
.textColor(cafFragment.getActivity().getResources().getColor(R.color.white))
.border(
Border.create(c)
.widthDip(YogaEdge.ALL, 1)
.color(YogaEdge.ALL, Color.parseColor("#FFA500"))
.build()))
.clickHandler(CAFAssessmentListItem.onEditTextClick(c, textInputHandle))
.build();
}
#OnEvent(ClickEvent.class)
static void onEditTextClick(ComponentContext c, #Param Handle textInputHandle) {
String customer = TextInput.getText(c, textInputHandle).toString();
}
}
First of all, your LayoutSpec class's name is supposed to end with Spec and you should not ever call its methods directly.
When your Spec class will be named MyComponentSpec the compiler will generate a real Litho Component implementation named MyComponent (notice the absence of the suffix Spec). And methods of this class you are supposed to use. I.e, in your example you reference CAFAssessmentListItem.onEditTextClick(c, textInputHandle) which is Spec's method (which you wrote manually), but you should use Component's method (which will be generated by the compiler).
Second, all inputs to the component should be marked as #Prop, i.e #Prop Assessment assessment. Again, because you should not use onCreateLayout method yourself – you'll use generated ComponentBuilder. Like:
CAFAssessmentListItem.create(c)
.assessment(myAssessment)
.n(myString)
.build()
Third, you don't need your fragment to retrieve resources. There are specific methods for this, i.e
Text.create(c)
.testRes(resId)
.textColorRes(colorResId)
.backgroundColorRes(colorResId2)
Fourth, you've never bound textInputHandle with the TextInput widget to get anything on the onClick. Check out this doc: https://fblitho.com/docs/trigger-events. You need to add .handle(textInputHandle) to the TextInput.
And lastly, you don't need to parse color from string .color(Color.parseColor("#F36F21")) when you already have the value for that color – you can just use hexadecimal int .color(0xFFF36F21).
To sum it up:
Rename your class, add Spec to the end (but don't rename CAFAssessmentListItem.onEditTextClick invocation).
Add #Prop to Assessment param and remove Fragment param from onCreateLayout
Replace cafFragment.getActivity().getResources(). calls to just using resource Ids and respective methods in widgets
Add .handle(textInputHandle) to the TextInput widget
Cleanup setting color values
Related
I am trying to test my service Implementation class, but when I try running the test case, its showing an exception sayinth the repository class is null.
java.lang.NullPointerException: Cannot invoke
"com.example.training.repository.HotelRepository.findAll()" because "this.hotelRepository" is null
at com.example.training.services.TravelServiceImpl.getHotels(TravelServiceImpl.java:80)
at com.example.training.services.TravelServiceImplTest.canGetHotels(TravelServiceImplTest.java:74)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
This is my serviceTest class
package com.example.training.services;
import com.example.training.models.Contract;
import com.example.training.models.Hotel;
import com.example.training.models.Rooms;
import com.example.training.repository.HotelRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
#ExtendWith(MockitoExtension.class)
class TravelServiceImplTest {
#Mock
private HotelRepository hotelRepository;
#Autowired
#InjectMocks
private TravelServiceImpl underTest;
private Hotel hotel1;
private Hotel hotel2;
List<Hotel> hotelList;
List<Contract> contracts = new ArrayList<Contract>();
List<Rooms> rooms = new ArrayList<Rooms>();
String start="2015-03-31";
String end="2015-05-31";
#BeforeEach
void setUp() {
hotelList = new ArrayList<>();
contracts.add(new Contract(1, Date.valueOf(start), Date.valueOf(end), 20));
contracts.add(new Contract(2, Date.valueOf(start), Date.valueOf(end), 30));
rooms.add(new Rooms(1,10, "standard", 10, 20, 2000));
hotel1 = new Hotel(1,"cinna","gmail","add1", "add2", contracts,rooms);
hotel2 = new Hotel(2,"cinna","gmail","add1", "add2", contracts,rooms);
hotelList.add(hotel1);
hotelList.add(hotel2);
}
#AfterEach
void tearDown() throws Exception {
hotelList = null;
hotel1= hotel2=null;
}
#Test
void canGetHotels() {
// TravelServiceImpl underTest1 = new TravelServiceImpl(hotelRepository);
hotelRepository.save(hotel1);
when(hotelRepository.findAll()).thenReturn(hotelList);
List<Hotel> hotelList1 = underTest.getHotels();
assertEquals (hotelList1,hotelList);
verify(hotelRepository, times(1)).save(hotel1);
verify(hotelRepository,times(1)).findAll();
underTest.findAllHotels();
//verify(hotelRepository).findAll();
}
}
And this is the function that I am trying to test
#Override
public List<Hotel> getHotels() {
return (List<Hotel>) hotelRepository.findAll();
}
I haven't written any test cases for the repository class. But my repository class does have additional methods with #Query annotations
What am I doing wrong
You need to use #SpringBootTest annotation on top of your class name. And also add
#BeforeEach
void init() {
MockitoAnnotations.initMocks(this);
}
It looks like the issue is with the TravelServiceImpl implementation in the part that initializes the repository, for some reason its null.
Place a breakpoint at the first line of canGetHotels method and inspect the underTest object - I believe you'll see the non-initialized field of the repository.
Why is it so? Hard to tell - you don't show the code. As a guess, you have an initialization logic that complies with the ways #InjectMocks work. For mode details see this SO thread for example.
I am trying to make my program able to get the user's current longitude and latitude and then place a marker to it. I have used various method in the Internet but none of them seemed to work. From what I have observed I suspect the reason the trouble is that the program fails to get the permission, despite I have already set it in the manifest
Here is the code, I currently only use setMyLocationEnabled to demonstrate the problem
package com.example.user.googlemaptest2;
import android.*;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.io.IOException;
import java.util.List;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private double longitudeDefaultLocation;
private double latitudeDefaultLocation;
private static final int MY_PERMISSION_ACCESS_COARSE_LOCATION = 11;
private static final int MY_PERMISSION_ACCESS_FINE_LOCATION = 12;
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
longitudeDefaultLocation = location.getLongitude();
latitudeDefaultLocation = location.getLatitude();
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions( this, new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION },
MapsActivity.MY_PERMISSION_ACCESS_COARSE_LOCATION );
ActivityCompat.requestPermissions( this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
MapsActivity.MY_PERMISSION_ACCESS_FINE_LOCATION );
}
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
mMap.animateCamera(CameraUpdateFactory.zoomTo(14));
}
else
{
Toast.makeText(MapsActivity.this,"FAIL", Toast.LENGTH_LONG).show();
}
}
public void onSearch(View view)
{
EditText location_tf = (EditText)findViewById(R.id.TFaddress);
String location = location_tf.getText().toString();
List<Address> addressList = null;
if (location !=null || location.equals("")) {
Geocoder geocoder = new Geocoder(this);
try {
addressList = geocoder.getFromLocationName(location,1);
} catch (IOException e) {
e.printStackTrace();
}
Address address = addressList.get(0);
LatLng latLng = new LatLng( address.getLatitude(), address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
public void changeType (View view)
{
if (mMap.getMapType() == GoogleMap.MAP_TYPE_NORMAL)
{
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
else
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
public void onZoom(View view)
{
if (view.getId() == R.id.zoomInButton);
{
mMap.animateCamera(CameraUpdateFactory.zoomIn());
}
if (view.getId() == R.id.zoomOutButton)
{
mMap.animateCamera(CameraUpdateFactory.zoomOut());
}
}
This is the content of my Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.googlemaptest2">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="My Key is Here" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I am using google map V2 in android app by tab(viewPager) and I want to show current location in map but I couldn't find this button.
AddMasjid.java
package com.example.saroosh.masjidnow.Tabs;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.saroosh.masjidnow.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class AddMasjid extends Fragment implements OnMapReadyCallback{
MapView gMapView;
GoogleMap gMap = null;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.add_masjid,container,false);
gMapView = (MapView) v.findViewById(R.id.map);
gMapView.getMapAsync(this);
gMapView.onCreate(savedInstanceState);
gMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
return v;
}
#Override
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(0, 0), 0));
if (gMap != null) {
gMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
gMap.getUiSettings().setMyLocationButtonEnabled(true); }
}
#Override
public void onResume() {
super.onResume();
gMapView.onResume();
}
#Override
public void onPause() {
super.onPause();
gMapView.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
gMapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
gMapView.onLowMemory();
}
}
add_masjid.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentStart="true"
android:text="#string/xyz"
android:textColor="#FFFFFF"
android:textSize="20sp"
/>
<Button
android:id="#+id/generalId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:background="#drawable/rect1"
android:onClick="geoLocate"
android:text="#string/abc"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/textView1"
android:layout_toStartOf="#+id/generalId"
android:ems="10"
android:inputType="text"
android:background="#FFFFFF"
android:labelFor="#+id/editText1"
android:layout_above="#+id/map"
android:layout_alignParentTop="true" />
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/generalId">
</com.google.android.gms.maps.MapView>
<!--<fragment-->
<!--android:id="#+id/map"-->
<!--android:name="com.google.android.gms.maps.SupportMapFragment"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:layout_below="#+id/generalId" />-->
</RelativeLayout>
Please anybody guide me how can I get this button in my app.
I have solved my problem by adding some code in it, like this.
#Override
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(0, 0), 0));
if (gMap != null) {
gMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext()
, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity().getApplicationContext()
, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
gMap.setMyLocationEnabled(true);
gMap.getUiSettings().setMyLocationButtonEnabled(true);
}
}
Here are some nice tutorials to get current location
Link
Link
Learn to get current location from here than update the location parameters lat n lng in this code like this.
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(lat, lng), 0));
if (gMap != null) {
gMap.addMarker(new MarkerOptions().position(new LatLng(lat, lng)).title("Marker"));
gMap.getUiSettings().setMyLocationButtonEnabled(true); }
}
Alas! after a lots of efforts and search I couldn't find my problem. I want to find current location in google map but I am still getting an error(required permissions).
call requires permission which may be rejected by user: code should
explicitly check to see if permission is available (with check
permission) or explicitly handle a potential 'security Exception'
at gMap.setMyLocationEnable(true); Please anybody guide me how can I fix it? My code is given below.
AddMasjid.java
package com.example.saroosh.masjidnow.Tabs;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.saroosh.masjidnow.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class AddMasjid extends Fragment implements OnMapReadyCallback{
MapView gMapView;
GoogleMap gMap = null;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.add_masjid,container,false);
gMapView = (MapView) v.findViewById(R.id.map);
gMapView.getMapAsync(this);
gMapView.onCreate(savedInstanceState);
gMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
return v;
}
#Override
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(0, 0), 0));
if (gMap != null) {
gMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
gMap.setMyLocationEnabled();
}
}
#Override
public void onResume() {
super.onResume();
gMapView.onResume();
}
#Override
public void onPause() {
super.onPause();
gMapView.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
gMapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
gMapView.onLowMemory();
}
}
add_masjid.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentStart="true"
android:text="#string/xyz"
android:textColor="#FFFFFF"
android:textSize="20sp"
/>
<Button
android:id="#+id/generalId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:background="#drawable/rect1"
android:onClick="geoLocate"
android:text="#string/abc"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/textView1"
android:layout_toStartOf="#+id/generalId"
android:ems="10"
android:inputType="text"
android:background="#FFFFFF"
android:labelFor="#+id/editText1"
android:layout_above="#+id/map"
android:layout_alignParentTop="true" />
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/generalId">
</com.google.android.gms.maps.MapView>
</RelativeLayout>
I have just solved my problem by adding some permissions in it.
#Override
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(0, 0), 0));
//add this code...
if (gMap != null) {
gMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext()
, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity().getApplicationContext()
, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
gMap.setMyLocationEnabled(true);
gMap.getUiSettings().setMyLocationButtonEnabled(true);
}
}
I am using Volley library for fetching the json data. I have also modified the Manifest adding the necessary Internet permission . But when I run the app it crashes.
Main activity.java
package com.example.sans.myapplication1;
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.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
ListView listView;
RequestQueue requestQueue;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
listView=(ListView)findViewById(R.id.list);
RequestQueue requestQueue= Volley.newRequestQueue(this);
JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.GET, "http://api.themoviedb.org/3/movie/popular?api_key=fa468af9e769ba5fbc027e9e933130ed",
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
ArrayList<Movie> movieList= new ArrayList<Movie>();
try{
JSONArray jsonArray=response.getJSONArray("results");
for (int i=0;i< jsonArray.length();i++){
JSONObject jsonObject= jsonArray.getJSONObject(i);
String title= jsonObject.getString("title");
movieList.add(new Movie(title));
MovieAdapter adapter= new MovieAdapter(getApplicationContext(),movieList);
listView.setAdapter(adapter);
}
}catch(Exception e){
Toast.makeText(getApplicationContext(), "Error getting data", Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
}
});
requestQueue.add(jsonObjectRequest);
}
}
$ MovieAdapter.java
package com.example.sans.myapplication1;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
/**
* Created by sans on 13/7/16.
*/
public class MovieAdapter extends ArrayAdapter<Movie> {
public MovieAdapter(Context context, List<Movie> objects) {
super(context,0, objects);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Movie movie=getItem(position);
if(convertView==null){
convertView= LayoutInflater.from(getContext()).inflate(R.layout.list_row, parent);
}
TextView title=(TextView)convertView.findViewById(R.id.title);
title.setText(movie.getTitle());
return convertView;
}
}
$ Movie.java
package com.example.sans.myapplication1;
import android.app.Activity;
import android.content.Context;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
/**
* Created by sans on 13/7/16.
*/
public class Movie {
private String title;
public Movie(String title){
this.title=title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
}
$ list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:id="#+id/title"/>
</LinearLayout>
$ content_main.xml
<?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: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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.sans.myapplication1.MainActivity"
tools:showIn="#layout/activity_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/list" />
</RelativeLayout>
Log error
FATAL EXCEPTION: main
Process: com.example.sans.myapplication1, PID: 4252
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at com.example.sans.myapplication1.MovieAdapter.getView(MovieAdapter.java:29)
at android.widget.AbsListView.obtainView(AbsListView.java:2346)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1280)
at android.widget.ListView.onMeasure(ListView.java:1188)
at android.view.View.measure(View.java:18788)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:668)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:735)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18788)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-13 17:37:39.746 1532-1903/? W/ActivityManager: Force finishing activity com.example.sans.myapplication1/.MainActivity
In MovieAdapter.java class change convertView!=null to convertView==null
& in list_row.xml file
instead of android:minHeight="?attr/listPreferredItemHeight"
change it to android:minHeight="?android:attr/listPreferredItemHeight"