Sry I am newbie to this Topic, but I always get this Exception when I want to make a rpc call:
Caused by: com.google.gwt.user.client.rpc.ServiceDefTarget$NoServiceEntryPointSpecifiedException: Service implementation URL not specified
I don't know why, because I have make it like the gwt Tutorial.
Thats my source code:
web.xml:
<web-app>
<servlet>
<servlet-name>SpeicherService</servlet-name>
<servlet-class>de.fhdo.kuss.server.SpeicherServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SpeicherService</servlet-name>
<url-pattern>/SpeicherService</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Kuss_Projekt.html</welcome-file>
</welcome-file-list>
</web-app>
-
Kuss_Projekt.gwt.xml:
<module rename-to='kuss_projekt'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean' />
<!--<inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!--<inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='de.fhdo.kuss.client.Kuss_Projekt' />
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
</module>
-
Speicherservice:
#RemoteServiceRelativePath("SpeicherService")
public interface SpeicherService extends RemoteService {
String getName(String name);
public static class Util {
private static SpeicherServiceAsync instance;
public static SpeicherServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(SpeicherService.class);
}
return instance;
}
}
}
-
SpeicherServiceAsync:
public interface SpeicherServiceAsync {
void getName(String name, AsyncCallback<String> callback);
}
-
SpeicherServiceImpl:
public class SpeicherServiceImpl extends RemoteServiceServlet implements SpeicherService {
#Override
public String getName(String name) {
return("Server meldet sich " + name);
}
}
-
Test():
public void test() {
AsyncCallback<String> callback = new AsyncCallback<String>() {
#Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
#Override
public void onSuccess(String result) {
Window.alert(result);
}
};
SpeicherService.Util.getInstance().getName("test",callback);
}
Add back in:
#RemoteServiceRelativePath("SpeicherService")
Then in your web.xml replace
<url-pattern>/SpeicherService</url-pattern>
with
<url-pattern>/kuss_projekt/SpeicherService</url-pattern>
The reason you need to do that is because you are using: <module rename-to='kuss_projekt'> in your gwt.xml.
Related
I am trying to create a RESTful web-service and I created one but I am getting a
MessageBodyWriter not found for media type=application/json error
My Todo class:
package com.jersey.jaxb;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.pojomatic.Pojomatic;
import org.pojomatic.annotations.AutoProperty;
#XmlRootElement
#XmlType(name = "todo")
#XmlAccessorType(XmlAccessType.FIELD)
#AutoProperty
public class Todo {
#XmlElement(name = "summary")
private final String summary;
#XmlElement(name = "description")
private final String description;
public String getSummary() {
return summary;
}
public String getDescription() {
return description;
}
public Todo() {
this(new Builder());
}
public Todo(Builder builder) {
this.summary = builder.summary;
this.description = builder.description;
}
#Override
public boolean equals(Object o) {
return Pojomatic.equals(this, o);
}
#Override
public int hashCode() {
return Pojomatic.hashCode(this);
}
#Override
public String toString() {
return Pojomatic.toString(this);
}
public static class Builder {
private String description;
private String summary;
public Builder summary(String summary) {
this.summary = summary;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Todo build() {
return new Todo(this);
}
}
}
And my Resource:-
package com.jersey.jaxb;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
#Path("/todo")
public class TodoResource {
#GET
#Produces(MediaType.APPLICATION_JSON)
public Response getTodo(){
Todo todo = new Todo.Builder().description("My Todo Object").summary("Created").build();
return Response.status(Status.OK).entity(todo).build();
}
}
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<display-name>MyFirstWebService</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.jersey.jaxb</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
My Libraries:
aopalliance-repackaged-2.4.0-b10.jar
asm-debug-all-5.0.2.jar
hk2-api-2.4.0-b10.jar
hk2-locator-2.4.0-b10.jar
hk2-utils-2.4.0-b10.jar
jackson-jaxrs-json-provider-2.2.3.jar
javassist-3.18.1-GA.jar
javax.annotation-api-1.2.jar
javax.inject-2.4.0-b10.jar
javax.servlet-api-3.0.1.jar
javax.ws.rs-api-2.0.1.jar
jaxb-api-2.2.7.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet.jar
jersey-container-servlet-core.jar
jersey-guava-2.17.jar
jersey-media-jaxb.jar
jersey-server.jar
org.osgi.core-4.2.0.jar
osgi-resource-locator-1.0.1.jar
persistence-api-1.0.jar
validation-api-1.1.0.Final.jar
When I run this application on Tomcat server and run this :
http://localhost:8080/MyFirstWebService/rest/todo
I get the error:
SEVERE: MessageBodyWriter not found for media type=application/json,
type=class com.jersey.jaxb.Todo, genericType=class
com.jersey.jaxb.Todo.
You have jackson-jaxrs-json-provider which is a start..
But...
that artifact is still dependent on Jacskon itself, which includes all these artifacts
That's why we use Maven[1] (so we don't have to worry about this kind of thing :-). So go find these.
Then just add the package to the web.xml, and it should work
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.jersey.jaxb,
com.fasterxml.jackson.jaxrs.json
</param-value>
1. Maven dependency
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.2.3</version>
</dependency>
Or use the below Jersey "wrapper" for the above dependency. It will register the Jackson providers (so we don't need to explicitly register like above), and the Jackson exception mappers, and start from version 2.17, provides support for Entity Data Filtering.
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey2.version}</version>
</dependency>
Note: The fact that we don't have to register anything with the above dependency, is made possible through the Auto-discovery feature of Jersey. If we for some reason disable the auto-discovery, you will want to explicitly register the JacksonFeature.
The solution may be to make ensure that the model classes have a no-argument constructor.
And add this dependency on your pom.XML:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
I had the same issue, i solved it by addind a empty constructor to the class
public SandBoxClass(){} //-> solved the issue**
public SandBoxClass(Integer arg1, Integer arg2) {
this.arg1=arg1;
this.arg2=arg2;
}
If you already have the jersey-media-moxy dependency added into your pom.xml. Make sure your entity class has the default constructor.
I got this issue when I introduced a paramatrized constructor in the model class. Adding the default constructor again worked for me.
As for me, it helped to register JacksonFeature:
public class App extends ResourceConfig {
public App() {
packages("info.ernestas.simplerest");
register(new JacksonFeature()); // This magical line helped
}
}
Update Library Jax-RS 2.0 and Jersey 2.5.1(JAX-RS-RI) only
Return Bean object(todo) not response because while auto generating json or xml it response create issue.
Answered here: Obtaining "MessageBodyWriter not found for media type=application/json" trying to send JSON object through JAX-RS web service
As stated above:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
For me I also had to add:
ClientConfig config = new ClientConfig();
config.register(JacksonJsonProvider.class);
return ClientBuilder.newClient(config)
I am currently building a sample application using Castle Windsor. The motto is to use xml/app.config to switch method interception on/off. I had used the Fluent API earlier and it worked as a charm. As the next step, I am trying to replace the fluent API with my xml.
The gist of the code is as follows:
A class called RandomOperations with two virtual methods.
A LoggingAspect class which implements IInterceptor.
A MyInterceptorsSelector class which implements IModelInterceptorsSelector
A Program.cs which had the fluent api syntax earlier and is now uses to only make calls to methods of RandomOperations class.
An app.config with a section called which has the xml syntax of registering components.
When I use the fluent api, I am able to intercept the method calls but I am unable to do it using the xml/app.config registration. Could someone please throw some light on what is being missed?
The classes are as follows:
RandomOperations.cs
public class RandomOperations
{
public virtual int MyRandomMethod(int x)
{
return x * x;
}
public virtual void Writer(string x)
{
Console.WriteLine(x);
}
}
LoggingAspect.cs
public class LoggingAspect : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Console.WriteLine("Intercepted the call to " + invocation.Method.Name);
invocation.Proceed();
Console.WriteLine("After the method call, the return value is " + invocation.ReturnValue);
}
}
MyInterceptorsSelector.cs
public class MyInterceptorsSelector : IModelInterceptorsSelector
{
public bool HasInterceptors(ComponentModel model)
{
return typeof(LoggingAspect) != model.Implementation &&
model.Implementation.Namespace.StartsWith("ConsoleApplication1") ;
}
public InterceptorReference[] SelectInterceptors(ComponentModel model, Castle.Core.InterceptorReference[] obj)
{
var interceptors = new List<InterceptorReference>(model.Interceptors.Count + 1);
foreach (InterceptorReference inter in model.Interceptors)
{
interceptors.Add(inter);
}
return interceptors.ToArray();
}
}
Main in Program.cs
static void Main(string[] args)
{
var container = new WindsorContainer();
//container.Register(Component.For<RandomOperations>().Interceptors(typeof(LoggingAspect)));
//container.Register(Component.For<LoggingAspect>());
//container.Kernel.ProxyFactory.AddInterceptorSelector(new MyInterceptorsSelector());
var service = container.Resolve<RandomOperations>();
service.MyRandomMethod(4);
service.Writer("Hello, World");
}
Removing the commented out fluent api syntax makes the application work correctly.
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
</configSections>
<castle>
<components>
<component id="MyInterceptorsSelector" type="MyInterceptorsSelector"/>
<component
id="LoggingAspect"
type="ConsoleApplication1.LoggingAspect, ConsoleApplication1">
</component>
<component
type="ConsoleApplication1.RandomOperations, ConsoleApplication1">
<interceptors selector="${MyInterceptorsSelector}">
<interceptor>${LoggingAspect}</interceptor>
</interceptors>
</component>
</components>
</castle>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Thanks in advance.
You need to pass an IConfigurationInterpreter to your Windsor constructor. Change:
var container = new WindsorContainer();
To:
var container = new WindsorContainer(new XmlInterpreter());
The XmlInterpreter (with no parameters) will pull configuration from your app.config/web.config.
For more options on using IConfigurationInterpreter, see the docs.
I have a slight problem figuring out a "bug" in my code. Im not sure if its a bug or not. However, as you can see in the picture 1, the fixed tabs' position is behind the curtain drawer. I cant find/understand why this is. Ive followed several tutorials and they dont seem to have the same problem.
Ive tried to google it up, but i cant find a similar problem. Anyone experienced something similar before?
In the android studio, the design layout seems to be on point, however, not when compiled.
Im using the neokree lib so i can use the icons and ripple effect when selecting tabs. I've tried to use the google's tab layout link here, but as soon as i tried to remove the actionbar and apply the icons, the same problem occurred.
Thanks!
activity_main
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<it.neokree.materialtabs.MaterialTabHost
android:id="#+id/materialTabHost"
android:layout_width="match_parent"
android:layout_height="48dp"
app:iconColor="#color/iconColor"
app:primaryColor="#color/primaryColor"
app:accentColor="#color/accentColor"
app:hasIcons="true"/>
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"/>
</LinearLayout>
styles.xml
<resources>
<style name="AppTheme" parent="AppTheme.Base"></style>
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
<item name="colorControlHighlight">#color/colorHighlight</item>
</style>
</resources>
styles.xml v21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<!--Using same style as in default style.xml file-->
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">#color/primaryColor</item>
<item name="android:colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:colorAccent">#color/accentColor</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:colorControlHighlight">#color/colorHighlight</item>
</style>
</resources>
MainActivity
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ImageSpan;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import it.neokree.materialtabs.MaterialTab;
import it.neokree.materialtabs.MaterialTabHost;
import it.neokree.materialtabs.MaterialTabListener;
public class MainActivity extends ActionBarActivity implements MaterialTabListener
{
private Toolbar toolbar;
private ViewPager mPager;
private SlidingTabLayout mTabs;
private MaterialTabHost tabHost;
private ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (MaterialTabHost) findViewById(R.id.materialTabHost);
viewPager = (ViewPager) findViewById(R.id.viewPager);
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
tabHost.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < adapter.getCount(); i++) {
tabHost.addTab(
tabHost.newTab()
.setIcon(adapter.getIcon(i))
.setTabListener(this));
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onTabSelected(MaterialTab materialTab) {
viewPager.setCurrentItem(materialTab.getPosition());
}
#Override
public void onTabReselected(MaterialTab materialTab) {
}
#Override
public void onTabUnselected(MaterialTab materialTab) {
}
class ViewPagerAdapter extends FragmentStatePagerAdapter
{
int icons[] = {R.drawable.ic_home,
R.drawable.ic_graph,
R.drawable.ic_bell_mid,
R.drawable.ic_settings};
//String[] tabText = getResources().getStringArray(R.array.tabs);
public ViewPagerAdapter(FragmentManager fm)
{
super(fm);
//tabText = getResources().getStringArray(R.array.tabs);
}
#Override
public Fragment getItem(int position)
{
MyFragment myFragment = MyFragment.getInstance(position);
return myFragment;
}
//Attaching an image to a (spannable) string so we can show the image instead of text.
#Override
public CharSequence getPageTitle(int position){
/*Drawable drawable = getResources().getDrawable(icons[position]);
//icon bounds/size
drawable.setBounds(0,0,96,96);
ImageSpan imageSpan = new ImageSpan(drawable);
SpannableString spannableString = new SpannableString(" ");
spannableString.setSpan(imageSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannableString;*/
return getResources().getStringArray(R.array.tabs)[position];
}
#Override
public int getCount()
{
return 4;
}
private Drawable getIcon(int position)
{
return getResources().getDrawable(icons[position]);
}
}
}
After accidentally getting over a youtube tutorial about making simple material design tabs, I made a new project and started to combine the one I found in youtube with my old one. Eventually, I found out that the following code line in the styles file was the cause of the problem.
<item name="android:windowTranslucentStatus">true</item>
It seems like it was something I added for testing and forgot to remove later on.
Try adding a Toolbar with a no actionbar theme..
In order to do this you have to make a new xml file called tool_bar.xml and paste the following code into it:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/ColorPrimary"
android:elevation="2dp"
android:theme="#style/Theme.AppCompat.NoActionBar"
xmlns:android="http://schemas.android.com/apk/res/android" />
You have then add this to your activity_main.xml file:
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
I think I have done all using the Google Maps API v2 but the position is not shown and the camera doesn't changes its position.
The map loads normally but stays only in 0,0 location and it never moves.
In the device, I see the GPS signal only looking for position and I have already tested outside.
Here is my code:
MainActivity.java:
public class MainActivity extends FragmentActivity implements LocationSource,LocationListener, OnMapClickListener, OnMyLocationChangeListener
{
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
private LocationManager lm;
public Location myLocation;
public TipoBusca busca;
private enum TipoBusca {BUSCA_PARADA, BUSCA_LOCALIZACAO_INICIAL, BUSCA_LOCALIZACAO, BUSCA_ENDERECO, BUSCA_DRAG};
public String tipoRequest;
private Criteria myCriteria;
public TextView textView;
public OnMyLocationChangeListener locationListener;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Define textView wich will receive test messages
textView = (TextView) findViewById(R.id.textView1);
// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status!=ConnectionResult.SUCCESS)
{ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
else
{
//Defining fragment for map
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
myMap.setMyLocationEnabled(true);
myMap.setIndoorEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
myMap.setLocationSource(this);
//myMap.setOnMyLocationChangeListener(this);
myMap.setOnMyLocationChangeListener((OnMyLocationChangeListener) locationListener);
myCriteria = new Criteria();
myCriteria.setAccuracy(Criteria.ACCURACY_FINE);
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//lm.requestLocationUpdates(0, 50.0f, myCriteria, this, null);
lm.requestLocationUpdates(250, 1, myCriteria, this, null);
textView.setText("Localizando usuário...");
myLocation = myMap.getMyLocation();
}
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
#Override
public void activate(OnLocationChangedListener listener) {
// TODO Auto-generated method stub
}
#Override
public void deactivate() {
// TODO Auto-generated method stub
}
#Override
public void onMapClick(LatLng point) {
// TODO Auto-generated method stub
myMap.animateCamera(CameraUpdateFactory.newLatLng(point));
}
#Override
public void onMyLocationChange(Location location) {
// TODO Auto-generated method stub
Log.i("onMyLocationChanged", "my location changed");
LatLng latlng= new LatLng(location.getLatitude(), location.getLongitude());
myMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
myMap.animateCamera(CameraUpdateFactory.zoomTo(15));
textView.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude() );
}
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Log.i("onLocationChanged", "location changed");
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myPackage"
android:versionCode="1"
android:versionName="1.0" >
<!-- Setting Permissions -->
<permission
android:name="myPackage.permission.MAPS_RECEIVE" android:protectionLevel="signature"></permission>
<uses-permission android:name="myPackage.permission.MAPS_RECEIVE"/>
<!-- Setting versions requirements -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- setting icon for application -->
<application android:allowBackup="true" android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" >
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="myApiKey_Code_Inserted_here"/>
<activity android:name="myPackage.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
If what you're trying to accomplish is to have the camera automatically update when the user (My Location dot) changes location, then you only need the following:
implement OnMyLocationChangeListener
myMap.setMyLocationEnabled(true) (enable the my-location layer, which has a built-in location provider)
myMap.setOnMyLocationChangeListener(this) (register to receive updates when My Location dot changes location)
in your callback method onMyLocationChange(Location location) update the camera accordingly.
You already have the code for all of this, but I see you have commented the line in step 3, and this is probably the reason why you don't see the camera updating.
You don't need to implement LocationSource and LocationListener (because the my-location layer has its own location provider), and you need OnMapClickListener only if you want to respond to a user tapping on a point on the map.
When MainClass is created public MyWindsorClass(IMyInterface obj) {} is called and when MainClass2 is created public MyWindsorClass(IMyInterface obj) {} is also called when I'm expecting public MyWindsorClass() {} to be called. What exactly am I doing wrong?I'm having an issue with constructor injection. Here is an example:
class Program
{
static void Main(string[] args)
{
var container = new WindsorContainer(new XmlInterpreter());
var objs = container.ResolveAll<IMyWindsorInterface>();
}
}
public interface IMyWindsorInterface { }
public class MyWindsorClass : IMyWindsorInterface
{
public MyWindsorClass() {}
public MyWindsorClass(IMyInterface obj) {}
}
public interface IMyInterface { }
public class MyInjectedClass : IMyInterface{ }
<castle>
<components>
<component id="MainClass"
service="CastleTest.IMyWindsorInterface, CastleTest"
type="CastleTest.MyWindsorClass, CastleTest"
inspectionBehavior="None"
lifestyle="Transient">
<parameters>
<obj>${blah}</obj>
</parameters>
</component>
<component id="MainClass2"
service="CastleTest.IMyWindsorInterface, CastleTest"
type="CastleTest.MyWindsorClass, CastleTest"
inspectionBehavior="None"
lifestyle="Transient" />
<component id="blah"
service="CastleTest.IMyInterface, CastleTest"
type="CastleTest.MyInjectedClass, CastleTest"
inspectionBehavior="None"/>
</components>
</castle>
When MainClass is created public MyWindsorClass(IMyInterface obj) {} is called and when MainClass2 is created public MyWindsorClass(IMyInterface obj) {} is also called when I'm expecting public MyWindsorClass() {} to be called. What exactly am I doing wrong? Thanks to anyone that can help!
Windsor will by default autowire all available dependencies. In your case, IMyInterface is available as a component so Windsor will choose the constructor that can satisfy the most dependencies.
You may change this behavior ad-hoc by removing the constructor from the component model so Windsor doesn't 'see' it any more:
var container = new WindsorContainer();
container.Kernel.ComponentModelCreated += model => {
if (model.Name == "MainClass2")
model.Constructors.Remove(model.Constructors.First(c => c.Dependencies.Any(m => m.TargetType == typeof(IMyInterface))));
};
container.Install(Configuration.FromAppConfig());