I am using a simple code to open up a camera on opencv the app works fine on LG G Pro but crashes on samsung galaxy S4
Please Note that this activity is called via another activity through intent.
GameActivity.java
public class GameActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
public static final String MY_TAG = "MY_CUSTOM_MESSAGE";
private JavaCameraView javaCameraView;
private BaseLoaderCallback baseLoaderCallback= new BaseLoaderCallback(this) {
#Override
public void onManagerConnected(int status) {
switch (status){
case LoaderCallbackInterface.SUCCESS:
{
Log.i(MY_TAG, "OPENCV Loaded");
javaCameraView.enableView();
break;
}
default:
super.onManagerConnected(status);
}
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Log.i(MY_TAG, "onCreate Act 2");
javaCameraView=(JavaCameraView)findViewById(R.id.MyJavaCam);
javaCameraView.setVisibility(SurfaceView.VISIBLE);
javaCameraView.setCvCameraViewListener(this);
}
#Override
protected void onResume() {
super.onResume();
Log.i(MY_TAG, "onResume Act 2");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_11, this, baseLoaderCallback);
Log.i(MY_TAG, "onResume Act 2 done resuming");
}
#Override
protected void onPause() {
super.onPause();
Log.i(MY_TAG, "onPause Act 2");
}
#Override
public void onCameraViewStarted(int width, int height) {
}
#Override
public void onCameraViewStopped() {
}
#Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
return inputFrame.rgba();
}
#Override
protected void onDestroy() {
super.onDestroy();
if(javaCameraView != null)
{
javaCameraView.disableView();
}
}
}
content_game.xml
<org.opencv.android.JavaCameraView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
android:id="#+id/MyJavaCam"
opencv:show_fps="true"
opencv:camera_id="any"
/>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".GameActivity"
android:label="#string/title_activity_game"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="com.roundcube.gamewithserver.GameActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Logcat
07-10 04:13:48.107 11233-11233/com.roundcube.gamewithserver E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.roundcube.gamewithserver, PID: 11233
java.lang.RuntimeException: Unable to resume activity {com.roundcube.gamewithserver/com.roundcube.gamewithserver.GameActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=org.opencv.engine.BIND }
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3403)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2772)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
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:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=org.opencv.engine.BIND }
at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:2052)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:2160)
at android.app.ContextImpl.bindService(ContextImpl.java:2138)
at android.content.ContextWrapper.bindService(ContextWrapper.java:559)
at org.opencv.android.AsyncServiceHelper.initOpenCV(AsyncServiceHelper.java:24)
at org.opencv.android.OpenCVLoader.initAsync(OpenCVLoader.java:89)
at com.roundcube.gamewithserver.GameActivity.onResume(GameActivity.java:85)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1255)
at android.app.Activity.performResume(Activity.java:6412)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2772)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
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:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
On using Logs i figured out that problem in this function call
`OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_11, this, baseLoaderCallback);
Please help me find a solution to this thank you.
Related
I have just gotten into Android app development and have been working on parts of my project in bits and pieces.
I first created my onboarding screens and then made my animated splash screen. However, when I run my application my splash screen does not show and instead loads the onboarding pages first. How can I fix this to make my app first transition through the splash screen before moving on the onboarding screens?
This is my SplashActivity Class code
public class SplashActivity extends AppCompatActivity {
private static int SPLASH_SCREEN = 5000;
// Variables
Animation topAnim;
ImageView image;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
// Animations
topAnim = AnimationUtils.loadAnimation(this,R.anim.top_animation);
// Hooks
image = findViewById(R.id.splashScreenLogo);
image.setAnimation(topAnim);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashActivity.this, OnboardingActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_SCREEN);
}
}
This is my OnboardingActivity Class code
public class OnboardingActivity extends AppCompatActivity {
private OnboardingAdapter onboardingAdapter;
private LinearLayout layoutOnboardingIndicators;
private MaterialButton buttonOnboardingAction;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_onboarding);
// Onboarding Screens
layoutOnboardingIndicators = findViewById(R.id.layoutOnboardingIndicators);
buttonOnboardingAction = findViewById(R.id.buttonOnboardingAction);
setupOnboardingItems();
final ViewPager2 onboardingViewPager = findViewById(R.id.onboardingViewPager);
onboardingViewPager.setAdapter(onboardingAdapter);
setupOnboardingIndicators();
setCurrentOnboardingIndicator(0);
onboardingViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
#Override
public void onPageSelected(int position) {
super.onPageSelected(position);
setCurrentOnboardingIndicator(position);
}
});
buttonOnboardingAction.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(onboardingViewPager.getCurrentItem() + 1 < onboardingAdapter.getItemCount()) {
onboardingViewPager.setCurrentItem(onboardingViewPager.getCurrentItem() + 1);
}
else {
startActivity(new Intent(getApplicationContext(), SignUpActivity.class));
finish();
}
}
});
}
}
Edit - My Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mentalhealthapp">
<application
android:allowBackup="true"
android:icon="#drawable/treen_app_logo"
android:label="treen"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashActivity"></activity>
<activity android:name=".HomeActivity" />
<activity android:name=".SignInActivity" />
<activity android:name=".SignUpActivity" />
<activity android:name=".OnboardingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
What should I change in my Manifest File?
You need to set the Launch activity as SplashActivity in your AndroidManifest.xml file
<activity
android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I'm making an android app with 2 activities and a Java class that reads/writes RFID data using NFC.
I'm using the enableReaderMode() method to enable reader/writer mode in the mainActivity, which then calls onTagDiscovered in a separate java class. Once in the onTagDiscovered method, I'm calling mainActivity.startNewActivity() to open a the second activity. I know that I'm reaching startNewActivity() because of a log message, but the activity is not actually starting. The app doesn't crash, and I'm not getting any errors, it just isn't starting. I've tried placing a button in the mainActivity and opening that way, and it works fine. It just doesn't work when I call the method from encode.java.
**I know that it is not necessary to open the activity from Encode.java, and that I could directly code this into MainActivity, but I'm preparing to do something more complex where I will need to open from Encode.java, and I want to test that the activity will open at all.
Here's the code
Encode.java
public class Encode implements NfcAdapter.ReaderCallback {
MainActivity mainActivity = new MainActivity();
public void onTagDiscovered(Tag tag) {
Log.i(TAG, "New tag discovered");
mainActivity.startNewActivity();
}
MainActivity
public void startNewActivity() {
Log.v(TAG, "in startNewActivity");
Intent intent = new Intent(this, Success.class);
startActivity(intent);
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.NFC"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/xband"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech" />
</activity>
<activity android:name=".Success" >
</activity>
</application>
</manifest>
Success.java
package com.project;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class Success extends Activity {
private static final String TAG = "encode";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.success_activity);
Log.v(TAG, "in success activity");
}
}
I tried adding the following code and then got this error message:
Encode.java
public void onTagDiscovered(Tag tag) {
Log.i(TAG, "New Tag Discovered");
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
#Override
public void run() {
mainActivity.startNewActivity();
}
});
}
02-20 11:52:27.739 22088-22088/com.project E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.project, PID: 22088
java.lang.NullPointerException
at android.app.Activity.startActivityForResult(Activity.java:3474)
at android.app.Activity.startActivityForResult(Activity.java:3435)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:3677)
at android.app.Activity.startActivity(Activity.java:3645)
at com.project.MainActivity.startNewActivity(MainActivity.java:110)
at com.project.encoding.Encode$1.run(Encode.java:331)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
Someone at work was able to help me figure this out.
This wasn't working because I was creating a new instance of the MainActivity in Encode, instead of referencing the existing MainActivity.
In MainActivity we added:
private static MainActivity _instance = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
encode = new Encode();
enableReaderMode();
MainActivity._instance = this;
}
public static MainActivity getInstance() {
return _instance;
}
and in Encode we called the startNewActivity method by calling:
public void onTagDiscovered(Tag tag) {
Log.i(TAG, "New Tag Discovered");
MainActivity.getInstance().startNewActivity();
});
so that now Encode is using the existing instance of MainActivity
Instead of:
Intent intent = new Intent(this, Success.class);
Try: Intent intent = new Intent(getApplicationContext(), Success.class);
That worked for me one time cause it "Return the context of the single, global Application object of the current process. "
i have an activity that lets me sign up or simply log in, when the user has been logged in, four fragments, which can be navigated through scrollable tabs are displayed, the last fragment has a log out button, i need that log out button to 1)log out directly from parse.com and 2)get the user to the activity where they can sign up or sign in.
This is the code that i have so far
THIS IS THE SIGN IN OR SIGN UP ACTIVITY
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.signup_or_login);
// Log in button click handler
((Button) findViewById(R.id.login)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Starts an intent of the log in activity
startActivity(new Intent(SignUpOrLogInActivity.this, LoginActivity.class));
}
});
// Sign up button click handler
((Button) findViewById(R.id.signup)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Starts an intent for the sign up activity
startActivity(new Intent(SignUpOrLogInActivity.this, SignUpActivity.class));
}
});
}
THIS IS THE SET UP FRAGMENT WHERE THE LOG OUT BUTTON IS LOCATED
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
return inflater.inflate(R.layout.setup_fragment,container,false);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
logout = (Button) getView().findViewById(R.id.logout_button);
// Logout Button Click Listener
logout.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
// Logout current user
ParseUser.logOut();
startActivity(new Intent(getActivity(), SignUpOrLogInActivity.class));
}
});
}
}
The problems are 1)that when i run the app, it first starts at the scrollable tabs (the fragments) and not at the sign in or sign up activity and 2)when i go to the set up fragment where the log out button is located the app crashes and a message is displayed saying "unfortunately your app has stopped.
HERE IS THE MANIFEST
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".ParseStarter">
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
<activity android:name=".DispatchActivity"
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=".LoginActivity" />
<activity android:name=".SignUpActivity" />
<activity android:name=".SignUpOrLogInActivity" />
</application>
HERE IS THE LOGCAT
Process: com.sebasdeldihotmail.mediocre, PID: 1863
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at com.sebasdeldihotmail.mediocre.Setup.onCreate(Setup.java:35)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1763)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:913)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:249)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
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:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
12-14 00:26:52.791 1863-1863/com.sebasdeldihotmail.mediocre I/Process﹕ Sending signal. PID: 1863 SIG: 9
AND HERE IS THE DISPATCH ACTIVITY CLASS
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
return inflater.inflate(R.layout.setup_fragment,container,false);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
logout = (Button) getView().findViewById(R.id.logout_button);
// Logout Button Click Listener
logout.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
// Logout current user
ParseUser.logOut();
startActivity(new Intent(getActivity(), SignUpOrLogInActivity.class));
}
});
}
THANKS FOR TAKING THE TIME FOR READING THIS I REALLY APPRECIATE IT.
For problem 1: you wrote this in you manifest file
<activity android:name=".DispatchActivity"
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=".LoginActivity" />
<activity android:name=".SignUpActivity" />
<activity android:name=".SignUpOrLogInActivity" />
now change it
<activity android:name=".SignUpOrLogInActivity"
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=".LoginActivity" />
<activity android:name=".SignUpActivity" />
For problem 2:
now look your logout button object ... its actually null .. you inflate a layout in onCreateView.. so you need to make a button object that associated this view .. so do this inside onCreateView() method
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.setup_fragment,container,false);
Button logout = (Button)root.findViewById(R.id.logout_button);
logout.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
// Logout current user
ParseUser.logOut();
startActivity(new Intent((ParentActivity)getActivity(), SignUpOrLogInActivity.class));
}
});
return root;
}
Hope it works ... if face any problem .. just comment it... Thank you
I've got an android project from another developer. He can launch this project on his machine successfully, but when I try to launch it on my machine, I've got this exception when application trying load map in a fragment. The logcat with exception:
09-29 07:37:50.298 2442-2442/nz.co.tish.android.coffeetime E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{nz.co.tish.android.coffeetime/nz.co.tish.android.coffeetime.fragment.MapFragment$InnerActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2054)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at nz.co.tish.android.coffeetime.fragment.MapFragment.onCreate(MapFragment.java:132)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:893)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
at android.view.View.measure(View.java:15848)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:651)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:302)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
at android.view.View.measure(View.java:15848)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
at android.app.Activity.setContentView(Activity.java:1895)
at nz.co.tish.android.coffeetime.fragment.MapFragmen
09-29 07:42:50.399 2442-2442/nz.co.tish.android.coffeetime I/Process﹕ Sending signal. PID: 2442 SIG: 9
Android manifest:
android:versionCode="7"
android:versionName="1.3" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission
android:name="nz.co.tish.android.coffeetime.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="nz.co.tish.android.coffeetime.permission.C2D_MESSAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name="nz.co.tish.android.coffeetime.CoffeetimeApplication"
android:allowBackup="true"
android:description="#string/app_desc"
android:icon="#drawable/app_logo57"
android:label="Coffeetime TISH Limited"
android:screenOrientation="portrait"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDMx6IbAJEWnHuKv_yv4Pkwgx_U1mF2Qkc" />
<!--Debug: AIzaSyDMx6IbAJEWnHuKv_yv4Pkwgx_U1mF2Qkc-->
<!--Live: AIzaSyCnNpNptAzaBdtF9GOAVw-POo1gt2Tsw-Q-->
<meta-data
android:name="com.google.android.gms.versionCode"
android:value="#integer/google_play_services_version" />
<activity
android:name="nz.co.tish.android.coffeetime.MainActivity"
android:label="#string/title_activity_main"
android:screenOrientation="portrait"
android:theme="#style/AppMainTheme" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.PlaceActivity"
android:label="#string/title_activity_place"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.ForgotPasswordActivity"
android:label="#string/title_activity_forgot_password"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.CVCInfoActivity"
android:label="#string/cvc_text_header"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.CategoryActivity"
android:label="#string/title_activity_category"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.MainActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.ProductActivity"
android:label="#string/title_activity_product"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.CategoryActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.CheckoutActivity"
android:label="#string/title_activity_checkout"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.PlaceActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.TopupActivity"
android:label="#string/title_activity_topup"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.RegisterCardActivity"
android:label="#string/title_activity_register_card"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.StoreMapActivity"
android:label="#string/store_map_title_activity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.AuthActivity"
android:label="#string/title_activity_auth"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.VersionInfoActivity"
android:label="#string/title_activity_version"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.AuthActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.TermsActivity"
android:label="#string/title_activity_terms"
android:screenOrientation="portrait" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="launch.TermsActivity" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="nz.co.tish.android.coffeetime.AuthActivity" />
</activity>
<activity
android:name="nz.co.tish.android.coffeetime.fragment.MapFragment$InnerActivity"
android:screenOrientation="portrait" />
<activity
android:name=".LogoutActivity"
android:label="#string/title_activity_logout"
android:screenOrientation="portrait" />
<activity
android:name=".LikeUsOnFacebookActivity"
android:label="Like Us On Facebook Activity"
android:screenOrientation="portrait" />
</application>
The code of fragment with map(MapFragment):
public class MapFragment extends Fragment implements LocationListener {
private static GoogleMap mapView;
private static final String MAP_ACTIVITY_ID = "map-activity";
private static final String ACTIVITY_MANAGER_BUNDLE_KEY = "activity-manager-bundle-key";
private LocalActivityManager localActivityManager;
private LocationManager locationManager = null;
private Window window;
private ProgressDialog dialog = null;
private String bestProvider = null;
private Criteria criteria = null;
private String keyword = "";
private Place[] places;
private HashMap<String, Place> currentPlaces;
private AsyncTask<Object, Object, CallResult<List<Place>>> location_task;
public static class InnerActivity extends
FragmentActivity {
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.fragment_map);
mapView = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.mapv2)).getMap();
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = window.getDecorView();
keyword = ((MainActivity) getActivity()).getSearchString();
locationManager = (LocationManager) view.getContext().getSystemService(
Activity.LOCATION_SERVICE);
if (locationManager == null) {
DialogUtil.showAlert(view.getContext(),
"Sorry, you do not seem to have GPS!");
return null;
}
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
criteria = new Criteria();
bestProvider = locationManager.getBestProvider(criteria, false);
return view;
}
#Override
public void onDestroyView() {
super.onDestroyView();
((ViewGroup) window.getDecorView().getParent()).removeAllViews();
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBundle(ACTIVITY_MANAGER_BUNDLE_KEY,
localActivityManager.saveInstanceState());
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = null;
if (savedInstanceState != null) {
bundle = savedInstanceState.getBundle(ACTIVITY_MANAGER_BUNDLE_KEY);
}
localActivityManager = new LocalActivityManager(getActivity(), true);
localActivityManager.dispatchCreate(bundle);
window = localActivityManager.startActivity(MAP_ACTIVITY_ID,
new Intent(getActivity(), InnerActivity.class));
}
#Override
public void onResume() {
super.onResume();
localActivityManager.dispatchResume();
places = ((MainActivity) getActivity()).getPlaces();
location_task = null;
if (places == null) {
AsyncTask<Object, Object, Location> task = new AsyncTask<Object, Object, Location>() {
#Override
protected Location doInBackground(Object... params) {
return locationManager.getLastKnownLocation(bestProvider);
}
#Override
protected void onPostExecute(Location result) {
onLocationChanged(result);
}
};
task.execute();
locationManager.requestLocationUpdates(bestProvider, 1000 * 60 * 5,
25, this);
} else {
setUpMapview(places);
}
}
private void setUpMapview(Place[] places) {
// List<Overlay> mapOverlays = mapView.getOverlays();
Drawable openPlace = this.getResources().getDrawable(R.drawable.opened);
Drawable closedPlace = this.getResources().getDrawable(
R.drawable.closed);
List<GeoPoint> items = new ArrayList<GeoPoint>();
currentPlaces = new HashMap<String, Place>();
mapView.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker coffe) {
if (currentPlaces != null) {
Intent intent = new Intent(getActivity(),
PlaceActivity.class);
intent.putExtra("place",
currentPlaces.get(coffe.getTitle()));
startActivity(intent);
}
}
});
for (Place place : places) {
GeoPoint point = new GeoPoint((int) (place.getLatitude()),
(int) (place.getLongitude()));
items.add(point);
Marker placeMarker = mapView
.addMarker(new MarkerOptions()
.position(
new LatLng(place.getLatitude(), place
.getLongitude()))
.title(place.getName())
.icon(BitmapDescriptorFactory.fromResource(place
.isOpen() ? R.drawable.opened
: R.drawable.closed)));
currentPlaces.put(place.getName(), place);
// itemizedOverlay.addOverlay(overlayitem);
// mapOverlays.add(itemizedOverlay);
}
MapUtils.animateToCenter(mapView, items, false);
}
#Override
public void onPause() {
super.onPause();
localActivityManager.dispatchPause(getActivity().isFinishing());
}
#Override
public void onStop() {
super.onStop();
localActivityManager.dispatchStop();
}
#Override
public void onDestroy() {
super.onDestroy();
localActivityManager.dispatchDestroy(getActivity().isFinishing());
}
#Override
public void onDetach() {
super.onDetach();
localActivityManager = null;
}
private class DialogOverlay extends SimpleItemizedOverlay {
public DialogOverlay(Drawable defaultMarker, MapView mapView) {
super(defaultMarker, mapView);
}
#Override
protected boolean onBalloonTap(int index, OverlayItem item) {
/*
* Intent intent = new Intent(mapView.getContext(),
* PlaceActivity.class); intent.putExtra("place",
* ((DialogOverlayItem)item).getCurrentPlace());
* startActivity(intent);
*/
return true;
}
}
private class DialogOverlayItem extends OverlayItem {
private Place currentPlace;
public DialogOverlayItem(GeoPoint point, String title, String snippet,
Place place) {
super(point, title, snippet);
setCurrentPlace(place);
}
private Place getCurrentPlace() {
return currentPlace;
}
private void setCurrentPlace(Place currentPlace) {
this.currentPlace = currentPlace;
}
}
}
fragment_map.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
MainActivity:
public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {
private ListView mDrawerList;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private SectionsPagerAdapter mSectionsPagerAdapter;
CustomViewPager mViewPager;
private Place[] places;
private String keyword = "";
private boolean checkedOut;
public Place[] getPlaces() {
return places;
}
public void setPlaces(Place[] places) {
this.places = places;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new MyFavoritesFragment();
case 1:
return new NearMeFragment();
case 2:
return new MapFragment();
case 3:
return new HistoryFragment(checkedOut);
case 4:
return new WalletFragment();
}
return null;
}
#Override
public int getCount() {
return 5;
}
public int getPageIcon(int position) {
switch (position) {
case 0:
return R.drawable.icon_fav;
case 1:
return R.drawable.icon_near;
case 2:
return R.drawable.icon_map;
case 3:
return R.drawable.icon_hist;
case 4:
return R.drawable.icon_wallet;
}
return 0;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getString(R.string.title_activity_my_favorites).toUpperCase();
case 1:
return getString(R.string.title_activity_near_me).toUpperCase();
case 2:
return getString(R.string.title_activity_map).toUpperCase();
case 3:
return getString(R.string.title_activity_history).toUpperCase();
case 4:
return getString(R.string.title_activity_wallet).toUpperCase();
}
return null;
}
}
}
This application also has another Activity with map , and the app is crashing on it too. The logcat:
09-29 08:33:50.559 2604-2604/nz.co.tish.android.coffeetime E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{nz.co.tish.android.coffeetime/nz.co.tish.android.coffeetime.StoreMapActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.maps.internal.q.v(Unknown Source)
at com.google.android.gms.maps.internal.q.u(Unknown Source)
at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$b.ex(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
StoreMapActivity:
public class StoreMapActivity extends FragmentActivity {
private Place place = null;
private GoogleMap mapView;
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return (true);
}
return (super.onOptionsItemSelected(item));
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.store_map_activity);
mapView = (GoogleMap) ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.store_mapv2)).getMap();
Serializable placeSer = getIntent().getSerializableExtra("place");
if (placeSer == null
|| !Place.class.isAssignableFrom(placeSer.getClass())) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
return;
}
place = (Place) placeSer;
setUpMapview();
/*List<Overlay> mapOverlays = mapView.getOverlays();
Drawable openPlace = this.getResources().getDrawable(R.drawable.opened);
Drawable closedPlace = this.getResources().getDrawable(
R.drawable.closed);
List<GeoPoint> items = new ArrayList<GeoPoint>();
SimpleItemizedOverlay itemizedOverlay = new SimpleItemizedOverlay(
place.isOpen() ? openPlace : closedPlace, mapView);
GeoPoint point = new GeoPoint(
(int) (place.getLatitude() * Const.GEOPOINT_CONST),
(int) (place.getLongitude() * Const.GEOPOINT_CONST));
items.add(point);
OverlayItem overlayitem = new OverlayItem(point, place.getName(), "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
// MapUtils.animateToCenter(mapView, items, true);*/
}
private void setUpMapview() {
Drawable openPlace = this.getResources().getDrawable(R.drawable.opened);
Drawable closedPlace = this.getResources().getDrawable(
R.drawable.closed);
List<GeoPoint> items = new ArrayList<GeoPoint>();
mapView.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker coffe) {
if (place != null) {
Intent intent = new Intent(StoreMapActivity.this,
PlaceActivity.class);
intent.putExtra("place", place);
startActivity(intent);
}
}
});
GeoPoint point = new GeoPoint((int) (place.getLatitude()),(int)(place.getLongitude()));
items.add(point);
Marker placeMarker = mapView.addMarker(new MarkerOptions().position(
new LatLng(place.getLatitude(), place.getLongitude()))
.title(place.getName())
.icon(BitmapDescriptorFactory.fromResource(place
.isOpen() ? R.drawable.opened
: R.drawable.closed)));
MapUtils.animateToCenter(mapView, items, false);
}
}
store_map_activity.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/store_mapv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
When I commented the code initializing the maps on these parts of application, it will start working normally.
Please verify that you have added the exceptions to your proguard configuration file. How and what to add is explained in Setting up Google Play Services
For the first, change your fragment from this:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
to this:
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
the main difference in this case is
class="com.google.android.gms.maps.SupportMapFragment"
to this:
android:name="com.google.android.gms.maps.SupportMapFragment"
For the second: add the following to the end of your manifest (but beforde the end-tag application!)
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
In your code you can ask for the service with the following:
// check status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
try {
if (status != ConnectionResult.SUCCESS)
{
GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show();
}
} catch (Exception e) {
Log.e("Error: ", + e);
}
OK, so the problem I'm having occurs when the startGame button is pressed. The app crashes when the button is pressed. The activity is instantiated in the manifest so I'm not sure where the error is. The code for the intent is a copy of the other one (which works) so I have no clue where I went wrong.
Error Log:
02-25 14:46:51.064: E/AndroidRuntime(1261): FATAL EXCEPTION: main
02-25 14:46:51.064: E/AndroidRuntime(1261): Process: com.example.hegemony, PID: 1261
02-25 14:46:51.064: E/AndroidRuntime(1261): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.hegemony/com.example.hegemony.PlayerTurn}: java.lang.NullPointerException
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hegemony"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.hegemony.SplashScreen"
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="com.example.hegemony.StartScreen" >
<intent-filter>
<action android:name="com.example.hegemony.STARTSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.hegemony.SetupHomeScreen" >
<intent-filter>
<action android:name="com.example.hegemony.SETUPHOMESCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.hegemony.SetupPlayer"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.hegemony.SETUPPLAYER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.hegemony.PlayerTurn"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.hegemony.PLAYERTURN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Java Code of sending activity:
public class SetupHomeScreen extends Activity{
private ArrayList<Player> p = GameMaster.players;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup_home_screen);
getActionBar().hide();
updatePlayers();
Button gotoInput = (Button) findViewById(R.id.btnSetupPlayer);
gotoInput.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent toInput = new Intent("com.example.hegemony.SETUPPLAYER");
startActivity(toInput);
}
});
Button startGame = (Button) findViewById(R.id.btnStartGame);
startGame.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent toStart = new Intent("com.example.hegemony.PLAYERTURN");
startActivity(toStart);
}
});
}
public void updatePlayers(){
TextView playerList = (TextView) findViewById(R.id.playerList);
String msg = "";
for(int i=0;i < p.size();i++)
msg = msg + "\n - "+p.get(i).getName();
playerList.setText(msg);
if(p.size() >=2){
Button enable = (Button) findViewById(R.id.btnStartGame);
enable.setEnabled(true);
}
}
}
Java code of receiving activity:
public class PlayerTurn extends Activity {
final ActionBar actionBar = getActionBar();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player_turn);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
};
}
}
Button startGame = (Button) findViewById(R.id.btnStartGame);
startGame.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent toStart = new Intent(SendingActivity.this, NewActivity.class);
startActivity(toStart);
}
});
I think this is how you should start an intent. Maybe its missing a context or the "activityname" is not the right way to do it. I tried to start an activity the way you are trying and it gave me an error as well, not the same one, but it didn't work.
I'm sorry if the solution I'm trying to provide doesn't work. This is really the first time I'm trying to help someone. I hope it works.
As per the logcat error message, your activity class is failing to instantiate. Instantiation involves the allocation and assignment of any class member variables. In the case of PlayerTurn, the only one is this:
final ActionBar actionBar = getActionBar();
The call to getActionBar() throws a NullPointerException because the activity's window has not been built yet - you should call getActionBar() after setContentView() has been called in onCreate(). You can resolve this by simply moving that line of code into onCreate().
If you still want to retain this as a class member variable, declare it but don't assign it:
ActionBar actionBar;
...and then do the assignment in onCreate():
actionBar = getActionBar();