I have a problem where files that should be showing up in my android project are not appearing. For example, in the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
>
<ImageButton
android:id="#+id/pencil"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="left"
android:src="#drawable-mdpi/pencil"
/>
<ImageButton
android:id="#+id/eraser"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="#drawable-mdpi/eraser"
/>
</LinearLayout>
I get errors for the pencil and eraser src lines, despite having the two bitmap images in that exact folder (and being able to see it in my directory). Similar problems exist for this code:
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class DrawingActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawing);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(res.menu.drawing, 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();
if (id == res.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Where it cannot find drawing.xml (at line with res.menu.drawing), even though again it is visible in the directory.
Is there something else I'm supposed to do first? Maybe some kind of import beyond putting the items in the folder and rebuilding? I've read in some other cases that these kinds of problems were resolved by exiting and re-opening Android Studio, but I've now done that twice with no effect (as well as multiple cleans and rebuilds of the project). As such, I can only assume that I'm missing something more essential.
Any help would be greatly appreciated.
Related
I am doing Android programming for the first time, I want to display a GeoServer layer using the ArcGis SDK map layer. I have done the code but it is not working, please tell me what i am doing wrong.
activity_main.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: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="com.example.subrata.mymap.MainActivity">
<com.esri.android.map.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapoptions.MapType="Aerial"
mapoptions.center="28, 77"
mapoptions.ZoomLevel="10">
</com.esri.android.map.MapView>
</RelativeLayout>
mainactivity.java
package com.example.subrata.mymap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.esri.android.map.MapView;
import com.esri.android.map.ogc.WMSLayer;
public class MainActivity extends AppCompatActivity {
MapView mMapView;
WMSLayer wmsLayer;
String wmsURL;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMapView = (MapView)findViewById(R.id.map);
wmsURL = "http://localhost:8081/geoserver/NFR-SR/wms";
wmsLayer = new WMSLayer(wmsURL);
wmsLayer.setImageFormat("application/openlayers");
// available layers
String[] visibleLayers = {"NFR-SR:Ridgeline_SR"};
wmsLayer.setVisibleLayer(visibleLayers);
wmsLayer.setOpacity(0.5f);
mMapView.addLayer(wmsLayer);
mMapView.setEsriLogoVisible(false);
mMapView.enableWrapAround(true);
}
#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);
}
}
Can't really tell what you mean by not working without any log or explanation.
Here are some possible reason:
cannot reach server at url http://localhost:8081/geoserver/NFR-SR/wms
layer name NFR-SR:Ridgeline_SR not found
map service doesn't support application/openlayers
It could even be it is working but you are viewing the map extent which does not contain any data.
I am new to Android and building a small test program and the program is not running and giving me Could not create the view: org.eclipse.pde.runtime.LogView error
here is the code from my android_main.xml file
<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"
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="com.example.myapplication.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
Here is the java code from MainActivity.Java
package com.example.myapplication;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I apologize that I am posting this as an answer instead of a comment, but commenting requires 50 reputation and I don't have that yet. Can you post your java code too? The problem is likely in there, it may be the method by which you are loading the view.
I'm new to programming. I've only learned the basics. Right now, I'm trying Android development out with Android Studio. My program simply has a title, and 2 buttons that are supposed to open a URL. There doesn't seem to be anything wrong with my code since nothing is underlined in red, so I don't understand why the layout model isn't showing up in the emulator.
What are some things that affects the emulator from running properly? I tried it on a windows computer and the emulator came after a minute or so. But nothing for the Mac. Anyway to speed up the process?
My code has no errors. Only problem I'm facing is the emulator not running in a timely manner. The app is supposed to open a URL for each of the 2 buttons in the browser.
Running on a Macbook Pro Mid 2010 13" with 8 GB RAM
**************************************Activity Code**********************************************
package com.first.bharg.firstapp;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonOnClick();
}
public void buttonOnClick(){
Button b = (Button) findViewById(R.id.button);
Button b1 = (Button) findViewById(R.id.button2);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i1 =
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yahoo.com"));
startActivity(i1);
}
});
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i2 =
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(i2);
}
});
}
#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);
}
}
************************************************Layout******************************************
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="#+id/activity_main"
android:clickable="true"
android:background="#ffffa157"
android:focusable="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yahoo"
android:id="#+id/button"
android:layout_marginTop="107dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="51dp"
android:layout_marginStart="51dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Google"
android:id="#+id/button2"
android:layout_alignBottom="#+id/button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="42dp"
android:layout_marginEnd="42dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="First App"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
As far as windows concerns, I am afraid there's nothing you can do but wait for the emulator to load everything up. It always takes a lot of time, unless you use your own device (i.e connect your mobile phone to your laptop via USB).
For Mac it's a bit tricky. It's obviously not the only way, but I do suggest you to try another emulator if the one you actually have it's not working properly on it. It's gonna be faster than trying to solve whatever that's going on.
Apparently your code is ok. However if you are new to android I suggest you first get familiar with android activities life cycle before using intents. Here you may find some information related.
I've personally used eclipse's android SDK and it works fine on both OS.
Im creating a new project from 0 but when i see the preview doesnt show any actionBar , im just creating it from 0 i dont have any code,
a Picture: http://i.stack.imgur.com/CaeE1.png
here is my style.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
And my activity_main.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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
And my MainActivity.java:
package com.example.jorwys.myapplication;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#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);
}
}
But when i open a older project the preview does show me the actionbar so i think the problem is the new android studio; Thank you for the help. im sorry about my bad english.
This Preview is only for your Layout Components. So if you wanna see there something you have to add it in your Layout Code. You could For Example add a sort of View you and take Acces of it in your Activity and change it as you like.
I noticed that was compiling with API 21 (Lollipop) so i change it to API 19 ( Kitkat) and also the appcompat library from: compile 'com.android.support:appcompat-v7:21.0.+' to compile 'com.android.support:appcompat-v7:20+'
I am writing my first android app after reading a tutorial. I am excited and thought its easy. However, after adding a simple edit text and a hello world message, i run and was expecting to see something yet nothing showed up. Neither the textbox nor the default hello world. Pls where do go wrong ? Below is my layout (i.e activity_main.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"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textColor="#FF00FF00"/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#FF0000FF"
android:id="#+id/et_Text" />
</RelativeLayout>
My java code is the default/code generated one. I was expecting to see atleast the message for a start yet didn't show any control. Just a screen with a phone dialers on the rigth hand.
package com.example.mytest;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Since you are using RelativeLayout, you need to tell Android how each control is relative to each other. Change the layout as follow:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:id="#+id/textView1"
android:textColor="#FF00FF00"/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#+id/textView1"
android:textColor="#FF0000FF"
android:id="#+id/et_Text" />
This will tell the system to place the EditText below the TextView.