Error inflating class fragment in Android popular movies app - android

After i made some changes in an AsynTask i get this error when running the app:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.popularmovies/com.example.android.popularmovies.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
This is the activity_main.xml file.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment"
android:name="com.example.android.popularmovies.MainActivityFragment"
tools:layout="#layout/fragment_main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
And this is the MainActivity.java file:
package com.example.android.popularmovies;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#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);
}
}
Thanks for any help you can provide! ;)

I am not sure try the following:
Add
tools:context= ".MainActivity"
or Can you put <fragment> inside a <FrameLayout>.
Clean the code once.

Related

I want to publish geosever layer in android app, using arcgis SDK, i have done code but it is not working, please tell me what i am doing wrong?

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.

Implementing sliding tab within fragment

I have a navigation drawer and against each item within the drawer there is one fragment page. I want to implement tabbed swipe within one fragment. How do I do that.
Here's my code after clicking to one navigation drawer fragment page. I want to implement the tabbed view within this page. What's the way?
//Code
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {#link Fragment} subclass.
*/
public class SalesFragment extends Fragment {
private Toolbar mToolbar;
public SalesFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_sales, container, false);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.toolbar_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
#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.add_user) {
return true;
}
if (id == R.id.barcode_scanner) {
return true;
}
if (id == R.id.search_overflow) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
//and here is the layout xml page
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.soumya.possystem.SalesFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Sales page"
android:textSize="40dp"/>
</FrameLayout>
You can created tabbed fragment page viewer by using Android Studio Activity Gallery. Just follow the below steps and create in half minute.
-> File -> New -> Activity -> Choose the type Tabbed Activity
-> Choose Navigation Style Action Bar Tabs (With ViewPager)
Enjoy Coding !

Android Studio: Adding Action Bar Item with "onClick" encounters "FATAL EXCEPTION"

So I'm starting to work on my first Android App and I've already hit a wall. I want to start off with a "Create" button at the action menu at the top that has the ability to create new contacts. But then I hit some sort of error I can't understand and it's been hindering my process.
The error started when I added the "onClick" line tot he action item and since then, stopped running on my emulator.
Thank you.
MainActivity.java
package com.xephos.detra;
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.TextView;
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);
}
public void create(View v){
TextView tv = (TextView) findViewById(R.id.test);
tv.setText("Working!");
}
}
This might help: the menu_main.xml.
<menu 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" tools:context=".MainActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item
android:id="#+id/add"
android:title="Add New Contact"
app:showAsAction ="always"
android:icon="#drawable/ic_add_white_48dp"
android:onClick="create"/>
</menu>
And finally, the error:
20653-20653/com.xephos.detra E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.xephos.detra, PID: 20653
android.view.InflateException: Couldn't resolve menu item onClick handler create in class com.xephos.detra.MainActivity
at android.support.v7.internal.view.SupportMenuInflater$InflatedOnMenuItemClickListener.<init>(SupportMenuInflater.java:242)
at android.support.v7.internal.view.SupportMenuInflater$MenuState.setItem(SupportMenuInflater.java:443)
at android.support.v7.internal.view.SupportMenuInflater$MenuState.addItem(SupportMenuInflater.java:479)
at android.support.v7.internal.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:196)
at android.support.v7.internal.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118)
at com.xephos.detra.MainActivity.onCreateOptionsMenu(MainActivity.java:22)
at android.app.Activity.onCreatePanelMenu(Activity.java:2823)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:277)
at android.support.v7.internal.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:84)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(AppCompatDelegateImplBase.java:275)
at android.support.v7.app.AppCompatDelegateImplV7.preparePanel(AppCompatDelegateImplV7.java:1117)
at android.support.v7.app.AppCompatDelegateImplV7.doInvalidatePanelMenu(AppCompatDelegateImplV7.java:1399)
at android.support.v7.app.AppCompatDelegateImplV7.access$100(AppCompatDelegateImplV7.java:89)
at android.support.v7.app.AppCompatDelegateImplV7$1.run(AppCompatDelegateImplV7.java:126)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NoSuchMethodException: create [interface android.view.MenuItem]
at java.lang.Class.getMethod(Class.java:664)
at java.lang.Class.getMethod(Class.java:643)
at android.support.v7.internal.view.SupportMenuInflater$InflatedOnMenuItemClickListener.<init>(SupportMenuInflater.java:240) ...
            
You create method needs to take a MenuItem as the argument, not a View.
public void create(MenuItem item){
TextView tv = (TextView) findViewById(R.id.test);
tv.setText("Working!");
}
Alternatively, remove the android:onClick attribute of your menu item and handle the click in onOptionsItemSelected() by checking the id of the item:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.add:
// your code here
return true;
case R.id.action_settings:
// copied from auto-generated stub
return true;
}
return super.onOptionsItemSelected(item);
}
Either will work, my preference is the second approach.
You'd be better off doing it programmatically. Get rid of the 'android:OnClick' line in the XML, then after you set the text of 'tv' put in this:
tv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Process click here
});
This should do the trick!

Could-not create the view: org.eclipse.pde.runtime.LogView

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.

How to solve inconvertable types cannot cast "Android.support.v4.app.fragment" to "packagename"

I am creating an android application that consists of navigation drawer in android studio.
I am getting an error called inconvertable types cannot cast "How to solve inconvertable types cannot cast "Android.support.v4.app.fragment" to "packagename"" please helpme howto solve this.
This is my activity_main.java
package sample.lakshman.com.sampleltester;
import android.content.Intent;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.Toolbar;
import sample.lakshman.com.sampleltester.Fragment_navigation;
public class MainActivity extends ActionBarActivity {
public Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
Fragment_navigation drawer_navigation = (Fragment_navigation)getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawer_navigation.setUp((DrawerLayout)findViewById(R.id.drawer_layout),toolbar);
}
#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;
}
if(id==R.id.navigation_item)
{
Intent sub = new Intent(MainActivity.this,Subactivity.class);
startActivity(sub);
}
return super.onOptionsItemSelected(item);
}
}
This is my main_activity.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar" />
</RelativeLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_fragment_navigation"
android:name="sample.lakshman.com.sampleltester.Fragment_navigation"
tools:layout="#layout/fragment_fragment_navigation" />
</android.support.v4.widget.DrawerLayout>
Just go to your Fragment_navigation class and
replace
import android.app.Fragment;
with
import android.support.v4.app.Fragment;

Categories

Resources