Dear people of the stackoverflow,
I'm afraid im in dire need of help. There is one problem that I keep encountering with my app.
I'm making an app that has three buttons: One to see a link, one for intent and one for sharing stuff on facebook (the reason is due to that you cant send stuff with intent anymore, or so i've been told)
However, according to the Facebook Developer website, i should get a share button. With my code , everything crashes and the only thing i can see, is the share dialog. My question is, what is the main mistake i've made?
My main activity code:
package things;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.view.View.OnClickListener;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.share.ShareApi;
import com.facebook.share.Sharer;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.widget.ShareButton;
import com.facebook.share.widget.ShareDialog;
import java.util.Random;
public class MainActivity extends ActionBarActivity {
private Button btnScore;
private Button btnShare;
private static String APP_ID = "things";
CallbackManager callbackManager;
ShareDialog shareDialog;
//ms = mobile Scores
WebView msWebView;
WebView mfWebView;
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentTitle("Test")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.setContentDescription("Play Something with your facebook friends and many more people!")
.build();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
//Facebook for sharing
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
final ShareButton shareButton = (ShareButton) findViewById(R.id.fb_share_button);
int score = 64;
//Searches the phone for apps that can share simple data
final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "My score of the last game was: " + score + " \n Can you beat my score?");
//This is for the share dialog to show
//an iff statement if it shows
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook")
.setContentDescription(
"The 'Hello Facebook' sample showcases simple Facebook integration")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
}
shareButton.setShareContent(content);
//The buttons
btnScore=(Button)findViewById(R.id.btnScores);
btnShare =(Button)findViewById(R.id.btnShare);
//the score Webview link
msWebView = new WebView(this);
msWebView.loadUrl("Thing");
msWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
ShareDialog.show(this, content);
btnScore.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View vw) {
setContentView(msWebView);
}
});
//the share button
btnShare.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View vw) {startActivity(Intent.createChooser(sendIntent, "share..."));
}
});
shareButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
shareButton.setShareContent(content);
}
} );
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu.
// Adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
// Access the Share Item defined in menu XML
return true;
}
//special method to handle the callbackmanager
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
ShareDialog.show(this, content);
}
#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.menu_item_share) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
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"
android:background="#ffd2e489">
<TextView android:text="Results"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View"
android:id="#+id/btnScores"
android:background="#ffff7878"
android:layout_marginTop="40dp"
android:layout_below="#+id/text"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/text"
android:layout_toStartOf="#+id/text" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:id="#+id/btnShare"
android:background="#ff20f6ff"
android:layout_alignTop="#+id/btnScores"
android:layout_toRightOf="#+id/text"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<com.facebook.share.widget.ShareButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fb_share_button"
android:text="SHARE"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="175dp" />
</RelativeLayout>
And just in case my Android: Manifest:
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/app_id"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<provider android:authorities="com.facebook.app.FacebookContentProviderthings"
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/app_name" />
android:debuggable="true"
</application>
</manifest>
Sorry for the long post, I know the answer is there but can't find the greemly error and this has been bothering me for a week.
Thanks for reading!
Frederick
Edit: I'm using facebookSDK 4.0.
Edit 2.0: the error:
Caused by: java.lang.NullPointerException
at things.MainActivity.onCreate(MainActivity.java:93)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
Edit 3.0 The Logcat:
Process: nl.test.test, PID: 12287
java.lang.ExceptionInInitializerError
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:240)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at nl.test.test.MainActivity.onCreate(MainActivity.java:60)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
at dalvik.system.NativeStart.main(Native Method)
Caused by: null
at com.facebook.internal.Validate.sdkInitialized(Validate.java:99)
at com.facebook.FacebookSdk.getCallbackRequestCodeOffset(FacebookSdk.java:735)
at com.facebook.internal.CallbackManagerImpl$RequestCodeOffset.toRequestCode(CallbackManagerImpl.java:109)
at com.facebook.share.widget.ShareButton.<clinit> (ShareButton.java:36)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
android.view.LayoutInflater.inflate(LayoutInflater.java:492)
android.view.LayoutInflater.inflate(LayoutInflater.java:397)
android.view.LayoutInflater.inflate(LayoutInflater.java:353)
android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:240)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
test.MainActivity.onCreate(MainActivity.java:60)
at android.app.Activity.performCreate(Activity.java:5231)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
android.app.ActivityThread.access$800(ActivityThread.java:144) android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:212)
android.app.ActivityThread.main(ActivityThread.java:5135)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
dalvik.system.NativeStart.main(Native Method)
Alright, after some work, I found the answer. The answer is very simple:
instead of this:
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
But what you need to do is this:
FacebookSdk.sdkInitialize(getApplicationContext());
super.onCreate(savedInstanceState);
The reason to do this, is because you want to initialize the Facebook SDK before you create the app instance, otherwise, the Facebook SDK can never be used by the app.
I hope that if someone has the same problem as I had, can use this!
Related
here is my logcat as the app crashes after i press the TextView
06-04 12:58:26.944 5680-5680/com.example.sandwichswitch E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sandwichswitch, PID: 5680
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.sandwichswitch/com.example.sandwichswitch.fragmentprofile}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1794)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:574)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:560)
at android.app.Activity.startActivity(Activity.java:4200)
at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
at androidx.fragment.app.FragmentHostCallback.onStartActivityFromFragment(FragmentHostCallback.java:166)
at androidx.fragment.app.Fragment.startActivity(Fragment.java:1377)
at androidx.fragment.app.Fragment.startActivity(Fragment.java:1365)
at com.example.sandwichswitch.fragmentprofile.onClick(fragmentprofile.java:44)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
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)
here is the java part of the activity (the fragmentprofile activity)
package com.example.sandwichswitch;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public class fragmentprofile extends Fragment implements View.OnClickListener{
#Nullable
#org.jetbrains.annotations.Nullable
#Override
public View onCreateView(#NonNull #org.jetbrains.annotations.NotNull LayoutInflater inflater, #Nullable #org.jetbrains.annotations.Nullable ViewGroup container, #Nullable #org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.fragmentprofile,container,false);
return view;
}
#Override
public void onActivityCreated(#Nullable #org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
TextView textView=getActivity().findViewById(R.id.tvtest);
textView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.tvtest:
Intent intent=new Intent(getActivity(),fragmentprofile.class);
startActivity(intent);
}
}
}
and here is the xml part of fragmentprofile
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="#+id/tvtest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:text="profile"
android:textSize="30dp"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
and here is the manifest, I added it because the log cat said somthing about declaring my activity here but if you keep scroling you can see what i tryed and what were the resaults
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sandwichswitch">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".createprofile"></activity>
<activity android:name=".
Profile" />
<activity android:name=".LogInScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
the log cat said somthing about declaring the activity there but when I add the line
<activity android:name="fragmentprofile"
tools:ignore="Instantiatable"></activity>
it still crashes and this is the logcat
06-04 13:14:50.370 6273-6273/com.example.sandwichswitch E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sandwichswitch, PID: 6273
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.sandwichswitch/com.example.sandwichswitch.fragmentprofile}: java.lang.ClassCastException: com.example.sandwichswitch.fragmentprofile cannot be cast to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
Caused by: java.lang.ClassCastException: com.example.sandwichswitch.fragmentprofile cannot be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
The issue is in the next section:
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.tvtest:
Intent intent=new Intent(getActivity(),fragmentprofile.class);
startActivity(intent);
}
}
Specificially in the last paramenter of the next line:
Intent intent=new Intent(getActivity(),fragmentprofile.class);
The method startActivity as the name states, is used to start activities, not fragments.
The last parameter in your code is passing fragmentprofile.class which is wrong. Instead it should be an activity class that you wish to start.
If you need to open a fragment, then read the Fragment Manager documentation, as opening fragments is a completely different paradigm from starting an activity.
you are try a start activity in the same fragment
your fragment name is fragmentprofile and you are call intent like this
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.tvtest:
Intent intent=new Intent(getActivity(),fragmentprofile.class);
startActivity(intent);
}
}
}
you are call same fragment then it will crash a apk the solution is
Fragment2 fragment2 = new Fragment2(); //your destination fragment
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content, fragment2);
fragmentTransaction.commit();
try this for call fragment to fragment
I'm receiving an InflateException from ChatActivity when it is not the LAUNCHER activity but when I change the manifest such that ChatActivity is the LAUNCHER, the app work properly.
I'm probably missing something, is there something missing in the code?
Update 18:15 16.10 -
I've found that if I delete
implements View.OnClickListener
from LoginActivity the app working (but now I don't have buttons).
What is the cause of this problem and how can it be fixed?
Part of the MANIFEST when the error accrue -
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Activities.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activities.ChatMainActivity"></activity>
<activity android:name=".Activities.RegisterActivity" />
And if I'm changing the file to this (below) the chat work properly -
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Activities.LoginActivity"></activity>
<activity android:name=".Activities.ChatMainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activities.RegisterActivity" />
The dependencies -
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
XML file of ChatActivity -
<?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"
tools:context=".Activities.ChatMainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appBarLayout">
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.tabs.TabLayout
android:id="#+id/main_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"></com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/main_tabPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/appBarLayout">
</androidx.viewpager.widget.ViewPager>
</RelativeLayout>
The activity -
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.widget.Toolbar;
import com.google.android.material.tabs.TabLayout;
import com.nirkov.hive.Fragments.ChatFragment;
import com.nirkov.hive.Fragments.ChatOffersFragment;
import com.nirkov.hive.Fragments.ChatRequestsFragment;
import com.nirkov.hive.R;
public class ChatMainActivity extends AppCompatActivity {
private ViewPager mViewPager;
private SectionsPagerAdapter mSectionsPagerAdapter;
private TabLayout mTabLayout;
private Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat_main);
mToolbar = (Toolbar) findViewById(R.id.main_app_bar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Chat");
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.main_tabPager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mTabLayout = (TabLayout) findViewById(R.id.main_tabs);
mTabLayout.setupWithViewPager(mViewPager);
}
#Override
public boolean onOptionsItemSelected(MenuItem item){
super.onOptionsItemSelected(item);
return true;
}
#Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.chat_bar_layout, menu);
return true;
}
#Override
public void onStart() {
super.onStart();
}
private class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(#NonNull FragmentManager fm) {
super(fm);
}
#NonNull
#Override
public Fragment getItem(final int position) {
switch (position){
case 0:
return new ChatRequestsFragment();
case 1:
return new ChatFragment();
case 2:
return new ChatOffersFragment();
}
return null;
}
#Override
public int getCount() {
return 3;
}
public CharSequence getPageTitle(final int position){
switch(position){
case 0:
return "REQUESTS";
case 1:
return "CHATS";
case 2:
return "OFFERS";
}
return null;
}
}
}
The appTheme style -
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
The LoginActivity -
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.nirkov.hive.R;
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
private static final String TAG = "LoginActivity";
private Button loginButton;
private EditText emailBox, passwordBox;
private TextView registerHereLink;
private FirebaseAuth mAuth;
ProgressBar progressBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loginButton = (Button) findViewById(R.id.loginButton);
emailBox = (EditText)findViewById(R.id.emailBox);
passwordBox = (EditText)findViewById(R.id.passwordBox);
registerHereLink = (TextView)findViewById(R.id.registerHereLink);
progressBar = (ProgressBar) findViewById(R.id.loginProgressBar);
mAuth = FirebaseAuth.getInstance();
loginButton.setOnClickListener(this);
registerHereLink.setOnClickListener(this);
}
#Override
public void onStart() {
super.onStart();
if(mAuth.getCurrentUser() != null){
startActivity(new Intent(this, ChatMainActivity.class));
}
}
#Override
public void onClick(View view) {
switch(view.getId()){
case R.id.loginButton:
String email = emailBox.getText().toString();
String password = passwordBox.getText().toString();
loginButton.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
signIn(email, password);
break;
case R.id.registerHereLink:
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
break;
}
}
private void signIn(String email, final String password){
mAuth.signInWithEmailAndPassword(email, password).
addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Log.d(TAG, "signIn : success");
startActivity(new Intent(LoginActivity.this, MainActivity.class));
}else{
Log.w(TAG, "signIn:failure", task.getException());
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
progressBar.setVisibility(View.GONE);
loginButton.setVisibility(View.VISIBLE);
}
});
}
}
The Login XML file -
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".Activities.LoginActivity">
<TextView
android:id="#+id/email"
android:layout_width="255dp"
android:layout_height="34dp"
android:layout_marginStart="20dp"
android:layout_marginTop="32dp"
android:text="Email:"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/emailBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/email" />
<!--Password : text view and text box-->
<TextView
android:id="#+id/password"
android:layout_width="133dp"
android:layout_height="31dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Password:"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/emailBox" />
<EditText
android:id="#+id/passwordBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/password" />
<Button
android:id="#+id/loginButton"
android:layout_width="115dp"
android:layout_height="37dp"
android:layout_marginStart="8dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="8dp"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/passwordBox" />
<ProgressBar
android:id="#+id/loginProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/spaceInBottom"
app:layout_constraintEnd_toEndOf="#+id/loginButton"
app:layout_constraintStart_toStartOf="#+id/loginButton"
app:layout_constraintTop_toTopOf="#+id/loginButton" />
<TextView
android:id="#+id/registerHereLink"
android:layout_width="63dp"
android:layout_height="12dp"
android:layout_gravity="center_horizontal"
android:layout_marginStart="8dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="8dp"
android:text="Register Here"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/loginButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
The full error -
2019-10-16 01:07:43.323 6109-6109/com.nirkov.hive E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nirkov.hive, PID: 6109
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nirkov.hive/com.nirkov.hive.Activities.ChatMainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.support.design.widget.AppBarLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.support.design.widget.AppBarLayout
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.AppBarLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.AppBarLayout" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.nirkov.hive-8a2GYMMALuvTn0Up_KEgfw==/base.apk"],nativeLibraryDirectories=[/data/app/com.nirkov.hive-8a2GYMMALuvTn0Up_KEgfw==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.nirkov.hive.Activities.ChatMainActivity.onCreate(ChatMainActivity.java:38)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
upload login Activity code as well , and tell me which is your parent class
Can you try adding
<item name="windowNoTitle">true</item>
to your main style and see if that works?
Didn't find class "android.support.design.widget.AppBarLayout" on path
Comes from your activity where you set the toolbar wrongly:
mToolbar = (Toolbar) findViewById(R.id.main_app_bar);
setSupportActionBar(mToolbar);
Your toolbar is wrapped by com.google.android.material.appbar.AppBarLayout.
So there's no need to add it into the supportActionBar.
Just define your activity theme as NoActionBar (in your styles.xml) and delete setSupportActionBar(mToolbar); in your activity
Ok, so I just begun with Android Development and basically my issue is what title describes. What I tried until now is to create a default Drawer Navigation Activity project and write a Google Maps Fragment class and lastly inflate this to the main content.
The reason I want this to work is because Drawer Nav Activity looks nice and it would be nice to have google maps in the main screen of it.
By reading the Docs: http://developer.android.com/guide/components/fragments.html I understand that in order to successfully display a fragment inside another activity you need to firstly create a Google Maps Class that extends MapFragment or Fragment and secondly declare the fragment inside the activity's layout file.
No matter what I tried, it just never works. I have managed to draw Google Maps successfully but its Class code is not being invoked, thus Maps actions do not exist.
The google maps responsible GMapsFragment Class (I think that the marked line below (35) is causing the error in conjuction with the maps xml file):
package com.example.s0me0n3.ytgooglemapstut;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class GMapsFragment extends Fragment {
public MapView mapView;
private static GoogleMap googleMap;
public GMapsFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
Log.w("GMAPS", "Map place 1");
// **********************************************************************************
// The line below throws an inflation error when trying to parse the fragment_map xml
// **********************************************************************************
View rootView = inflater.inflate(R.layout.fragment_map, container, false);
// Log.w("GMAPS", "Map place 1");
if (googleMap != null)
setUpMap();
if (googleMap == null) {
googleMap = ((MapFragment) MyActivity.fragmentManager.findFragmentById(R.id.ContactMapView)).getMap();
if (googleMap != null) {
setUpMap();
}
}
return rootView;
}
private static void setUpMap() {
googleMap.setMyLocationEnabled(true);
googleMap.addMarker(new MarkerOptions().position(new LatLng(41.009471, 28.916134)).title("baslik"));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(41.009471, 28.916134), 12.0f));
}
#Override
public void onDestroyView() {
super.onDestroyView();
if (googleMap != null) {
MyActivity.fragmentManager.beginTransaction()
.remove(MyActivity.fragmentManager.findFragmentById(R.id.ContactMapView))
.commit();
googleMap = null;
}
}
}
and the main activity class MyActivity:
package com.example.s0me0n3.ytgooglemapstut;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.widget.DrawerLayout;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.MapFragment;
public class MyActivity extends Activity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
public static FragmentManager fragmentManager;
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
/**
* Used to store the last screen title. For use in {#link #restoreActionBar()}.
*/
private CharSequence mTitle;
// private GMapsFragment _gmaps;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// _gmaps = (GMapsFragment)
// getFragmentManager().findFragmentById(R.id.ContactMapView);
// FragmentTransaction fragmentTransaction = _gmaps.beginTransaction();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
// *** The Note below is pointing here! ***
GMapsFragment fragment = new GMapsFragment();
fragmentTransaction.add(R.id.container, fragment);
fragmentTransaction.commit();
}
#Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
case 2:
mTitle = getString(R.string.title_section2);
break;
case 3:
mTitle = getString(R.string.title_section3);
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.my, menu);
restoreActionBar();
return true;
}
return super.onCreateOptionsMenu(menu);
}
#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) {
// showMsg("Settings reeee");
// Log.w("MyActivity", "Will now log u out...");
Intent intent = new Intent();
intent.setClass(MyActivity.this, SetPreferenceActivity.class);
startActivityForResult(intent, 0);
// return true;
}
return super.onOptionsItemSelected(item);
}
private void showMsg(String msg) {
Toast toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, toast.getXOffset() / 2, toast.getYOffset() / 2);
toast.show();
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_my, container, false);
return rootView;
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((MyActivity) activity).onSectionAttached(
getArguments().getInt(ARG_SECTION_NUMBER));
}
}
}
Note: If I change the line 73 "GMapsFragment fragment = new GMapsFragment();" in the MyActivity Class with something like this "Fragment fragment = new MapFragment();" then it works fine, but of course the GMapsFragment is not being run. Instead a default gmaps is being displayed with no functionalities at all. However, I do not understand why the inflation of my own gmaps fragment will not work.
After that, I understand that I have to include the Google Maps fragment inside the main xml.. so here is the activity_my.xml:
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment android:id="#+id/navigation_drawer"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.example.s0me0n3.ytgooglemapstut.NavigationDrawerFragment"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
and the fragment_map.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/ContactMapView"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.s0me0n3.ytgooglemapstut" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="com.example.s0me0n3.ytgooglemapstut.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.s0me0n3.ytgooglemapstut.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.example.s0me0n3.ytgooglemapstut.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-permission android:name="com.example.s0me0n3.ytgooglemapstut.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.example.s0me0n3.ytgooglemapstut.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<activity
android:name=".MyActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SetPreferenceActivity"
android:label="User Settings" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCoyacHtM9Nl0rjDYFJqV9wUQfiN6OlDOU"/>
</application>
</manifest>
The Logcat errors that I am receiving after running the app is:
10-10 12:44:55.420 8017-8017/com.example.s0me0n3.ytgooglemapstut E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.s0me0n3.ytgooglemapstut, PID: 8017
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.s0me0n3.ytgooglemapstut/com.example.s0me0n3.ytgooglemapstut.MyActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.example.s0me0n3.ytgooglemapstut.GMapsFragment.onCreateView(GMapsFragment.java:35)
at android.app.Fragment.performCreateView(Fragment.java:1700)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
at android.app.Activity.onCreateView(Activity.java:4805)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.example.s0me0n3.ytgooglemapstut.GMapsFragment.onCreateView(GMapsFragment.java:35)
at android.app.Fragment.performCreateView(Fragment.java:1700)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
at android.app.Activity.performStart(Activity.java:5240)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #1: Duplicate id 0x7f050017, tag null, or parent id 0x7f050015 with another fragment for com.google.android.gms.maps.MapFragment
at android.app.Activity.onCreateView(Activity.java:4791)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.example.s0me0n3.ytgooglemapstut.GMapsFragment.onCreateView(GMapsFragment.java:35)
at android.app.Fragment.performCreateView(Fragment.java:1700)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
at android.app.Activity.onCreateView(Activity.java:4805)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.example.s0me0n3.ytgooglemapstut.GMapsFragment.onCreateView(GMapsFragment.java:35)
at android.app.Fragment.performCreateView(Fragment.java:1700)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
at android.app.Activity.performStart(Activity.java:5240)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Last words.. I tried running the GMapsFragment class from other xml files or the my_activity.xml but I always end up getting errors.
So, after that wall spam, let me explain to you my goal. I would like to use the default produced Drawer Nav code from Android Studio in conjuction with a Google Maps that is being displayed on the main content.
Any enlightenment would be awesome. I have been searching for the last 6 days for a solution with no luck. It has to be a really silly mistake, I know but I am stuck.
P.S: I have seen examples using the SupportMapFragment but I would like to make my above code work or understand why this is impossible if so.
Change your fragment_map.xml to :
<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">
<fragment
android:id="#+id/ContactMapView"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
I would like to begin by saying I know this error has been posted about 2,000 times, but after looking through pages and pages of people with the same issue and trying all of their fixes, none of them have worked so I decided to make a new question. I apologize if there is a thread with a solution for my specific problem, I was not able to locate it.
With that out of the way, I believe the error is that there is a NullPointerException on line 41 of MainActivity.Java, because the Google Map is null and not being initialized.
Line 41 is as follows:
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapU)).getMap();
If I remove all of my code from MainActivity.Java, leaving only the code generated by Android Studio, the app starts up fine and will display a Google Map of the World, so I don't think it has anything to do with my API key or Google Play Services not being updated.
Some stuff I have tried is:
-Switching from FragmentManager to SupportFragmentManager on line 41 (When I did this I changed the map from FragmentMap to SupportMapFragment)
-Adding permissions to the Manifest file, you can see everything I have ended up with.
-Different devices (Doesn't work on a Samsung Galaxy S2 or a Galaxy S4)
-I was originally on minSDK 12, decided to change to 16 just to see if it would help, nothing
NOTE: When I first created this project, for some reason the MainActivity.Java said extends ActionBarActivity instead of FragmentActivity, so I changed it to say FragmentActivity, but I was having this issue both before and after.
Manifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hasan.maps" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="com.google.android.providers.gsf.permission.MAPS_RECIEVE"></uses-permission>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.hasan.maps.MainActivity"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="APIKEY_IS_INSERTED_HERE"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
MainActivity.Java
package com.hasan.maps;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import com.google.android.gms.maps.CameraUpdate;
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.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
public class MainActivity extends FragmentActivity {
private GoogleMap map;
private final LatLng Location_NJIT = new LatLng(40.7406517, -74.1792757);
private final LatLng Location_Stevens = new LatLng(40.7469309, -74.0258336);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapU)).getMap();
}
#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);
}
public void onClick_city (View v){
}
public void onClick_njit (View v){
CameraUpdate update = CameraUpdateFactory.newLatLng(Location_NJIT);
map.animateCamera(update);
}
public void onClick_stevens (View v){
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
Logcat
Logcat
01-31 00:08:42.050 14353-14353/com.hasan.maps E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hasan.maps/com.hasan.maps.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4938)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.hasan.maps.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:5188)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4938)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
Fragment_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="com.hasan.maps.MainActivity$PlaceholderFragment">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mapU"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_below="#+id/stevens" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City"
android:id="#+id/city"
android:layout_above="#+id/map"
android:layout_toRightOf="#+id/header"
android:onClick="onClick_city" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NJIT"
android:id="#+id/njit"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/city"
android:onClick="onClick_njit" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stevens"
android:id="#+id/stevens"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/njit"
android:onClick="onClick_stevens" />
</RelativeLayout>
Thanks in advance!
//Actually you have declared frafment id android:id="#+id/mapU" in layout Fragment_Main.xml
but your are calling in MainActivity.java with layout activity_main.xml
make sure that you are declared map fragment in activity_mail.xml.
or call the map in your
PlaceholderFragment
map = ((SupportMapFragment) getSupportFragmentManager()rootView.findFragmentById(R.id.mapU)).getMap();
ANSWER:
I figured it out finally after hours of tearing my hair out. The code had to be moved under the Fragment Activity Class.
I am facing an issue with a button onclick. I checked with previously asked questions, but was not able to figure out the problem, where exactly it lies. The first time, when I click on, 'Next' button, it successfully moves to next page, but in the second page, after entering details, when the 'Proceed'button is clicked, the application crashes.
Activity1:
package com.application.P1;
//import com.application.P1.R;
//import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class P1Activity extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
// #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Using TextView to Give a Home Page Screen
TextView tv=new TextView(this);
tv.setText("WELCOME TO Application Click on Next to Proceed");
setContentView(R.layout.main);
}
public void Welcome( View v){
// Toast.makeText(this, "Please enter your Nickname and proceed further", Toast.LENGTH_SHORT).show();
Intent myActivity = new Intent(this,Activity2.class);
startActivity(myActivity);
// EditText t
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Activity2:
package com.application.P1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Activity2 extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
// #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
}
public void Proceed4( View v){
// Toast.makeText(this, "Thanks for entering your nickname", Toast.LENGTH_SHORT).show();
Intent myActivity2 = new Intent(this,Activity3.class);
startActivity(myActivity2);
// EditText t
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Activity3:
package com.application.P1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
//import android.content.Intent;
//import android.widget.Button;
import android.widget.Toast;
public class Activity3 extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
// #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.check);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
All the three activities are in same package. In the second activity, after button click, when a message is toasted, the toasted message is coming properly. But, when the next activity is called, it is not coming.
XML Coding:
Main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/backrepeat"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<Button
android:text="#string/Next"
android:id="#+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="Welcome"/>
</LinearLayout>
login.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/mynickname" />
<EditText
android:id="#+id/mynickname3"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:text="#string/Proceed"
android:id="#+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="Proceed4"/>
</LinearLayout>
Check.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello3" />
</LinearLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application.P1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/cherry"
android:label="#string/app_name" >
<activity
android:name=".P1Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2">
</activity>
<activity android:name=".Activity3"></activity>
</application>
</manifest>
03-22 00:50:27.125: E/AndroidRuntime(857): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 00:50:27.125: E/AndroidRuntime(857): at java.lang.reflect.Method.invoke(Method.java:507)
03-22 00:50:27.125: E/AndroidRuntime(857): at android.view.View$1.onClick(View.java:2139)
03-22 00:50:27.125: E/AndroidRuntime(857): ... 11 more
03-22 00:50:27.125: E/AndroidRuntime(857): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity
class {com.application.P1/com.application.P1.Activity3}; have you declared this activity in your AndroidManifest.xml?
03-22 00:50:27.125: E/AndroidRuntime(857): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-22 00:50:27.125: E/AndroidRuntime(857): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-22 00:50:27.125: E/AndroidRuntime(857): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-22 00:50:27.125: E/AndroidRuntime(857): at android.app.Activity.startActivity(Activity.java:2933)
03-22 00:50:27.125: E/AndroidRuntime(857): at com.application.P1.Activity2.Proceed4(Activity2.java:31)
03-22 00:50:27.125: E/AndroidRuntime(857): ... 14 more
03-22 00:50:29.867: I/Process(857): Sending signal. PID: 857 SIG: 9
Values.xml:
<string name="hello">Welcome to Expresso Application</string>
<string name="Next">Next</string>
<string name="app_name">Expresso2</string>
<string name="Proceed">Proceed</string>
<string name="Nickname">Nickname</string>
<string name="mynickname">myNickname</string>
<string name="hello3">Tensions</string>
Based on the stack trace, it appears that your manifest file does not declare the activity. Check that there is an <activity> tag for Activity3.
fist replace in Activity A:
this
// #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Using TextView to Give a Home Page Screen
TextView tv=new TextView(this);
tv.setText("WELCOME TO Application Click on Next to Proceed");
setContentView(R.layout.main);
}
from this code :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Using TextView to Give a Home Page Screen
TextView tv=new TextView(this);
tv.setText("WELCOME TO Application Click on Next to Proceed");
}