java.lang.NoClassDefFoundError & java.lang.ClassNotFoundException - Android - java

my first question so I hope I'm doing this right.
I have added tablet layouts to my Android project and now I have a few crash reports on various devices. It works 100% just fine for me, however, testers with tablets get force closed at runtime.
The app is a simple dashboard allowing users to apply themes to third party launchers, Much like the Stark and Flatro icon packs.
Here's the errors:
java.lang.NoClassDefFoundError: com.arandompackage.jive.Fragment1$1
at com.arandompackage.jive.Fragment1.onActivityCreated(Fragment1.java:57)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1468)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:931)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1064)
at android.support.v4.view.ViewPager.populate(ViewPager.java:911)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1432)
at android.view.View.measure(View.java:12911)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:828)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:557)
at android.view.View.measure(View.java:12911)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4805)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:297)
at android.view.View.measure(View.java:12911)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:828)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:557)
at android.view.View.measure(View.java:12911)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4805)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:297)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2097)
at android.view.View.measure(View.java:12911)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
And
java.lang.RuntimeException: Unable to instantiate receiver com.arandompackage.jive.AnalogClockWidget: java.lang.ClassNotFoundException: com.arandompackage.jive.AnalogClockWidget
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2261)
at android.app.ActivityThread.access$1600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4946)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.arandompackage.jive.AnalogClockWidget
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2256)
... 10 more
I have done everything that all of these posts suggest, to no avail.
Here's the fragment1 java
package com.arandompackage.jive;
import com.arandompackage.jive.R;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import de.keyboardsurfer.android.widget.crouton.Style;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
public class Fragment1 extends Fragment{
static final String ACTION_APPLY_ICON_THEME = "com.teslacoilsw.launcher.APPLY_ICON_THEME";
public static final String ACTION_MYTHEME = "com.gau.go.launcherex.MyThemes.mythemeaction";
public static final String ACTION_SET_THEME = "com.anddoes.launcher.SET_THEME";
static final String EXTRA_ICON_THEME_PACKAGE = "com.teslacoilsw.launcher.extra.ICON_THEME_PACKAGE";
static final String EXTRA_ICON_THEME_TYPE = "com.teslacoilsw.launcher.extra.ICON_THEME_TYPE";
public static final String EXTRA_PACKAGE_NAME = "com.anddoes.launcher.THEME_PACKAGE_NAME";
ImageButton button;
Button button2;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment_1, null);
}
private boolean isAppInstalled(String uri) {
PackageManager pm = getActivity().getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
#Override
public void onActivityCreated (Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
button = (ImageButton) getActivity().findViewById(R.id.apextheme);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (isAppInstalled("com.anddoes.launcher")) {
Intent intent3 = new Intent("com.anddoes.launcher.SET_THEME");
intent3.putExtra("com.anddoes.launcher.THEME_PACKAGE_NAME", getActivity().getPackageName());
startActivity(intent3);
Crouton.makeText(getActivity(), "TAP APPLY TO FINALIZE", Style.INFO, (ViewGroup) getView()).show();
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.apexnotfound);
alert.setMessage(R.string.apexmarket);
alert.setIcon(R.drawable.apex_1);
alert.setPositiveButton((R.string.yes),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("market://details?id=com.anddoes.launcher"));
startActivity(intent);
}
});
alert.setNegativeButton((R.string.no),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
return;
}
});
alert.show();
}
}
});
And the xml for fragment_1
<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="#f9f9f9"
android:paddingBottom="15dp" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" android:scrollbars="none"
android:overScrollMode="never">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<!-- Action -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="40dp" >
<ImageButton
android:id="#+id/actiontheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/alp_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/actiontheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/action"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/actiondetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<ImageButton
android:id="#+id/apextheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/apex_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/apextheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/apex"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/apexdetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_apex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- Nova -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<ImageButton
android:id="#+id/novatheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/nova_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/novatheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/nova"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/novadetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_nova"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- Adw -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:paddingTop="15dp" >
<ImageButton
android:id="#+id/adwextheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/adwex_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adwextheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/adwex"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/adwexdetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_adwex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
<!-- go -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:paddingTop="15dp" >
<ImageButton
android:id="#+id/gotheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#drawable/btn_default_holo_dark"
android:paddingBottom="15dp"
android:src="#drawable/go_1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gotheme"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/go"
android:textSize="24dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:fontFamily="sans-serif-light"
android:text="#string/godetails"
android:textSize="18sp" />
<Button
android:id="#+id/screens_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:alpha=".6"
android:background="#00000000"
android:text="PREVIEW"
android:textColor="#color/blue" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
EDIT: Here is the FragmentAdapter.java:
package com.arandompackage.jive;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.viewpagerindicator.IconPagerAdapter;
public class TestFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter{
protected static final String[] CONTENT = new String[] {
"This", "Is", "A", "Test"
};
private int mCount = 4;
public TestFragmentAdapter(FragmentManager fm) {
super(fm);
}
#Override
public int getIconResId(int index) {
// TODO Auto-generated method stub
return 0;
}
#Override
public Fragment getItem(int position) {
Fragment fragment = new Fragment1();
switch(position){
case 0:
fragment = new Fragment1();
break;
case 1:
fragment = new Fragment2();
break;
case 2:
fragment = new Fragment3();
break;
case 3:
fragment = new Fragment4();
break;
}
return fragment;
}
#Override
public int getCount() {
return mCount;
}
#Override
public CharSequence getPageTitle(int position){
String title = "";
switch(position){
case 0:
title = "LAUNCHERS";
break;
case 1:
title = "EXTRAS";
break;
case 2:
title = "CONTACT";
break;
case 3:
title = "HELP";
break;
}
return title;
}
public void setCount(int count){
if (count > 0 && count < 10){
mCount = count;
notifyDataSetChanged();
}
}
}
And the TestFragment:
package com.arandompackage.jive;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class TestFragment extends Fragment{
private static final String KEY_CONTENT = "TestFragment:Content";
public static TestFragment newInstance(String content){
TestFragment fragment = new TestFragment();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 20; i++){
builder.append(content).append(" ");
}
builder.deleteCharAt(builder.length() -1);
fragment.mContent = builder.toString();
return fragment;
}
private String mContent = "???";
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)){
mContent = savedInstanceState.getString(KEY_CONTENT);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
TextView text = new TextView(getActivity());
text.setGravity(Gravity.CENTER);
text.setText(mContent);
text.setTextSize(20 * getResources().getDisplayMetrics().density);
text.setPadding(20, 20, 20, 20);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(text);
return layout;
}
public void onSavedInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
outState.putString(KEY_CONTENT, mContent);
}
}
Here's the twist, the theme still gets applied to Apex Launcher....Any help is much appreciated in advance!

I can't remember my exact answer but this could well be to do with exporting of libraries. Go to project, properties, build path, order and export. The correct order is src, gen, android x.x.x, android private libraries, private libraries. Play around with checking/unchecking them.
I will update the answer when I get home
Edit:
My other SO answer can be found here:
Unfortunately Google Maps API Demos has stopped - Google Maps Android API v2

Related

Invoking findViewById on a null object. Which isn't null

So I have a settings fragment which contains, well, settings.
On line 22 I have a findview which finds a textview. It worked wonders until today (Didn't change a thing). Now I imagine it will also fail the rest of the finds but since it crashes on this one, we will never know.
Why is that?
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">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#a8a4a1"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="ACCOUNT"
android:textColor="#2b2a29"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/SettingsFragmentAccountSettings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Account Settings"
android:textColor="#2b2a29"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="#a8a4a1"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="THEME"
android:textColor="#color/black"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/SettingsFragmentAccountSettings" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Dark Mode"
android:textColor="#color/black"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<Switch
android:id="#+id/SettingsFragmentDarkModeSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:scaleX="1.25"
android:scaleY="1.25"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.94"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/SettingsFragmentAccountSettings" />
<TextView
android:id="#+id/r"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#a8a4a1"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="OTHER"
android:textColor="#color/black"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/SettingsFragmentDarkModeSwitch" />
<TextView
android:id="#+id/SettingsFragmentFAQ"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="FAQ"
android:textColor="#color/black"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/r" />
<TextView
android:id="#+id/SettingsFragmentSupport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Support"
android:textColor="#color/black"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/SettingsFragmentFAQ" />
<TextView
android:id="#+id/SettingsFragmentPolicy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Content Policy & EULA"
android:textColor="#color/black"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/SettingsFragmentSupport" />
<TextView
android:id="#+id/SettingsFragmentUSerAgreement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="User Agreement"
android:textColor="#color/black"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/SettingsFragmentPolicy" />
<TextView
android:id="#+id/SettingsFragmentBugReport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Report A Bug"
android:textColor="#color/black"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/SettingsFragmentUSerAgreement" />
<TextView
android:id="#+id/Build"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#a8a4a1"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="BUILD INFORMATION"
android:textColor="#color/black"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/SettingsFragmentBugReport" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="1.0.0"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.042"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/Build" />
</androidx.constraintlayout.widget.ConstraintLayout>
The fragment code:
package com.example.create4me;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public class Settings extends Fragment {
TextView accSettings, FAQ, BugReport, Policy, UserAgg, Support;
Switch darkModeSwitch;
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState){
accSettings = (TextView) getView().findViewById(R.id.SettingsFragmentAccountSettings); <--- This one
FAQ = (TextView) getView().findViewById(R.id.SettingsFragmentFAQ);
BugReport = (TextView) getView().findViewById(R.id.SettingsFragmentBugReport);
Policy = (TextView) getView().findViewById(R.id.SettingsFragmentPolicy);
UserAgg = (TextView) getView().findViewById(R.id.SettingsFragmentUSerAgreement);
Support = (TextView) getView().findViewById(R.id.SettingsFragmentSupport);
darkModeSwitch = (Switch) getView().findViewById(R.id.SettingsFragmentDarkModeSwitch);
accSettings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), AccountSettings.class);
startActivity(intent);
}
});
BugReport.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), BugReport.class);
startActivity(intent);
}
});
FAQ.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDiag();
}
});
Policy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDiag();
}
});
UserAgg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDiag();
}
});
Support.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDiag();
}
});
darkModeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
/*
In here, put 0 into MySqli DB if the isChecked value = False.
Put 1 into MySqli DB if the isChecked value = 1.
*/
}
});
return inflater.inflate(R.layout.settings, container, false);
}
void alertDiag(){
new AlertDialog.Builder(getContext())
.setTitle("Well here we are")
.setMessage("Normally, the user by now would've gone into a website explaining the content of the pressed TextView.\n"
+ "Since we do not have a website or a domain, we show this AlertDialog. Sorry for the turnout!")
.setNegativeButton(android.R.string.no, null)
.show();
}
}
You need to do on the first line of onCreateView:
View view = inflater.inflate(R.layout.settings, container, false);
Then do for each of your findViewById:
view.findViewById(R.id.your_view);
You're inflating the view last instead of first.
Then at the end of onCreateView():
return view;
Please try below way to initialize and return in your oncreateview
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState){
View view = inflater.inflate(R.layout.settings, container, false);
//Init all here like
accSettings = (TextView) view. findViewById(R.id.SettingsFragmentAccountSettings)
//and then return like
return view;
}
Hope it may help you

App bugged: ImageView doesn't appear

I don't understand why the app doesn't work when I launch it.
First of all, this is what I want:
Spaceship appears perfectly
And this is what appears when I launch the game:
Spaceship disappears!
I dont know what is wrong. I haven't an atribute which makes invisible the ImageView... Here is my code:
game_activity.xml (game design)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.spaceinvaders.GameActivity">
<ImageView
android:id="#+id/fondo_juego"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/fondo3" />
<ImageView
android:id="#+id/enemigo"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="#drawable/enemigodiseno11"/>
<Button
android:id="#+id/disparo"
android:layout_width="wrap_content"
android:layout_height="90dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:onClick="dispara"
android:visibility="visible" />
<ImageView
android:id="#+id/municion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/disparo"
android:layout_centerHorizontal="true"
android:src="#drawable/municion"
android:visibility="invisible" />
<ImageView
android:id="#+id/nave"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="#drawable/diseno11" />
<Button
android:id="#+id/control_izquierda"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:onClick="actualizaPosicion"
android:visibility="visible" />
<Button
android:id="#+id/control_derecha"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:onClick="actualizaPosicion"
android:visibility="visible" />
</RelativeLayout>
activity_main.xml (This is the principal screen)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/principal_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.spaceinvaders.MainActivity">
<ImageView
android:id="#+id/fondo_pantalla_principal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/fondo2" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:adjustViewBounds="true"
android:src="#drawable/iconotitulo"
android:layout_centerHorizontal="true"/>
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/iconotitulo1"/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<ImageButton
android:id="#+id/play_boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
android:onClick="iniciaJuego"
android:src="#drawable/boton1" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_margin="10dp">
<ImageButton
android:id="#+id/opcion_boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
android:src="#drawable/boton2" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
popup_activity.xml (a simple popup which allow the user to change some parameters)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#839ceaac"
android:orientation="vertical">
<ImageButton
android:id="#+id/volver_boton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="2dp"
android:layout_marginTop="3dp"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
android:src="#drawable/cerrar" />
<TextView
android:id="#+id/titulo_opciones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="6dp"
android:layout_marginTop="5dp"
android:text="Opciones gráficas"
android:textSize="20dp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#id/titulo_opciones"
android:background="#9dc8a6" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/titulo_opciones"
android:layout_marginBottom="8dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/fondo_titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Fondo"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/fondo_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/fondo_titulo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaFondo"
android:scaleType="centerCrop"
android:src="#drawable/fondo" />
<ImageView
android:id="#+id/fondo_2"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/fondo_1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaFondo"
android:scaleType="centerCrop"
android:src="#drawable/fondo1" />
<ImageView
android:id="#+id/fondo_3"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/fondo_2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaFondo"
android:scaleType="centerCrop"
android:src="#drawable/fondo3" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/nave_titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Nave"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/nave_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/nave_titulo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaNave"
android:src="#drawable/diseno11" />
<ImageView
android:id="#+id/nave_2"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/nave_1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaNave"
android:src="#drawable/diseno21" />
<ImageView
android:id="#+id/nave_3"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/nave_2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaNave"
android:src="#drawable/diseno31" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/enemigos_titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Enemigos"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/enemigo_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/enemigos_titulo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaEnemigo"
android:rotation="180"
android:src="#drawable/enemigodiseno11" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
GameActivity.java (game_activity.xml functionality)
package com.example.android.spaceinvaders;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class GameActivity extends AppCompatActivity {
ImageView municion;
ImageView nave;
ImageView fondoJuego;
ImageView enemigo;
Button botonDisparo;
Handler manejaDisparo = new Handler();
Handler manejaEnemigo = new Handler();
final int movimiento = 30;
final int movimientoEnemigo = 20;
boolean inicioAFin = false;
int ladeadoIzq, ladeadoDer, frontal, disparo;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game_activity);
municion = (ImageView) findViewById(R.id.municion);
nave = (ImageView) findViewById(R.id.nave);
enemigo = (ImageView) findViewById(R.id.enemigo);
fondoJuego = (ImageView) findViewById(R.id.fondo_juego);
botonDisparo = (Button) findViewById(R.id.disparo);
Intent i = getIntent();
if (i != null) {
String data = i.getStringExtra("arg");
introduceCambios(data);
}
manejaEnemigo.postDelayed(accionMovimiento, 0);
}
private void introduceCambios(String data) {
String[] info = data.split(" ");
int idFondo = getResources().getIdentifier(info[0], "drawable", getPackageName());
fondoJuego.setImageResource(idFondo);
int idNave = getResources().getIdentifier(info[1], "drawable", getPackageName());
cambiosMovilidad(idNave);
nave.setImageResource(frontal);
int idEnemigo = getResources().getIdentifier(info[2], "drawable", getPackageName());
enemigo.setImageResource(idEnemigo);
}
public void actualizaPosicion(View v) {
switch (v.getId()) {
case (R.id.control_derecha):
if (!seSale("der", "CU")) {
nave.setImageResource(ladeadoIzq);
nave.setX(nave.getX() - movimiento);
}
break;
case R.id.control_izquierda:
if (!seSale("izq", "CU")) {
nave.setImageResource(ladeadoDer);
nave.setX(nave.getX() + movimiento);
}
break;
}
}
private void cambiosMovilidad(int idNave) {
switch (idNave) {
case 2130837589:
frontal = R.drawable.diseno11;
ladeadoDer = R.drawable.diseno13;
ladeadoIzq = R.drawable.diseno12;
disparo = R.drawable.municion;
break;
case 2130837592:
frontal = R.drawable.diseno21;
ladeadoDer = R.drawable.diseno23;
ladeadoIzq = R.drawable.diseno22;
disparo = R.drawable.municion1;
break;
case 2130837595:
frontal = R.drawable.diseno31;
ladeadoDer = R.drawable.diseno33;
ladeadoIzq = R.drawable.diseno32;
break;
}
}
public void dispara(View v) {
nave.setImageResource(frontal);
municion.setImageResource(disparo);
municion.setX(nave.getX() + (((nave.getWidth()) / 2) - 5));
municion.setY(nave.getY());
municion.setVisibility(View.VISIBLE);
botonDisparo.setEnabled(false);
manejaDisparo.postDelayed(accionDisparo, 0);
}
Runnable accionDisparo = new Runnable() {
#Override
public void run() {
municion.setY(municion.getY() - 50);
if (llegaAlFinal()) {
municion.setVisibility(View.INVISIBLE);
manejaDisparo.removeCallbacks(accionDisparo);
botonDisparo.setEnabled(true);
}
manejaDisparo.postDelayed(this, 80);
}
};
Runnable accionMovimiento = new Runnable() {
#Override
public void run() {
if (inicioAFin) {
enemigo.setImageResource(R.drawable.enemigodiseno12);
enemigo.setX(enemigo.getX() + movimientoEnemigo);
} else {
enemigo.setImageResource(R.drawable.enemigodiseno13);
enemigo.setX(enemigo.getX() - movimientoEnemigo);
}
if (seSale("izq", "IA") || seSale("der", "IA"))
inicioAFin = !inicioAFin;
manejaEnemigo.postDelayed(this, 80);
}
};
private boolean llegaAlFinal() {
return municion.getY() <= 20;
}
private boolean seSale(String direccion, String jugador) {
switch (direccion) {
case "izq":
switch (jugador) {
case "CU":
return (nave.getX() + movimiento + nave.getWidth()) > findViewById(R.id.activity_main).getWidth();
case "IA":
return (enemigo.getX() + movimiento + enemigo.getWidth()) > findViewById(R.id.activity_main).getWidth();
}
case "der":
switch (jugador) {
case "CU":
return (nave.getX() - movimiento) < 0;
case "IA":
return (enemigo.getX() - movimiento) < 0;
}
}
return true;
}
}
MainActivity.java (activity_main.xml and popup_activity.xml functionality)
package com.example.android.spaceinvaders;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
ImageButton opcionBoton;
private PopupWindow popup;
private RelativeLayout layoutPrincipal;
String[] resultados;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultados = new String[3];
resultados[0] = "fondo3";
resultados[1] = "diseno11";
resultados[2] = "enemigodiseno11";
opcionBoton = (ImageButton) findViewById(R.id.opcion_boton);
layoutPrincipal = (RelativeLayout) findViewById(R.id.principal_screen);
opcionBoton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View vistaPopup = inflater.inflate(R.layout.popup_activity, null);
popup = new PopupWindow(
vistaPopup,
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
ImageButton cerrarPop = (ImageButton) vistaPopup.findViewById(R.id.volver_boton);
cerrarPop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
popup.dismiss();
opcionBoton.setVisibility(View.VISIBLE);
}
});
popup.showAtLocation(layoutPrincipal, Gravity.BOTTOM, 0, 0);
opcionBoton.setVisibility(View.INVISIBLE);
}
});
}
public void iniciaJuego(View view) {
Intent juego = new Intent(view.getContext(), GameActivity.class);
juego.putExtra("arg", resultados[0] + " " + resultados[1] + " " + resultados[2]);
startActivity(juego);
}
public void actualizaFondo(View vista) {
switch (vista.getId()) {
case R.id.fondo_1:
resultados[0] = "fondo";
break;
case R.id.fondo_2:
resultados[0] = "fondo1";
break;
case R.id.fondo_3:
resultados[0] = "fondo3";
break;
}
}
public void actualizaNave(View vista) {
switch (vista.getId()) {
case R.id.nave_1:
resultados[1] = "diseno11";
break;
case R.id.nave_2:
resultados[1] = "diseno21";
break;
case R.id.nave_3:
resultados[1] = "diseno31";
break;
}
}
public void actualizaEnemigo(View vista) {
switch (vista.getId()) {
case R.id.enemigo_1:
resultados[2] = "enemigodiseno11";
break;
}
}
}
I hope you could help me, please... I don't know where is the error.
The project repository is: github.com/cvazquezlos/Space-Invaders-Android
Thank you so much!

How to open a browser through a Relative Layout

I have tried following 2 different links with no success.
https://stackoverflow.com/questions/3536165/how-can-imageview-link-to-web-page
and
https://stackoverflow.com/questions/3505788/how-to-open-default-browser/3505804#3505804
I do apologize if this is a simple fix but i'm that nooby and getting frustrated because according to those examples it should work.
Here is my Xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:layout_marginTop="5sp"
android:background="#color/grey"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="5sp" >
<ImageView
android:id="#+id/logo_about"
android:layout_width="85dp"
android:layout_height="105dp"
android:layout_gravity="center_vertical"
android:layout_weight="0.11"
android:src="#drawable/web_icon" />
</LinearLayout>
<TextView
android:id="#+id/tv_content_about"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:layout_marginTop="5sp"
android:background="#color/grey"
android:gravity="center_horizontal"
android:padding="5sp"
android:text="#string/info_about_us"
android:textColor="#color/black"
android:textSize="15sp" />
<!-- Contact Us -->
<RelativeLayout
android:id="#+id/contact"
android:clickable="true"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="50sp"
android:background="#drawable/btn_bg" >
<ImageView
android:id="#+id/img_icon"
android:clickable="true"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_centerVertical="true"
android:layout_marginLeft="5sp"
android:scaleType="fitXY"
android:src="#drawable/icon_email" />
<TextView
android:id="#+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/img_icon"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:layout_toLeftOf="#+id/img_indicator"
android:layout_toRightOf="#+id/img_icon"
android:singleLine="true"
android:text="#string/title_contact_us"
android:textColor="#color/black"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_name"
android:layout_alignRight="#+id/tv_name"
android:layout_below="#+id/tv_name"
android:singleLine="true"
android:text="#string/info_contact_us"
android:textColor="#color/black"
android:textSize="13sp" />
<ImageView
android:id="#+id/img_indicator"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5sp"
android:src="#drawable/ic_action_next_item" />
<View
android:id="#+id/devider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#color/grey" />
</RelativeLayout>
<!-- Facebook -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50sp"
android:clickable="true"
android:background="#drawable/btn_bg" >
<ImageView
android:id="#+id/facebook_icon"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_centerVertical="true"
android:layout_marginLeft="5sp"
android:scaleType="fitXY"
android:src="#drawable/icon_facebook" />
<TextView
android:id="#+id/tv_name1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/facebook_icon"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:layout_toLeftOf="#+id/facebook_icon"
android:layout_toRightOf="#+id/facebook_icon"
android:singleLine="true"
android:text="#string/title_facebook"
android:textColor="#color/black"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_content1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_name1"
android:layout_alignRight="#+id/tv_name1"
android:layout_below="#+id/tv_name1"
android:singleLine="true"
android:text="#string/info_facebook"
android:textColor="#color/black"
android:textSize="13sp" />
<ImageView
android:id="#+id/img_indicator1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5sp"
android:src="#drawable/ic_action_next_item" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#color/grey" />
</RelativeLayout>
<!-- Google Plus -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50sp"
android:clickable="true"
android:background="#drawable/btn_bg" >
<ImageView
android:id="#+id/google_icon"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_centerVertical="true"
android:layout_marginLeft="5sp"
android:scaleType="fitXY"
android:src="#drawable/icon_googleplus" />
<TextView
android:id="#+id/tv_name2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/google_icon"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:layout_toLeftOf="#+id/google_icon"
android:layout_toRightOf="#+id/google_icon"
android:singleLine="true"
android:text="#string/title_google_plus"
android:textColor="#color/black"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_content2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_name2"
android:layout_alignRight="#+id/tv_name2"
android:layout_below="#+id/tv_name2"
android:singleLine="true"
android:text="#string/info_google_plus"
android:textColor="#color/black"
android:textSize="13sp" />
<ImageView
android:id="#+id/img_indicator2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5sp"
android:src="#drawable/ic_action_next_item" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#color/grey" />
</RelativeLayout>
<!-- Website -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50sp"
android:background="#drawable/btn_bg" >
<ImageView
android:id="#+id/website_icon"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_centerVertical="true"
android:layout_marginLeft="5sp"
android:scaleType="fitXY"
android:src="#drawable/icon_website" />
<TextView
android:id="#+id/tv_name3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/website_icon"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:layout_toLeftOf="#+id/img_indicator3"
android:layout_toRightOf="#+id/website_icon"
android:singleLine="true"
android:text="#string/title_website"
android:textColor="#color/black"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_content3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_name3"
android:layout_alignRight="#+id/tv_name3"
android:layout_below="#+id/tv_name3"
android:singleLine="true"
android:text="#string/info_website"
android:textColor="#color/black"
android:textSize="13sp" />
<ImageView
android:id="#+id/img_indicator3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5sp"
android:src="#drawable/ic_action_next_item" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#color/grey" />
</RelativeLayout>
<!-- Rate Us -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50sp"
android:background="#drawable/btn_bg" >
<ImageView
android:id="#+id/rate_icon"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_centerVertical="true"
android:layout_marginLeft="5sp"
android:scaleType="fitXY"
android:src="#drawable/icon_rate_me" />
<TextView
android:id="#+id/tv_name4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/rate_icon"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:layout_toLeftOf="#+id/img_indicator4"
android:layout_toRightOf="#+id/rate_icon"
android:singleLine="true"
android:text="#string/title_rate_us"
android:textColor="#color/black"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_content4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_name4"
android:layout_alignRight="#+id/tv_name4"
android:layout_below="#+id/tv_name4"
android:singleLine="true"
android:text="#string/info_rate_us"
android:textColor="#color/black"
android:textSize="13sp" />
<ImageView
android:id="#+id/img_indicator4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5sp"
android:src="#drawable/ic_action_next_item" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#color/grey" />
</RelativeLayout>
<!-- More Apps -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50sp"
android:background="#drawable/btn_bg" >
<ImageView
android:id="#+id/apps_icon"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_centerVertical="true"
android:layout_marginLeft="5sp"
android:scaleType="fitXY"
android:src="#drawable/icon_more_app" />
<TextView
android:id="#+id/tv_name5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/apps_icon"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:layout_toLeftOf="#+id/img_indicator5"
android:layout_toRightOf="#+id/apps_icon"
android:singleLine="true"
android:text="#string/title_more_app"
android:textColor="#color/black"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_content5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_name5"
android:layout_alignRight="#+id/tv_name5"
android:layout_below="#+id/tv_name5"
android:singleLine="true"
android:text="#string/info_more_app"
android:textColor="#color/black"
android:textSize="13sp" />
<ImageView
android:id="#+id/img_indicator5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5sp"
android:src="#drawable/ic_action_next_item" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#color/grey" />
</RelativeLayout>
</LinearLayout>
Now my Fragment.java
package com.wny.wecare.fragment;
import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.wny.wecare.R;
public class AboutUsFragment extends Fragment implements OnClickListener {
public static final String TAG = AboutUsFragment.class.getSimpleName();
private View mRootView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_about_us, container, false);
return mRootView;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView Img = (ImageView) getView().findViewById(R.id.img_indicator);
Img.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://infinitycodeservices.com")));
}
});
}
}
do this rather bro
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView Img = (ImageView) getView().findViewById(R.id.img_indicator);
if(v == img)
Context.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://infinitycodeservices.com"))); //context stands 4 ur activity
}
Edit 1: i change the intent to Intent this was the reason for the earlier variable error..
so retry & seee
let me know if it works.. im feeling i left something.
According to my understanding, your public void onClick(View v) not called you just declare but don't set Listener,then when you set listener to ImageView on onClick() that never call too.
I think you should setListener() in onCreateView() by using anonymous inner class like this
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_about_us, container, false);
ImageView Img = (ImageView) getView().findViewById(R.id.img_indicator);
Img.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://infinitycodeservices.com")));
}
});
return mRootView;
}
or If you still use implement View.OnClickListener() use this
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_about_us, container, false);
ImageView Img = (ImageView) getView().findViewById(R.id.img_indicator);
Img.setOnClickListener(this);
return mRootView;
}
#Override
public void onClick(View v) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://infinitycodeservices.com")));
}
Hope this helps
After Hours of reading i finally solved this issue.
Thanks to this link Correct way to call onClickListener on fragments
Thank You all for your help, very appreciated.
Here is my full AboutUsFragment.Java
package com.wny.wecare.fragment;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import com.wny.wecare.MainActivity;
import com.wny.wecare.R;
public class AboutUsFragment extends Fragment implements OnClickListener {
ImageView Contact;
ImageView Facebook;
ImageView Google;
ImageView Website;
ImageView Rate;
ImageView Apps;
public static final String TAG = AboutUsFragment.class.getSimpleName();
private View mRootView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mRoot = inflater.inflate(R.layout.fragment_about_us, null);
Contact = (ImageView) mRoot.findViewById(R.id.contact_icon);
Contact.setOnClickListener(this);
Facebook = (ImageView) mRoot.findViewById(R.id.facebook_icon);
Facebook.setOnClickListener(this);
Google = (ImageView) mRoot.findViewById(R.id.google_icon);
Google.setOnClickListener(this);
Website = (ImageView) mRoot.findViewById(R.id.website_icon);
Website.setOnClickListener(this);
Rate = (ImageView) mRoot.findViewById(R.id.rate_icon);
Rate.setOnClickListener(this);
Apps = (ImageView) mRoot.findViewById(R.id.apps_icon);
Apps.setOnClickListener(this);
return mRoot;
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.contact_icon:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:infinitycodeservices#gmail.com")));
break;
case R.id.facebook_icon:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://facebook.com/infinitycodeservices")));
break;
case R.id.google_icon:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/105796163192090141980/")));
break;
case R.id.website_icon:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://infinitycodeservices.com")));
break;
case R.id.rate_icon:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=InfinityCodeServices")));
break;
case R.id.apps_icon:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=InfinityCodeServices")));
break;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
Intent intent;
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
String cameback="CameBack";
intent = new Intent(getActivity(), MainActivity.class);
intent.putExtra("Comingback", cameback);
startActivity(intent);
return true;
}
return false;
}
}
You are in a Fragment so I think you should invoke startActivity() method using:
getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://infinitycodeservices.com")));

java.lang.NullPointerException on my app

I use Android Studio, it's my very first time developing for android
and also java language!
So, upon building my project and running it on my own phone, it crashes when
I enter a second activity.
This is the xml of the activity I try to open.:(activity_infomenu.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:id="#+id/fullscreen_content"
android:background="#ff282bff"
android:fitsSystemWindows="true"
android:keepScreenOn="true"
android:gravity="center"
tools:context="com.luiscesjr.aquariodebolso.aquariodebolso.infomenu">
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button7"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/calendar128"
/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button8"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/button11"
android:layout_alignStart="#+id/button11"
android:src="#drawable/fish128"/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button9"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/button12"
android:layout_alignStart="#+id/button12"
android:src="#drawable/clown_fish128"/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button10"
android:layout_marginTop="102dp"
android:layout_below="#+id/button7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/ruler128"/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button11"
android:layout_alignTop="#+id/button10"
android:layout_centerHorizontal="true"
android:src="#drawable/ruler128"/>
<ImageButton
android:layout_width="120dp"
android:layout_height="150dp"
android:id="#+id/button12"
android:layout_alignTop="#+id/button11"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#drawable/ruler128"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Calendário"
android:id="#+id/textView"
android:layout_below="#+id/button7"
android:layout_alignRight="#+id/textView4"
android:layout_alignEnd="#+id/textView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Aqua Doce"
android:id="#+id/textView2"
android:layout_below="#+id/button8"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Aqua Marinho"
android:id="#+id/textView3"
android:layout_below="#+id/button9"
android:layout_alignLeft="#+id/button9"
android:layout_alignStart="#+id/button9" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Ferramentas"
android:id="#+id/textView4"
android:layout_below="#+id/button10"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView5"
android:layout_below="#+id/button11"
android:layout_alignRight="#+id/button11"
android:layout_alignEnd="#+id/button11" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView6"
android:layout_below="#+id/button12"
android:layout_alignLeft="#+id/button12"
android:layout_alignStart="#+id/button12" />
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
</RelativeLayout>
The Code.: (infomenu.java)
(This is the auto generated activity with fullscreen form the Android Studio.)
package com.luiscesjr.aquariodebolso.aquariodebolso;
import com.luiscesjr.aquariodebolso.aquariodebolso.util.SystemUiHider;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.graphics.drawable.AnimationDrawable;
public class infomenu extends Activity {
private static final boolean AUTO_HIDE = true;
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
private static final boolean TOGGLE_ON_CLICK = true;
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
private SystemUiHider mSystemUiHider;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_infomenu);
setupActionBar();
final View controlsView = findViewById(R.id.fullscreen_content_controls);
final View contentView = findViewById(R.id.fullscreen_content);
mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
mSystemUiHider.setup();
mSystemUiHider
.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
// Cached values.
int mControlsHeight;
int mShortAnimTime;
#Override
#TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void onVisibilityChange(boolean visible) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
if (mControlsHeight == ) {
// LINE 83 HERE mControlsHeight = controlsView.getHeight();
}
if (mShortAnimTime == 0) {
mShortAnimTime = getResources().getInteger(
android.R.integer.config_shortAnimTime);
}
controlsView.animate()
.translationY(visible ? 0 : mControlsHeight)
.setDuration(mShortAnimTime);
} else {
controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
}
if (visible) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
}
});
contentView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (TOGGLE_ON_CLICK) {
mSystemUiHider.toggle();
} else {
mSystemUiHider.show();
}
}
});
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
delayedHide(100);
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
Handler mHideHandler = new Handler();
Runnable mHideRunnable = new Runnable() {
#Override
public void run() {
mSystemUiHider.hide();
}
};
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}
And here is the Error.:
05-20 22:48:24.737 18794-18794/com.luiscesjr.aquariodebolso.aquariodebolso E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.luiscesjr.aquariodebolso.aquariodebolso.infomenu$1.onVisibilityChange(infomenu.java:83)
at com.luiscesjr.aquariodebolso.aquariodebolso.util.SystemUiHiderHoneycomb$1.onSystemUiVisibilityChange(SystemUiHiderHoneycomb.java:112)
at android.view.View.dispatchSystemUiVisibilityChanged(View.java:15933)
at android.view.ViewGroup.dispatchSystemUiVisibilityChanged(ViewGroup.java:1412)
at android.view.ViewGroup.dispatchSystemUiVisibilityChanged(ViewGroup.java:1418)
at android.view.ViewGroup.dispatchSystemUiVisibilityChanged(ViewGroup.java:1418)
at android.view.ViewGroup.dispatchSystemUiVisibilityChanged(ViewGroup.java:1418)
at android.view.ViewRootImpl.handleDispatchSystemUiVisibilityChanged(ViewRootImpl.java:3777)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2966)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
05-20 22:48:26.417 18794-18794/com.luiscesjr.aquariodebolso.aquariodebolso I/Process﹕ Sending signal. PID: 18794 SIG: 9
What am I missing here?
Oh and please, don't mind the idiotic name of the app.
Edit.: Won't have the error anymore since I added this.:
<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:background="#ff282bff"
android:fitsSystemWindows="true"
android:keepScreenOn="true"
android:gravity="center"
tools:context="com.luiscesjr.aquariodebolso.aquariodebolso.infomenu"
android:id="#+id/fullscreen_content_controls">
<View //Without this it will still crash, but it also bugs the activity
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fullscreen_content">
</View>
But now the code won't work properly.
You are setting controlsView value to this
final View controlsView = findViewById(R.id.fullscreen_content_controls);
but fullscreen_content_controls is not present in your layout
Add your Required view to your layout because your given layout does not contains any thing like fullscreen_content_controls, So it is throwing NPE

gps wont work if it is not on the main startup page

i am making an android app that uses the gps to mark you lat/long, speed etc but when i try to change the fields the app nolonger loads up, any ideas why? the first page to load up is MainActivity.java but this is just a logo screen that loads the app then uses
setContentView(R.layout.main_page);
to load the MainPageActivity.Java that i will be using to do most of the app stuff here is the code for that
here is the code for MainActivity.Java:
package com.aramis;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity implements Runnable {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
setContentView(R.layout.main_page);
}
}.start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void run() {
// TODO Auto-generated method stub
}
public void GoToMap(View view) {
setContentView(R.layout.map);
}
public void GoToOpt(View view) {
setContentView(R.layout.options);
}
public void GoToStart(View view) {
setContentView(R.layout.main_page);
}
}
and here is the code for MainPageActivity.Java:
package com.aramis;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainPageActivity extends Activity {
/** Called when the activity is first created. */
EditText et_gpsLAT;
EditText et_gpsLONG;
ProgressDialog progressDialog;
Thread thread;
String info;
LocationManager mlocManager=null;
LocationListener mlocListener;
AlertDialog.Builder alert;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
et_gpsLAT=(EditText)findViewById(R.id.et_gpsLAT);
et_gpsLONG=(EditText)findViewById(R.id.et_gpsLONG);
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
Button btn_gps=(Button)findViewById(R.id.btn_gps);
btn_gps.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
if(MyLocationListener.latitude>0 )
{
et_gpsLAT.setText("Latitude: "
+ MyLocationListener.latitude
+ '\n');
et_gpsLONG.setText("Longitude: "
+ MyLocationListener.longitude);
}
}
}
}
);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_page, menu);
return true;
}
}
and here is a copy of the page that will display the lat/long:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/backrepeat"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="#string/LatENG"
tools:context=".MainActivity" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:text="#string/Long"
tools:context=".MainActivity" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="20dp"
android:text="#string/Alt"
tools:context=".MainActivity" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginTop="20dp"
android:text="#string/Speed"
tools:context=".MainActivity" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_marginRight="21dp"
android:text="#string/Current_Lat"
tools:context=".MainActivity" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignRight="#+id/TextView02"
android:text="#string/Current_Long"
tools:context=".MainActivity" />
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView4"
android:layout_alignRight="#+id/TextView01"
android:text="#string/Current_Alt"
tools:context=".MainActivity" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_alignRight="#+id/TextView03"
android:text="#string/Current_Speed"
tools:context=".MainActivity" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="GoToMap"
android:text="#string/mapbtn" />
<Button
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="GoToOpt"
android:text="#string/optbtn" />
<Button
android:id="#+id/btn_gps"
style="#style/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView5"
android:layout_marginTop="33dp"
android:text=" GPS " />
<EditText
android:id="#+id/et_gpsLAT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn_gps"
android:layout_centerHorizontal="true"
android:editable="false"
android:ems="10" />
<EditText
android:id="#+id/et_gpsLONG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/et_gpsLAT"
android:layout_below="#+id/et_gpsLAT"
android:editable="false"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/tv_gps"
style="#style/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btn_gps"
android:layout_alignParentLeft="true"
android:text="Location :" />
</RelativeLayout>
any help with this would be apreciated i have been stuck on this for a while now

Categories

Resources