This error has appeared on this forum millions of time but I really could not find the answer to resolve this error! I am using Navigation drawer with fragments, so far I have incorporated(I think I have) a countdown timer and a google map. I don't know what the problem is I have tried "almost" every solution mentioned on the internet for this error.
ERROR:
01-26 15:10:47.923: E/AndroidRuntime(3731): FATAL EXCEPTION: main
01-26 15:10:47.923: E/AndroidRuntime(3731): Process: com.example.TheWeddingApp, PID: 3731
01-26 15:10:47.923: E/AndroidRuntime(3731): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.TheWeddingApp/com.example.TheWeddingApp.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.navigationdrawer.FragmentOne: make sure class name exists, is public, and has an empty constructor that is public
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.app.ActivityThread.access$800(ActivityThread.java:139)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.os.Handler.dispatchMessage(Handler.java:102)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.os.Looper.loop(Looper.java:136)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.app.ActivityThread.main(ActivityThread.java:5086)
01-26 15:10:47.923: E/AndroidRuntime(3731): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 15:10:47.923: E/AndroidRuntime(3731): at java.lang.reflect.Method.invoke(Method.java:515)
01-26 15:10:47.923: E/AndroidRuntime(3731): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
01-26 15:10:47.923: E/AndroidRuntime(3731): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
01-26 15:10:47.923: E/AndroidRuntime(3731): at dalvik.system.NativeStart.main(Native Method)
01-26 15:10:47.923: E/AndroidRuntime(3731): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.navigationdrawer.FragmentOne: make sure class name exists, is public, and has an empty constructor that is public
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
01-26 15:10:47.923: E/AndroidRuntime(3731): at com.example.TheWeddingApp.MainActivity.onCreate(MainActivity.java:54)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.app.Activity.performCreate(Activity.java:5248)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
01-26 15:10:47.923: E/AndroidRuntime(3731): ... 11 more
01-26 15:10:47.923: E/AndroidRuntime(3731): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.navigationdrawer.FragmentOne" on path: DexPathList[[zip file "/mnt/asec/com.example.TheWeddingApp-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/com.example.TheWeddingApp-1/lib, /vendor/lib, /system/lib]]
01-26 15:10:47.923: E/AndroidRuntime(3731): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-26 15:10:47.923: E/AndroidRuntime(3731): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
01-26 15:10:47.923: E/AndroidRuntime(3731): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
01-26 15:10:47.923: E/AndroidRuntime(3731): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
01-26 15:10:47.923: E/AndroidRuntime(3731): ... 16 more
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.TheWeddingApp"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.TheWeddingApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.TheWeddingApp.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.TheWeddingApp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBTbyjkzYDeEFGsljSoLBr54riAjhWCVJg" />
</application>
</manifest>
MainActivity.java
package com.example.TheWeddingApp;
import android.app.ActionBar;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends FragmentActivity {
final String[] data ={"Home","Venue","Gallery","Meet the Groom","Meet `the Bride"};`
final String[] fragments ={
"com.example.navigationdrawer.FragmentOne",
"com.example.navigationdrawer.FragmentTwo",
"com.example.navigationdrawer.FragmentThree",
"com.example.navigationdrawer.FragmentFour",
"com.example.navigationdrawer.FragmentFive"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, data);
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
final ListView navList = (ListView) findViewById(R.id.drawer);
navList.setAdapter(adapter);
navList.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view, final int pos,long id){
drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
#Override
public void onDrawerClosed(View drawerView){
super.onDrawerClosed(drawerView);
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.main, Fragment.instantiate(MainActivity.this, fragments[pos]));
tx.commit();
}
});
drawer.closeDrawer(navList);
}
});
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.main,Fragment.instantiate(MainActivity.this, fragments[0]));
tx.commit();
}
}
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<FrameLayout
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<ListView
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ff0000"
android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>
FragmentOne.java
package com.example.TheWeddingApp;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public class FragmentOne extends Fragment {
private TextView tvDay, tvHour, tvMinute, tvSecond, tvEvent;
private LinearLayout linearLayout1, linearLayout2;
private Handler handler;
private Runnable runnable;
public static Fragment newInstance(Context context) {
FragmentOne f = new FragmentOne();
return f;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_one, null);
getActivity().setContentView(R.layout.fragment_one);
initUI();
countDownStart();
return root;
}
#SuppressLint("SimpleDateFormat")
private void initUI() {
linearLayout1 = (LinearLayout) getActivity().findViewById(R.id.ll1);
linearLayout2 = (LinearLayout) getActivity().findViewById(R.id.ll2);
tvDay = (TextView) getActivity().findViewById(R.id.txtTimerDay);
tvHour = (TextView) getActivity().findViewById(R.id.txtTimerHour);
tvMinute = (TextView) getActivity().findViewById(R.id.txtTimerMinute);
tvSecond = (TextView) getActivity().findViewById(R.id.txtTimerSecond);
tvEvent = (TextView) getActivity().findViewById(R.id.tvevent);
}
public void countDownStart() {
handler = new Handler();
runnable = new Runnable() {
#Override
public void run() {
handler.postDelayed(this, 1000);
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
// Here Set your Event Date
Date futureDate = dateFormat.parse("2016-2-19");
Date currentDate = new Date();
if (!currentDate.after(futureDate)) {
long diff = futureDate.getTime()
- currentDate.getTime();
long days = diff / (24 * 60 * 60 * 1000);
diff -= days * (24 * 60 * 60 * 1000);
long hours = diff / (60 * 60 * 1000);
diff -= hours * (60 * 60 * 1000);
long minutes = diff / (60 * 1000);
diff -= minutes * (60 * 1000);
long seconds = diff / 1000;
tvDay.setText("" + String.format("%02d", days));
tvHour.setText("" + String.format("%02d", hours));
tvMinute.setText("" + String.format("%02d", minutes));
tvSecond.setText("" + String.format("%02d", seconds));
} else {
linearLayout1.setVisibility(View.VISIBLE);
linearLayout2.setVisibility(View.GONE);
tvEvent.setText("Android Event Start");
handler.removeCallbacks(runnable);
// handler.removeMessages(0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
handler.postDelayed(runnable, 0);
}
}
fragment_one.xml
<?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:orientation="vertical" >
<LinearLayout
android:id="#+id/ll1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#000000"
android:gravity="center|center_horizontal|center_vertical"
android:orientation="horizontal"
android:visibility="gone" >
<TextView
android:id="#+id/tvevent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:singleLine="true"
android:text="Android Event Start"
android:textColor="#fff"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:background="#000000"
android:gravity="center|center_horizontal|center_vertical"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/txtTimerDay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
<TextView
android:id="#+id/txt_TimerDay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Days"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/txtTimerHour"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
<TextView
android:id="#+id/txt_TimerHour"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Hour"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/txtTimerMinute"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
<TextView
android:id="#+id/txt_TimerMinute"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Minute"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/txtTimerSecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
<TextView
android:id="#+id/txt_TimerSecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Second"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
FragmentTwo.java
package com.example.TheWeddingApp;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.content.Context;
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.Toast;
public class FragmentTwo extends Fragment {
private GoogleMap googleMap;
public static Fragment newInstance(Context context) {
FragmentTwo f = new FragmentTwo();
return f;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_two, null);
getActivity().setContentView(R.layout.fragment_two);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
return root;
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getActivity().getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
public void onResume() {
super.onResume();
initilizeMap();
}
}
fragment_two.xml
<?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:orientation="vertical" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
you are using
final String[] fragments ={
"com.example.navigationdrawer.FragmentOne",
"com.example.navigationdrawer.FragmentTwo",
"com.example.navigationdrawer.FragmentThree",
"com.example.navigationdrawer.FragmentFour",
"com.example.navigationdrawer.FragmentFive"};
to instantiate your Fragments in MainActivity. There you are providing the a full qualified path to your Fragments that, accordingly to the stacktrace, doesn't exits. The package of your Fragments is com.example.TheWeddingApp. You might what to change the String[] to reflect the real path. E.g.
final String[] fragments ={
"com.example.TheWeddingApp.FragmentOne",
"com.example.TheWeddingApp.FragmentTwo",
"com.example.TheWeddingApp.FragmentThree",
"com.example.TheWeddingApp.FragmentFour",
"com.example.TheWeddingApp.FragmentFive"};
Related
I'm a new Android developer working on the JustJava app on Udacity Beginners course. Using my phone to debug my code, when I clicked on the button to update price it gives the error: "Unfortunately JustJava has stopped".
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.justjava">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="justjava"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity.java
import android.icu.text.NumberFormat;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(2);
displayPrice(2 * 5);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView)
findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
/**
* *This method displays the given price on the screen.
*/
private void displayPrice(int number) {
TextView priceTextView = (TextView)
findViewById(R.id.price_text_view);
priceTextView.setText
(NumberFormat.getCurrencyInstance().format(number));
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context="com.example.android.justjava.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="quantity"
android:textAllCaps="true"
android:padding="16dp" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:textColor="#android:color/black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAllCaps="true"
android:padding="16dp" />
<TextView
android:id="#+id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NGN0"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:textColor="#android:color/black"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORDER"
android:layout_margin="16dp"
android:onClick="submitOrder"/>
</LinearLayout>
Logcat error:
04-25 09:22:04.944 449-449/com.example.android.justjava E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.android.justjava, PID: 449
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:4470)
at android.view.View$PerformClick.run(View.java:18773)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5341)
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:830)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:646)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4470)
at android.view.View$PerformClick.run(View.java:18773)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5341)
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:830)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:646)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: android.icu.text.NumberFormat
at com.example.android.justjava.MainActivity.displayPrice(MainActivity.java:49)
at com.example.android.justjava.MainActivity.submitOrder(MainActivity.java:33)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4470)
at android.view.View$PerformClick.run(View.java:18773)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5341)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
The error is rather specific. The root cause is at the end of the stacktrace :
Caused by: java.lang.NoClassDefFoundError: android.icu.text.NumberFormat
at com.example.android.justjava.MainActivity.displayPrice(MainActivity.java:49)
at com.example.android.justjava.MainActivity.submitOrder(MainActivity.java:33)
The classloader could have not found the android.icu.text.NumberFormat class definition you are using in your app.
You should check that the Android version installed on your phone is compatible with this class that is available only since the API 24 (Android 7.0).
https://developer.android.com/reference/android/icu/text/NumberFormat.html
I am attempting to concatenate strings in Android using two activities. Every time I enter two string and hit the button to run the app crashes on the emulator. Can you help me find what I am doing wrong here? My code and the error are below.
Main Activity (Activity 1)
package com.example.tristan.a1p1n1;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
public final static String EXTRA_MESSAGE = "com.example.tristan.a1p1n1.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
public void sendMessage(View view) {
Intent intent = new Intent(this, DICS.class);
EditText editText = (EditText) findViewById(R.id.editText);
EditText editText2 = (EditText) findViewById(R.id.editText2);
String message = editText.getText().toString() + editText2.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}}
DICS (Activity 2)
package com.example.tristan.a1p1n1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
/**
* Created by Tristan on 2/11/2017.
*/
public class DICS extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dics);
//TextView mTextView = (TextView)findViewById(R.id.textView2);
// mTextView.setText(getIntent().getStringExtra("message"))
}
}
My Error Message:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tristan.a1p1n1, PID: 3082
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.tristan.a1p1n1/com.example.tristan.a1p1n1.DICS}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
at android.app.Activity.startActivityForResult(Activity.java:4224)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4183)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4507)
at android.app.Activity.startActivity(Activity.java:4475)
at com.example.tristan.a1p1n1.MainActivity.sendMessage(MainActivity.java:41)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.tristan.a1p1n1.MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Enter a String"
android:ems="10"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Enter a String"
android:ems="10"
android:id="#+id/editText2"
android:layout_below="#+id/editText"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText"
android:layout_marginRight="11dp"
android:layout_marginEnd="11dp"
android:layout_marginTop="13dp" />
<Button
android:text="+"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="23dp"
android:id="#+id/button"
android:onClick="sendMessage" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tristan.a1p1n1">
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
dics.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView2" />
</LinearLayout>
your Button Xml should be:
<Button
android:text="+"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="23dp"
android:id="#+id/button"
android:onClick="sendMessage" /> //change here
Try this: in your MainActivity
String message = editText.getText().toString() + editText2.getText().toString();
intent.putExtra("message", message);
Now in Dics activity:
TextView mTextView = (TextView)findViewById(R.id.textView2);
mTextView.setText(getIntent().getStringExtra("message")); //the key ID should match
I am new to android. Here am trying to pass the radiobutton and Checkbox values from one activity to another activity. Its not showing any error but when I run it simply gets closed. Any help would be appreciated.Here I have posted the complete code..
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
public class MainActivity extends Activity {
Intent obj = new Intent(this, SecondActivity.class);
Bundle extras = new Bundle();
RadioButton male, female, single, married;
CheckBox twelveth, bE, mE;
String s1="+2";
String s2="B.E.";
String s3="M.E.";
StringBuilder s;
String str;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
male = (RadioButton) findViewById(R.id.male);
female = (RadioButton) findViewById(R.id.female);
single = (RadioButton) findViewById(R.id.single);
married = (RadioButton) findViewById(R.id.married);
twelveth = (CheckBox) findViewById(R.id.twelveth);
bE = (CheckBox) findViewById(R.id.BE);
mE = (CheckBox) findViewById(R.id.ME);
str=s.toString();
extras.putString("Education",str);
}
public void onGenderClicked(View v) {
boolean checked = ((RadioButton) v).isChecked();
switch (v.getId()) {
case R.id.male:
if (checked)
extras.putString("Gender", "Male");
break;
case R.id.female:
if (checked)
extras.putString("Gender", "Female");
break;
}
}
public void onStatusClicked(View v) {
boolean checked = ((RadioButton) v).isChecked();
switch (v.getId()) {
case R.id.single:
if (checked)
extras.putString("Status", "Single");
break;
case R.id.married:
if (checked)
extras.putString("Status", "Married");
break;
}
}
public void ButtonClick(View v) {
obj.putExtras(extras);
startActivity(obj);
}
public void onCheckBoxClicked(View v)
{
boolean checked=((CheckBox)v).isChecked();
switch(v.getId())
{
case R.id.twelveth:
if(checked)
{
s.append("\n"+s1);
}
break;
case R.id.BE:
if(checked)
{
s.append("\n"+s2);
}
break;
case R.id.ME:
if(checked)
{
s.append("\n"+s3);
}
break;
}
str=s.toString();
extras.putString("Education",str);
}
}
SecondActivity
package com.example.aravindpraveen.buttonsandboxes;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends Activity {
TextView tvGender,tvStatus,tvEducation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
tvGender=(TextView)findViewById(R.id.tvGender);
tvStatus=(TextView)findViewById(R.id.tvStatus);
tvEducation=(TextView)findViewById(R.id.tvEducation);
Intent obj1=getIntent();
Bundle extras=obj1.getExtras();
String gender=extras.getString("Gender");
String status=extras.getString("Starus");
String education=extras.getString("Education");
tvGender.setText(gender);
tvStatus.setText(status);
tvEducation.setText(education);
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aravindpraveen.buttonsandboxes" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#6457d962"
android:orientation="vertical">
<TextView android:text="#string/b_b"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="40sp"
android:background="#f62dd93c"
android:textColor="#c34c27e6"
android:gravity="center"/>
<Space
android:layout_width="match_parent"
android:layout_height="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/gender"
android:textSize="40sp"
android:gravity="center"
android:textColor="#000000"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rg_gender">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/male"
android:text="#string/male"
android:textSize="30sp"
android:checked="true"
android:onClick="onGenderClicked"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/female"
android:text="#string/female"
android:textSize="30sp"
android:onClick="onGenderClicked"/>
</RadioGroup>
<Space
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="#string/M_status"
android:textColor="#000000"
android:gravity="center"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rg_status">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/single"
android:text="#string/single"
android:textSize="30sp"
android:checked="true"
android:onClick="onStatusClicked"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/married"
android:text="#string/married"
android:textSize="30sp"
android:onClick="onStatusClicked"/>
</RadioGroup>
<Space
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="#string/education"
android:textColor="#000000"
android:gravity="center"
/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/twelveth"
android:textSize="30sp"
android:id="#+id/twelveth"
android:onClick="onCheckBoxClicked"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/bE"
android:textSize="30sp"
android:id="#+id/BE"
android:onClick="onCheckBoxClicked"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/mE"
android:textSize="30sp"
android:id="#+id/ME"
android:onClick="onCheckBoxClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/submit"
android:text="#string/submit"
android:layout_gravity="center"
android:onClick="ButtonClick"/>
</LinearLayout>
second.xml
<?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="#f4dbde"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:background="#fba1a1"
android:text="#string/heading"
android:gravity="center"
android:textColor="#ffffff"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/gender"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvGender"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/M_status"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvStatus"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/education"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvEducation"/>
</LinearLayout>
LogCat
02-03 11:39:42.859 1135-1135/com.example.aravindpraveen.buttonsandboxes D/AndroidRuntime﹕ Shutting down VM
02-03 11:39:42.863 1135-1135/com.example.aravindpraveen.buttonsandboxes W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4c2c648)
02-03 11:39:42.899 1135-1135/com.example.aravindpraveen.buttonsandboxes E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.aravindpraveen.buttonsandboxes/com.example.aravindpraveen.buttonsandboxes.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
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: java.lang.NullPointerException
at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:3662)
at com.example.aravindpraveen.buttonsandboxes.MainActivity.<init>(MainActivity.java:15)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
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)
from the second activity declare in Manifest, remove tags
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
i think starting activity as MAIN while it's not MAIN may cause this problem
also in documentaion
Activity Action: Start as a main entry point, does not expect to receive data.
EDIT:
also move
str=s.toString();
extras.putString("Education",str);
inside onClick that starts the 2nd activity
Hi I have an app written that goes from a login page, to another activity with a progress bar, then to another activity with a tab host. If I get rid of the loading page and go from login to the tab host works fine, but if I try to go from login to loading the app stops and says 'Unfortunately application has stopped.' I have checked the logcat and see that there is a null pointer error for the Loading page, but I can't see why. In the intent to go from login to loading I call loading correctly, and the set content view in Loading matches its xml loading_main. Here is my code below, thannks:
Main login activity:
package com.example.loginscreen;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText username=null;
private EditText password=null;
private TextView attempts;
private Button login;
int counter = 3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText)findViewById(R.id.editText1);
password = (EditText)findViewById(R.id.editText2);
attempts = (TextView)findViewById(R.id.textView5);
attempts.setText(Integer.toString(counter));
login = (Button)findViewById(R.id.button1);
}
public void login(View view){
if(username.getText().toString().equals("mara") &&
password.getText().toString().equals("mara")){
Toast.makeText(getApplicationContext(), "Login Successful!",
Toast.LENGTH_LONG).show();
startActivity(new Intent(MainActivity.this,Loading.class));
}
else{
Toast.makeText(getApplicationContext(), "Wrong Credentials",
Toast.LENGTH_SHORT).show();
attempts.setBackgroundColor(Color.RED);
counter--;
attempts.setText(Integer.toString(counter));
if(counter==0){
login.setEnabled(false);
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Loading activity:
package com.example.loginscreen;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class Loading extends Activity {
Button btnStartProgress;
ProgressDialog progressBar;
private int progressBarStatus = 0;
private Handler progressBarHandler = new Handler();
private long fileSize = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loading_main);
addListenerOnButton();
}
public void addListenerOnButton() {
btnStartProgress = (Button) findViewById(R.id.button1);
btnStartProgress.setOnClickListener( // <== This is line 33
new OnClickListener() {
#Override
public void onClick(View v) {
// prepare for a progress bar dialog
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("Searching for Driver Card...");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
//reset progress bar status
progressBarStatus = 0;
//reset filesize
fileSize = 0;
new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {
// process some tasks
progressBarStatus = doSomeTasks();
// your computer is too fast, sleep 1 second
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Update the progress bar
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}
// driver card is found
if (progressBarStatus >= 100) {
// sleep 2 seconds, so that you can see the 100%
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// close the progress bar dialog
progressBar.dismiss();
}
}
});
startActivity(new Intent(Loading.this,LinkTabs.class));
}
});
}
// file download simulator
public int doSomeTasks() {
while (fileSize <= 1000000) {
fileSize++;
if (fileSize == 100000) {
return 10;
} else if (fileSize == 200000) {
return 20;
} else if (fileSize == 300000) {
return 30;
}
}
return 100;
}
}
Activity LinkTabs to link all tabs in tab host:
package com.example.loginscreen;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
#SuppressWarnings("deprecation")
public class LinkTabs extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.link_main);
Resources ressources = getResources();
TabHost tabHost = getTabHost();
// First tab
Intent intentAndroid = new Intent().setClass(this, HomePage.class);
TabSpec tabSpecHomePage = tabHost
.newTabSpec("HomePage")
.setIndicator("", ressources.getDrawable(R.drawable.overview))
.setContent(intentAndroid);
// Second tab
Intent intentApple = new Intent().setClass(this, HomePage2.class);
TabSpec tabSpecHomePage2 = tabHost
.newTabSpec("HomePage2")
.setIndicator("", ressources.getDrawable(R.drawable.card_summary))
.setContent(intentApple);
// Third tab
Intent intentWindows = new Intent().setClass(this, HomePage3.class);
TabSpec tabSpecHomePage3 = tabHost
.newTabSpec("HomePage3")
.setIndicator("", ressources.getDrawable(R.drawable.details))
.setContent(intentWindows);
// add all tabs
tabHost.addTab(tabSpecHomePage);
tabHost.addTab(tabSpecHomePage2);
tabHost.addTab(tabSpecHomePage3);
//set Windows tab as default (zero based)
tabHost.setCurrentTab(2);
}
}
Tab activities:
package com.example.loginscreen;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HomePage extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Overview");
setContentView(textview);
}
}
package com.example.loginscreen;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HomePage2 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Card Summary");
setContentView(textview);
}
}
package com.example.loginscreen;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HomePage3 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Details");
setContentView(textview);
}
}
Here are the xml files:
//activity_main.xml
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_marginLeft="32dp"
android:layout_toRightOf="#+id/textView2"
android:ems="10"
tools:ignore="TextFields" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView3"
android:layout_alignLeft="#+id/editText1"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_marginTop="40dp"
android:layout_toLeftOf="#+id/editText1"
android:hint="Password"
android:text="#string/password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<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_alignLeft="#+id/button1"
android:text="TextView"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignParentTop="true"
android:layout_marginTop="155dp"
android:hint="Username"
android:text="#string/username"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView3"
android:layout_alignLeft="#+id/textView2"
android:layout_alignParentTop="true"
android:src="#drawable/tranzlogo1" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_marginTop="26dp"
android:layout_toLeftOf="#+id/textView5"
android:text="#string/attempts"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignRight="#+id/editText2"
android:layout_below="#+id/textView4" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp"
android:onClick="login"
android:text="#string/Login" />
</RelativeLayout>
//fragment_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.loginscreen.MainActivity$PlaceholderFragment" >
<ImageView
android:id="#+id/tranzlogo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="71dp"
android:src="#drawable/overview"
tools:ignore="ContentDescription" />
</RelativeLayout>
//link_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.loginscreen.MainActivity$PlaceholderFragment" >
<ImageView
android:id="#+id/tranzlogo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="71dp"
android:src="#drawable/overview"
tools:ignore="ContentDescription" />
</RelativeLayout>
//loading_main.xml
<?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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="413dp"
android:layout_height="382dp" />
</LinearLayout>
Here is loading_main.xml:
<?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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="413dp"
android:layout_height="382dp" />
</LinearLayout>
Here is the mainfest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginscreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.loginscreen.MainActivity"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HomePage" />
<activity android:name=".HomePage2" />
<activity android:name=".HomePage3" />
<activity android:name=".Loading"/>
<activity android:name=".LinkTabs"/>
</application>
</manifest>
And the logcat output:
06-20 10:22:15.289: W/dalvikvm(29524): threadid=1: thread exiting with uncaught exception (group=0x40cca318)
06-20 10:22:15.299: E/AndroidRuntime(29524): FATAL EXCEPTION: main
06-20 10:22:15.299: E/AndroidRuntime(29524): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.loginscreen/com.example.loginscreen.Loading}: java.lang.NullPointerException
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2063)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2088)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.app.ActivityThread.access$600(ActivityThread.java:134)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.os.Looper.loop(Looper.java:137)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.app.ActivityThread.main(ActivityThread.java:4744)
06-20 10:22:15.299: E/AndroidRuntime(29524): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 10:22:15.299: E/AndroidRuntime(29524): at java.lang.reflect.Method.invoke(Method.java:511)
06-20 10:22:15.299: E/AndroidRuntime(29524): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-20 10:22:15.299: E/AndroidRuntime(29524): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-20 10:22:15.299: E/AndroidRuntime(29524): at dalvik.system.NativeStart.main(Native Method)
06-20 10:22:15.299: E/AndroidRuntime(29524): Caused by: java.lang.NullPointerException
06-20 10:22:15.299: E/AndroidRuntime(29524): at com.example.loginscreen.Loading.addListenerOnButton(Loading.java:33)
06-20 10:22:15.299: E/AndroidRuntime(29524): at com.example.loginscreen.Loading.onCreate(Loading.java:26)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.app.Activity.performCreate(Activity.java:5008)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
06-20 10:22:15.299: E/AndroidRuntime(29524): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2027)
06-20 10:22:15.299: E/AndroidRuntime(29524): ... 11 more
You have referenced in Your LoadingMain activity the following layout with setContentView:
setContentView(R.layout.loading_main);
But this Layout does not have any button1. Instead, You are trying to reference a button from another layout, from activity_main.xml
btnStartProgress = (Button) findViewById(R.id.button1);
This button1 is inside the activity_main.xml and You cannot reference a button in a layout that is not attached per setContentView. So What You have to do is, add a button to the loading_main.xml, BUT, don´t give it the same id like in the activity main "button1". Sure, it works, to give same ids as long as the right layout is referenced, but id´s should be unique. If the button in the activity_layout should remain, give the id for your button inside loading_main.xml another name, maybe android:id="#+id/loading_main_button_1".
Clearly the error is in xml, you have not added the button here:
<?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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="413dp"
android:layout_height="382dp" />
</LinearLayout>
Try adding the following in your loading_main.xml
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
The complete thing should look like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="413dp"
android:layout_height="382dp" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
NullPointerExcception
it causes because using null object or not defining value to object.
In Loading.java you have used
setContentView(R.layout.loading_main);
that don't have button1
add button1 in loading_main.xml it or Change layout in setContentView(R.layout.other_layout);
I'm working on a Madlib app. The code you see below is the class that handles gathering input from edittext boxes found in madlibinput1.xml, storing that info as strings, and then sending that text to the madliboutput.xml where it replaces all "wx" with input gathered in the input xml. This class used to be an activity, but I found making it a fragment helps implement my navigation drawer better. However, I am an almost complete beginner with fragments (and programming in general) and feel like I didn't convert my code to work with fragments very well.
Can someone help me figure out why I have a null pointer exception in the gather() method (and perhaps null pointers elsewhere) when I hit the convert button. Perhaps I am doing something wrong getting information about my xml or something to do with my views. It would be very appreciated thank you.
package com.shamu11.madlibsportable;
import java.io.IOException;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
public class Madlibs extends Fragment {
int inLayout; // will hold the id number for layout file
// main_class_activity_in.xml.
int outLayout; // will hold the id number for layout file
// main_class_activity_out.xml.
int outviewid; // will hold the id number for the textview found in
// main_class_activity_out.xml
//Activity activity = this;
String test;
AutoCompleteTextView autoview;
StringBuffer stringbuffer = new StringBuffer();
String[] stringviews = new String[16];
Button convert;
View view;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
view = inflater.inflate(R.layout.madlibinput1, container, false);
//setContentView(R.layout.madlibinput1);
outLayout = (R.layout.madliboutput1);
inLayout = (R.layout.madlibinput1);
outviewid = (R.id.outview14);
convert = (Button) view.findViewById(R.id.convert);
convert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
gather();
postIt();
}
});
return view;
}
public void gather() {
ViewGroup layout = (ViewGroup) getView().findViewById(R.id.anskey_clover);
View[] views = new View[layout.getChildCount()];
int[] ids = new int[layout.getChildCount()];
for (int i = 0; i < layout.getChildCount(); i++) {
ids[i] = layout.getChildAt(i).getId();
}
for (int i = 0; i < layout.getChildCount(); i++) {
AutoCompleteTextView au = (AutoCompleteTextView) getActivity().findViewById(ids[i]);
stringbuffer.append(au.getText().toString() + "\n");
}
//setContentView(outLayout);
TextView outview = (TextView) getView().findViewById(outviewid);
outview.setText(stringbuffer.toString());
}
public void postIt() {
String str = "let's go to the park";
String str2;
String newstr = null;
//setContentView(outLayout);
TextView outview = (TextView) view.findViewById(outviewid);
str = (String) outview.getText();
stringviews = stringbuffer.toString().split("\n"); // turns the
// stringbuffer from
// getAllXml() into
// an array and
// assigns to
// stringviews.
for (int i = 0; i < stringviews.length; i++) {
str2 = stringviews[i];
newstr = str.replaceFirst("wx", str2); // replaces all the "wx"s in
// the
// main_class_activity_out
// textview with values from
// strinvgviews.
str = newstr;
}
outview.setText(newstr);
stringbuffer.delete(0, stringbuffer.length());
Fragment newFragment = new MadlibsOutput();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment1, newFragment);
transaction.addToBackStack(null);
transaction.commit();
}
}
madlibinput1.xml:
<?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:orientation="vertical"
android:background="#ffffff" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.39"
android:background="#ffffff" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="184dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff" >
<TextView
android:id="#+id/outview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="1.) Adjective to Describe:" />
<TextView
android:id="#+id/lvheader_song"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="2.) ing-verb (i.e. running):" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="3.) Negative Adjective:" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="4.) Negative Verb:" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="5.) Adjective" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="6.) Plural Noun:" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="7.) Verb (ending in '-ed'):" />
</LinearLayout>
<LinearLayout
android:id="#+id/anskey_clover"
android:layout_width="match_parent"
android:layout_height="234dp"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="#+id/auview1"
android:layout_width="141dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:ems="10"
android:text="la dee dah" />
<AutoCompleteTextView
android:id="#+id/auview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<AutoCompleteTextView
android:id="#+id/auview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<AutoCompleteTextView
android:id="#+id/auview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<AutoCompleteTextView
android:id="#+id/auview5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<AutoCompleteTextView
android:id="#+id/auview6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<AutoCompleteTextView
android:id="#+id/auview7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/convert"
android:layout_width="222dp"
android:layout_height="93dp"
android:layout_weight="0.25"
android:text="Get My Mad Lib" />
</LinearLayout>
madliboutput1.xml:
<?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:orientation="vertical" >
<TextView
android:id="#+id/outview14"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:gravity="left"
android:text="madlib text.........etc" />
</LinearLayout>
LOG CAT:
06-30 23:00:11.530: E/AndroidRuntime(5567): FATAL EXCEPTION: main
06-30 23:00:11.530: E/AndroidRuntime(5567): Process: com.shamu11.madlibsportable, PID: 5567
06-30 23:00:11.530: E/AndroidRuntime(5567): java.lang.NullPointerException
06-30 23:00:11.530: E/AndroidRuntime(5567): at com.shamu11.madlibsportable.Madlibs.gather(Madlibs.java:78)
06-30 23:00:11.530: E/AndroidRuntime(5567): at com.shamu11.madlibsportable.Madlibs$1.onClick(Madlibs.java:51)
06-30 23:00:11.530: E/AndroidRuntime(5567): at android.view.View.performClick(View.java:4438)
06-30 23:00:11.530: E/AndroidRuntime(5567): at android.view.View$PerformClick.run(View.java:18422)
06-30 23:00:11.530: E/AndroidRuntime(5567): at android.os.Handler.handleCallback(Handler.java:733)
06-30 23:00:11.530: E/AndroidRuntime(5567): at android.os.Handler.dispatchMessage(Handler.java:95)
06-30 23:00:11.530: E/AndroidRuntime(5567): at android.os.Looper.loop(Looper.java:136)
06-30 23:00:11.530: E/AndroidRuntime(5567): at android.app.ActivityThread.main(ActivityThread.java:5001)
06-30 23:00:11.530: E/AndroidRuntime(5567): at java.lang.reflect.Method.invokeNative(Native Method)
06-30 23:00:11.530: E/AndroidRuntime(5567): at java.lang.reflect.Method.invoke(Method.java:515)
06-30 23:00:11.530: E/AndroidRuntime(5567): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
06-30 23:00:11.530: E/AndroidRuntime(5567): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
06-30 23:00:11.530: E/AndroidRuntime(5567): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
06-30 23:00:11.530: E/AndroidRuntime(5567): at dalvik.system.NativeStart.main(Native Method)
You try to find view in activity not in fragment, by this line:
AutoCompleteTextView au = (AutoCompleteTextView) getActivity().findViewById(ids[i]);