startActivity() forces closes my application - java

I cannot start a new activity no matter what I do.
I re-downloaded all Android SDKs again.
I re-downloaded Eclipse and installed ADT plugin again
Error Log
09-16 17:53:51.537: W/IInputConnectionWrapper(4661): getCursorCapsMode on inactive InputConnection
09-16 17:53:51.998: D/AndroidRuntime(4661): Shutting down VM
09-16 17:53:51.998: W/dalvikvm(4661): threadid=1: thread exiting with uncaught exception (group=0x41987300)
09-16 17:53:52.022: E/AndroidRuntime(4661): FATAL EXCEPTION: main
09-16 17:53:52.022: E/AndroidRuntime(4661): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.lays.decisong/com.lays.decisong.activities.GameActivity}: java.lang.NullPointerException
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.os.Handler.dispatchMessage(Handler.java:99)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.os.Looper.loop(Looper.java:137)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-16 17:53:52.022: E/AndroidRuntime(4661): at java.lang.reflect.Method.invokeNative(Native Method)
09-16 17:53:52.022: E/AndroidRuntime(4661): at java.lang.reflect.Method.invoke(Method.java:511)
09-16 17:53:52.022: E/AndroidRuntime(4661): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-16 17:53:52.022: E/AndroidRuntime(4661): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-16 17:53:52.022: E/AndroidRuntime(4661): at dalvik.system.NativeStart.main(Native Method)
09-16 17:53:52.022: E/AndroidRuntime(4661): Caused by: java.lang.NullPointerException
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:132)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:65)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.AlertDialog.<init>(AlertDialog.java:98)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ProgressDialog.show(ProgressDialog.java:110)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ProgressDialog.show(ProgressDialog.java:99)
09-16 17:53:52.022: E/AndroidRuntime(4661): at com.lays.decisong.activities.GameActivity$3.<init>(GameActivity.java:401)
09-16 17:53:52.022: E/AndroidRuntime(4661): at com.lays.decisong.activities.GameActivity.<init>(GameActivity.java:398)
09-16 17:53:52.022: E/AndroidRuntime(4661): at java.lang.Class.newInstanceImpl(Native Method)
09-16 17:53:52.022: E/AndroidRuntime(4661): at java.lang.Class.newInstance(Class.java:1319)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-16 17:53:52.022: E/AndroidRuntime(4661): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
Public key in DecisongApplication.java
public static final String PLAYERS_KEY = "com.lays.decisong.activities.Players";
Button Handler in InputActivity.java
App forces closes when startActivity() is called
public void startGame(View v) {
// check if there's more than one player
if (mPlayers.size() < 2) {
Log.i(TAG, "Only 1 player");
Toast.makeText(mContext, "At least 2 players needed to start game",
Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent(this.getApplicationContext(), GameActivity.class);
intent.putStringArrayListExtra(DecisongApplication.PLAYERS_KEY, mPlayers);
startActivity(intent);
overridePendingTransition(R.anim.slide_up_incoming, R.anim.slide_up_outgoing);
}
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lays.decisong"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<supports-screens
android:anyDensity="true"
android:largeScreens="false"
android:normalScreens="true"
android:smallScreens="false"
android:xlargeScreens="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name="com.lays.decisong.DecisongApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
<activity android:name=".activities.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.InstructionsActivity"
android:noHistory="true" />
<activity
android:name=".activities.InputActivity"
android:noHistory="true" />
<activity
android:name=".activities.SettingsActivity"
android:noHistory="true" />
<activity
android:name=".activities.GameActivity"
android:noHistory="true" />
</application>
</manifest>
onCreate of GameActivity.java in com.lays.decisong.activities which never got called
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
// init rdio variables
mTrackQueue = new LinkedList<Track>();
if (mRdio == null) {
mRdio = new Rdio(DecisongApplication.RDIO_API_KEY,
DecisongApplication.RDIO_SECRET_KEY, null, null, this, this);
}
// init quiz variables
mListView = getListView();
mAllAlbums = new HashMap<String, Album>();
mChosenTracks = new ArrayList<Track>();
mAdapter = new TracksAdapter(this, mChosenTracks);
setListAdapter(mAdapter);
// init player variables
mCurrentRoundView = (TextView) findViewById(R.id.current_round);
mCurrentRound = INITIAL_ROUND;
mCurrentPlayerView = (TextView) findViewById(R.id.current_player);
mCurrentPlayer = INITIAL_PLAYER;
mPlayers = new ArrayList<Player>();
if (getIntent().hasExtra(DecisongApplication.PLAYERS_KEY)) {
ArrayList<String> players = getIntent().getStringArrayListExtra(DecisongApplication.PLAYERS_KEY);
for (String p : players) {
mPlayers.add(Player.create(p));
}
}
// setup game conditions
Collections.shuffle(mPlayers);
mCurrentPlayerView.setText(mPlayers.get(mCurrentPlayer).name);
}

09-16 17:53:52.022: E/AndroidRuntime(4661): at com.lays.decisong.activities.GameActivity$3.<init>(GameActivity.java:401)
09-16 17:53:52.022: E/AndroidRuntime(4661): at com.lays.decisong.activities.GameActivity.<init>(GameActivity.java:398)
Looks like you're trying to do some setup in your GameActivity's constructor, or initialise some fields before the activity's Context is fully initialised. You should really do all setup in onCreate(); don't use a constructor, and don't rely on the Context being usable until onCreate() is entered.

Related

Class not found Android

I have a custom View class in my application. I want to extend it and add it to my xml file however when I do that I get class not found exception..
Here is the xml file:
floorplan.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/floorplannextbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="47dp"
android:layout_marginTop="22dp"
android:text="Next" />
<com.example.helloworld3.FloorPlan.DrawView2
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
And this is my DrawView2 class. It is inside another class called FloorPlan but the entire code would be too long to post
DrawView2.java
public class DrawView2 extends RelativeLayout {
Paint paint = new Paint();
public DrawView2(Context context) {
super(context);
paint.setColor(Color.RED);
}
public void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
for(int i =0,j=i+1 ; i<subpath.size()&& j<subpath.size(); i++, j++){
ux = subpath.get(i).v.x;
dx =subpath.get(i).v.y;
rx= subpath.get(j).v.x;
lx = subpath.get(j).v.y;
canvas.drawLine(ux, dx , rx, lx, paint);
}
}
This is what I get in the LogCat:
04-04 20:37:59.959: D/(884): HostConnection::get() New Host Connection established 0x8b92258, tid 884
04-04 20:38:07.047: W/KeyCharacterMap(884): No keyboard for id 0
04-04 20:38:07.047: W/KeyCharacterMap(884): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-04 20:38:16.599: D/AndroidRuntime(884): Shutting down VM
04-04 20:38:16.599: W/dalvikvm(884): threadid=1: thread exiting with uncaught exception (group=0xb5ff94f0)
04-04 20:38:16.607: E/AndroidRuntime(884): FATAL EXCEPTION: main
04-04 20:38:16.607: E/AndroidRuntime(884): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloworld3/com.example.helloworld3.FloorPlan}: android.view.InflateException: Binary XML file line #18: Error inflating class com.example.helloworld3.FloorPlan.DrawView2
04-04 20:38:16.607: E/AndroidRuntime(884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.os.Looper.loop(Looper.java:130)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-04 20:38:16.607: E/AndroidRuntime(884): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 20:38:16.607: E/AndroidRuntime(884): at java.lang.reflect.Method.invoke(Method.java:507)
04-04 20:38:16.607: E/AndroidRuntime(884): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-04 20:38:16.607: E/AndroidRuntime(884): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-04 20:38:16.607: E/AndroidRuntime(884): at dalvik.system.NativeStart.main(Native Method)
04-04 20:38:16.607: E/AndroidRuntime(884): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class com.example.helloworld3.FloorPlan.DrawView2
04-04 20:38:16.607: E/AndroidRuntime(884): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-04 20:38:16.607: E/AndroidRuntime(884): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.app.Activity.setContentView(Activity.java:1657)
04-04 20:38:16.607: E/AndroidRuntime(884): at com.example.helloworld3.FloorPlan.onCreate(FloorPlan.java:164)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-04 20:38:16.607: E/AndroidRuntime(884): ... 11 more
04-04 20:38:16.607: E/AndroidRuntime(884): Caused by: java.lang.ClassNotFoundException: com.example.helloworld3.FloorPlan.DrawView2 in loader dalvik.system.PathClassLoader[/data/app/com.example.helloworld3-1.apk]
04-04 20:38:16.607: E/AndroidRuntime(884): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-04 20:38:16.607: E/AndroidRuntime(884): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-04 20:38:16.607: E/AndroidRuntime(884): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
04-04 20:38:16.607: E/AndroidRuntime(884): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
04-04 20:38:16.607: E/AndroidRuntime(884): ... 20 more
And is my Manifest file:
AndroidManifes. xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld3"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<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=".FloorPlan"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.helloworld3.FLOORPLAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".FloorPlanTwo"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.helloworld3.FLOORPLANTWO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".FloorPlanThree"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.helloworld3.FLOORPLANTHREE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Thank you for all you help!
If DrawView2 is an inner class it should be referred to in XML as:
...
<com.example.helloworld3.FloorPlan$DrawView2
android:layout_width="match_parent"
android:layout_height="match_parent"/>
...
I had a problem similar to yours. Try these two things:
Extends from View, not from RelativeLayout
Add these constructors to your DrawView2 class
public DrawView2(Context context)
{
super(context);
}
public DrawView2(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public DrawView2(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
}

Edittext to ratingbar in Android

This is my first question here so I would ask you not to be tough on me if I violate some rules, etc.
I am developing an Android project with a ratingbar. I try to get a number from edittext and pass its value to the ratingbar. I get a nullpointerexception and can't get past this, any help will be appreciated.
Here is the portion of relevant code:
public void bindView(View movieView, Context context, Cursor cursor)
{
final Movie movie = new Movie(cursor);
Holder holder = (Holder)movieView.getTag();
holder.setMovie(movie);
TextView movieTitleText = (TextView)movieView.findViewById(R.id.movieTitleText);
TextView movieDescriptionText = (TextView)movieView.findViewById(R.id.movieDescriptionText);
RatingBar rb = (RatingBar)movieView.findViewById(R.id.movieRatingBar);
rb.setNumStars(5);
rb.setMax(5);
rb.setRating(2.4F);
rb.setEnabled(false);
rb.setFocusable(false);
float numRate = 0;
numRate = Float.parseFloat(movie.getRating().toString());
rb.setRating(numRate);
movieTitleText.setText(movie.getTitle());
movieDescriptionText.setText(movie.getDescription());
movieView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Short click", Toast.LENGTH_LONG).show();
Intent editIntent = new Intent(MoviesActivity.this, EditMovieActivity.class);
editIntent.putExtra("isNew",false);
editIntent.putExtra("title", movie.getTitle());
editIntent.putExtra("description", movie.getDescription());
editIntent.putExtra("year", movie.getYear());
editIntent.putExtra("rating", movie.getRating());
editIntent.putExtra("rottenId", movie.getRottenId());
editIntent.putExtra("smallImage", movie.getSmallImage());
editIntent.putExtra("largeImage", movie.getLargeImage());
startActivityForResult(editIntent,EDIT_MOVIE_REQUEST_CODE);
}
});
movieView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(final View v) {
Toast.makeText(getApplicationContext(), "Long click", Toast.LENGTH_LONG).show();
AlertDialog.Builder editBuilder = new AlertDialog.Builder(MoviesActivity.this);
editBuilder.setTitle("Edit or Clear Movie").setMessage("Please choose either to clear or to edit the movie");
editBuilder.setPositiveButton("Edit", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Intent editIntent = new Intent(MoviesActivity.this, EditMovieActivity.class);
editIntent.putExtra("isNew",false);
editIntent.putExtra("title", movie.getTitle());
editIntent.putExtra("description", movie.getDescription());
editIntent.putExtra("year", movie.getYear());
editIntent.putExtra("rating", movie.getRating());
editIntent.putExtra("rottenId", movie.getRottenId());
editIntent.putExtra("smallImage", movie.getSmallImage());
editIntent.putExtra("largeImage", movie.getLargeImage());
startActivityForResult(editIntent,EDIT_MOVIE_REQUEST_CODE);
}
});
editBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
Builder setNeutralButton = editBuilder.setNeutralButton("Clear movie", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.deleteMovie(movie.getId());
moviesCursor = handler.getAllMoviesCursor();
adapter.swapCursor(moviesCursor);
adapter.notifyDataSetChanged();
Toast.makeText(getApplicationContext(), "Movie deleted", Toast.LENGTH_LONG).show();
}
});
editBuilder.show();
return true;
}
});
}
and here is the stack trace:
09-16 03:41:28.912: E/AndroidRuntime(1248): FATAL EXCEPTION: main
09-16 03:41:28.912: E/AndroidRuntime(1248): java.lang.NullPointerException
09-16 03:41:28.912: E/AndroidRuntime(1248): at com.rotten.tomatoes.MoviesActivity$MyCursorAdapter.bindView(MoviesActivity.java:209)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.AbsListView.obtainView(AbsListView.java:2033)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.ListView.makeAndAddView(ListView.java:1772)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.ListView.fillDown(ListView.java:672)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.ListView.fillFromTop(ListView.java:732)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.ListView.layoutChildren(ListView.java:1625)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.AbsListView.onLayout(AbsListView.java:1863)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.View.layout(View.java:11278)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.View.layout(View.java:11278)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.View.layout(View.java:11278)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.View.layout(View.java:11278)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.View.layout(View.java:11278)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.os.Handler.dispatchMessage(Handler.java:99)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.os.Looper.loop(Looper.java:137)
09-16 03:41:28.912: E/AndroidRuntime(1248): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-16 03:41:28.912: E/AndroidRuntime(1248): at java.lang.reflect.Method.invokeNative(Native Method)
09-16 03:41:28.912: E/AndroidRuntime(1248): at java.lang.reflect.Method.invoke(Method.java:511)
09-16 03:41:28.912: E/AndroidRuntime(1248): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-16 03:41:28.912: E/AndroidRuntime(1248): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-16 03:41:28.912: E/AndroidRuntime(1248): at dalvik.system.NativeStart.main(Native Method)
Thanks a lot!

Why DrawerLayout and ActionBar not working on Tablets?

I'm develop some app with sliding menu.
when i try to run this on my galaxy 4s(api 18+ 4.3.3) its work fine!
but when i run this on xperia arc (api 8 ver 2.3.4) the app crash.
i know its dependent on Support library and i use :
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
and i need to use :
import android.support.v7.app.ActionBar;
so i added to my project the support library and connect the support library to him.
but i dont know how to handle the support and what i need to chage on my code:
my java code (v4){
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
public class MainActivity extends Activity implements OnClickListener, OnLongClickListener , OnTouchListener , OnItemClickListener{
/////////////////
ArrayList<ItemInSetting > listSetting = new ArrayList<ItemInSetting>();
CustomAdapterSetting adapterSetting;
DrawerLayout drawer;
ActionBarDrawerToggle toggle;
//////////////////
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
settingItems();
}
public void settingItems(){
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
drawer = (DrawerLayout) findViewById(R.id.drawer);
toggle = new ActionBarDrawerToggle(this, drawer, R.drawable.ic_drawer, 0, 0){
#Override
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle("menu");
invalidateOptionsMenu();
}
#Override
public void onDrawerClosed(View drawerView) {
getActionBar().setTitle("app title");
invalidateOptionsMenu();
}
};drawer.setDrawerListener(toggle);
listSetting.add(new ItemInSetting("ist1", R.drawable.calende_bigg));
listSetting.add(new ItemInSetting("ist2", R.drawable.calende_bigg));
listSetting.add(new ItemInSetting("ist3", R.drawable.calende_bigg));
listSetting.add(new ItemInSetting("ist4", R.drawable.calende_bigg));
lvSetting = (ListView) findViewById(R.id.listSetting);
lvSetting.setOnItemClickListener(this);
adapterSetting = new CustomAdapterSetting(listSetting, this);
lvSetting.setAdapter(adapterSetting);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
date = new Date();
switch (position) {
case 0:
Intent intent = new Intent (MainActivity.this,ListOfHours.class);
startActivity(intent);
break;
case 1:
getSetting();
if(sickIsOn){
cancelingFreeday(false);
}else{
addingManualMenu();
}
break;
case 2:
changingSetting(" ");
break;
case 3:
sendContact();
break;
default:
break;
}
drawer.closeDrawers();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (toggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
toggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
toggle.onConfigurationChanged(newConfig);
}
my 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="#drawable/new_back"
android:orientation="vertical"
tools:context=".MainActivity" >
<FrameLayout
android:id="#+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listSetting"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="#android:color/darker_gray"
android:choiceMode="singleChoice"
android:listSelector="#drawable/list_selector" >
</ListView>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bib.workclock"
android:versionCode="52"
android:versionName="3.0.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/icon_new3"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<activity
android:name="com.bibas.workclock.MainActivity"
android:label="#string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ListOfHours" ></activity>
<activity android:name="HelpPage"></activity>
<activity android:name="info" android:screenOrientation="portrait"></activity>
</application>
</manifest>
this the locat error when i try to run on xperia :
05-04 01:59:05.058: E/AndroidRuntime(15484): FATAL EXCEPTION: main
05-04 01:59:05.058: E/AndroidRuntime(15484): java.lang.NoSuchMethodError: com.bba.workclock.MainActivity.getActionBar
05-04 01:59:05.058: E/AndroidRuntime(15484): at com.bba.workclock.MainActivity.settingItems(MainActivity.java:1657)
05-04 01:59:05.058: E/AndroidRuntime(15484): at com.bba.workclock.MainActivity.onCreate(MainActivity.java:124)
05-04 01:59:05.058: E/AndroidRuntime(15484): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-04 01:59:05.058: E/AndroidRuntime(15484): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
05-04 01:59:05.058: E/AndroidRuntime(15484): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
05-04 01:59:05.058: E/AndroidRuntime(15484): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
05-04 01:59:05.058: E/AndroidRuntime(15484): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
05-04 01:59:05.058: E/AndroidRuntime(15484): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 01:59:05.058: E/AndroidRuntime(15484): at android.os.Looper.loop(Looper.java:130)
05-04 01:59:05.058: E/AndroidRuntime(15484): at android.app.ActivityThread.main(ActivityThread.java:3701)
05-04 01:59:05.058: E/AndroidRuntime(15484): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 01:59:05.058: E/AndroidRuntime(15484): at java.lang.reflect.Method.invoke(Method.java:507)
05-04 01:59:05.058: E/AndroidRuntime(15484): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
05-04 01:59:05.058: E/AndroidRuntime(15484): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
05-04 01:59:05.058: E/AndroidRuntime(15484): at dalvik.system.NativeStart.main(Native Method)
here is project like mine:
http://speedy.sh/UKsrV/SlidingMenu.zip
if any one can fix that code and give it to me back i appreciate alot
How can i fix this?!!
please help me :(((
I FIX THAT PROBLEM BUT KNOW ON MY TABLET IT'S CRASH .
here the locat error:
05-11 23:10:22.127: E/AndroidRuntime(31723): FATAL EXCEPTION: main
05-11 23:10:22.127: E/AndroidRuntime(31723): java.lang.IllegalStateException: Child android.widget.FrameLayout#41f91e40 at index 0 does not have a valid layout_gravity - must be Gravity.LEFT, Gravity.RIGHT or Gravity.NO_GRAVITY
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:721)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.View.measure(View.java:15479)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4826)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.View.measure(View.java:15479)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.View.measure(View.java:15479)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4826)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
05-11 23:10:22.127: E/AndroidRuntime(31723): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2359)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.View.measure(View.java:15479)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1968)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1214)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1387)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4464)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.Choreographer.doFrame(Choreographer.java:525)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.os.Handler.handleCallback(Handler.java:615)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.os.Handler.dispatchMessage(Handler.java:92)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.os.Looper.loop(Looper.java:137)
05-11 23:10:22.127: E/AndroidRuntime(31723): at android.app.ActivityThread.main(ActivityThread.java:4895)
05-11 23:10:22.127: E/AndroidRuntime(31723): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 23:10:22.127: E/AndroidRuntime(31723): at java.lang.reflect.Method.invoke(Method.java:511)
05-11 23:10:22.127: E/AndroidRuntime(31723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
05-11 23:10:22.127: E/AndroidRuntime(31723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
05-11 23:10:22.127: E/AndroidRuntime(31723): at dalvik.system.NativeStart.main(Native Method)
ActionBar is available from api level 11. To support below api level 11 you need to use AppCompat from the support library. Reference AppCompat in your android project.
You need to extend ActionBarActivity. Use theme derived from Theme.AppCompat in manifest and use getSupportActionBar().
Complete example #
Navigation Drawer with backword compatibility android
Check Adding libraries with resources
https://developer.android.com/tools/support-library/setup.html
And read
http://developer.android.com/guide/topics/ui/actionbar.html

Android Application crahes when passing strings between classes

I'm trying to pass a string between 2 classes in Android . The first class is "MainActivity" and the second one is "abc" .
Here's my MainActivity code :
package com.example.passstrings;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
public class MainActivity extends ActionBarActivity {
String pass;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pass = "abcabc";
Intent abc = new Intent(this , abc.class);
abc.putExtra("key", pass);
startActivity(abc);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
and here's my abc class code :
package com.example.passstrings;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class abc extends Activity{
TextView tv1;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1=(TextView) findViewById(R.id.textView1);
Intent intent = getIntent();
String pass= intent.getExtras().getString("key");
if(pass!= null){
tv1.setText(pass);
}
}
}
Here's my fragment_main.xml code :
<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.passstrings.MainActivity$PlaceholderFragment" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_marginLeft="69dp"
android:layout_marginTop="72dp"
android:layout_toRightOf="#+id/textView2"
android:text="TextView" />
</RelativeLayout>
and here's my LogCat :
04-04 05:34:38.545: I/dalvikvm(734): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
04-04 05:34:38.545: W/dalvikvm(734): VFY: unable to resolve virtual method 320: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
04-04 05:34:38.545: D/dalvikvm(734): VFY: replacing opcode 0x6e at 0x008b
04-04 05:34:38.545: I/dalvikvm(734): Could not find method android.content.pm.ApplicationInfo.loadLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
04-04 05:34:38.545: W/dalvikvm(734): VFY: unable to resolve virtual method 316: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
04-04 05:34:38.545: D/dalvikvm(734): VFY: replacing opcode 0x6e at 0x0099
04-04 05:34:38.555: D/dalvikvm(734): VFY: dead code 0x008e-0092 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
04-04 05:34:38.555: D/dalvikvm(734): VFY: dead code 0x009c-00a0 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
04-04 05:34:38.675: D/AndroidRuntime(734): Shutting down VM
04-04 05:34:38.675: W/dalvikvm(734): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-04 05:34:38.685: E/AndroidRuntime(734): FATAL EXCEPTION: main
04-04 05:34:38.685: E/AndroidRuntime(734): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.passstrings/com.example.passstrings.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.passstrings/com.example.passstrings.abc}; have you declared this activity in your AndroidManifest.xml?
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.os.Looper.loop(Looper.java:123)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-04 05:34:38.685: E/AndroidRuntime(734): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 05:34:38.685: E/AndroidRuntime(734): at java.lang.reflect.Method.invoke(Method.java:521)
04-04 05:34:38.685: E/AndroidRuntime(734): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-04 05:34:38.685: E/AndroidRuntime(734): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-04 05:34:38.685: E/AndroidRuntime(734): at dalvik.system.NativeStart.main(Native Method)
04-04 05:34:38.685: E/AndroidRuntime(734): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.passstrings/com.example.passstrings.abc}; have you declared this activity in your AndroidManifest.xml?
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.Activity.startActivityForResult(Activity.java:2817)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.Activity.startActivity(Activity.java:2923)
04-04 05:34:38.685: E/AndroidRuntime(734): at com.example.passstrings.MainActivity.onCreate(MainActivity.java:25)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-04 05:34:38.685: E/AndroidRuntime(734): ... 11 more
and here's my manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.passstrings"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.passstrings.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>
</application>
</manifest>
If I remove "startActivity(abc);" the application doesn't crash, also if use try&catch the application doesn't crash but the same time it doesn't perform the action . So what could be the reason ? and thanks in advance
My LogCat after adding the activity to manifest :
04-04 05:47:16.555: I/dalvikvm(883): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
04-04 05:47:16.555: W/dalvikvm(883): VFY: unable to resolve virtual method 320: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
04-04 05:47:16.555: D/dalvikvm(883): VFY: replacing opcode 0x6e at 0x008b
04-04 05:47:16.555: I/dalvikvm(883): Could not find method android.content.pm.ApplicationInfo.loadLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
04-04 05:47:16.565: W/dalvikvm(883): VFY: unable to resolve virtual method 316: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
04-04 05:47:16.565: D/dalvikvm(883): VFY: replacing opcode 0x6e at 0x0099
04-04 05:47:16.565: D/dalvikvm(883): VFY: dead code 0x008e-0092 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
04-04 05:47:16.565: D/dalvikvm(883): VFY: dead code 0x009c-00a0 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
04-04 05:47:16.775: D/AndroidRuntime(883): Shutting down VM
04-04 05:47:16.775: W/dalvikvm(883): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-04 05:47:16.786: E/AndroidRuntime(883): FATAL EXCEPTION: main
04-04 05:47:16.786: E/AndroidRuntime(883): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.passstrings/com.example.passstrings.abc}: java.lang.NullPointerException
04-04 05:47:16.786: E/AndroidRuntime(883): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-04 05:47:16.786: E/AndroidRuntime(883): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-04 05:47:16.786: E/AndroidRuntime(883): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-04 05:47:16.786: E/AndroidRuntime(883): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-04 05:47:16.786: E/AndroidRuntime(883): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 05:47:16.786: E/AndroidRuntime(883): at android.os.Looper.loop(Looper.java:123)
04-04 05:47:16.786: E/AndroidRuntime(883): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-04 05:47:16.786: E/AndroidRuntime(883): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 05:47:16.786: E/AndroidRuntime(883): at java.lang.reflect.Method.invoke(Method.java:521)
04-04 05:47:16.786: E/AndroidRuntime(883): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-04 05:47:16.786: E/AndroidRuntime(883): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-04 05:47:16.786: E/AndroidRuntime(883): at dalvik.system.NativeStart.main(Native Method)
04-04 05:47:16.786: E/AndroidRuntime(883): Caused by: java.lang.NullPointerException
04-04 05:47:16.786: E/AndroidRuntime(883): at com.example.passstrings.abc.onCreate(abc.java:20)
04-04 05:47:16.786: E/AndroidRuntime(883): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-04 05:47:16.786: E/AndroidRuntime(883): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-04 05:47:16.786: E/AndroidRuntime(883): ... 11 more
and my Manifest after the update :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.passstrings"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.passstrings.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="com.example.passstrings.abc" />
</application>
</manifest>
You need to add your second Activity to your Androidmanifest.xml file.
<activity android:name="com.example.passstrings.abc" />
have you declared this activity in your AndroidManifest.xml?
04-04 05:34:38.685: E/AndroidRuntime(734): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
it clearly say's that you have not declared your abc activity in manifest file. have you declared this activity in your AndroidManifest.xml?
so just decalre your abc activity in manifest file.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.passstrings.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=".abc"
</activity>
</application>
add this line
<activity
android:name=".abc"
</activity>
and also change this in your abc.java
setContentView(R.layout.activity_main);
you have reference of activity_main only you have to set abc.XML or whatever your XML filename for abc. So change it with
setContentView(R.layout.abc);
Edit
public class abc extends Activity{
TextView tv1;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
tv1=(TextView) findViewById(R.id.textView1);
Intent intent = getIntent();
String pass= intent.getExtras().getString("key");
if(pass!= null){
tv1.setText(pass);
}
}
It is simply ActivityNotFoundException which mean you forgot to declare abc activity in your AndroidManifest.xml file.
Just add following line in your manifest.xml in application tag.
<activity android:name="com.example.passstrings.abc" />
For your new NullPointerException here is the solution
You have defined following .xml in your Activity file activity_main while you have declare TextViews in fragment_main.xml, that's why it is giving NullPointerException.
I suggest you to change the xml from following line
setContentView(R.layout.activity_main);
to
setContentView(R.layout.fragment_main.xml);

Fatal Exception on starting activity Android

I have created new activity that my MainActivity Should lunch, some why the application is crashing on the start of the new activity (called GamePlayActivity).
Here is the java code:
Intent startGameDrill = new Intent(MainActivity.this, GamePlayActivity.class);
startActivity(startGameDrill);
Here is the startGameDrill:
package com.simplemathgame;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class GamePlayActivity extends MainActivity {
int addDrills;
int subDrils;
int mulDrills;
int divDrills;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_play);
try {
numberOfAddDrills = (TextView) findViewById(R.id.add_drills_number);
numberOfSubDrills = (TextView) findViewById(R.id.sub_drills_number);
numberOfMulDrills = (TextView) findViewById(R.id.mul_drills_number);
numberOfDivDrills = (TextView) findViewById(R.id.div_drills_number);
minBoundText = (TextView) findViewById(R.id.min_text);
maxBoundText = (TextView) findViewById(R.id.max_text);
} catch (Exception e1) {
// TODO Auto-generated catch block
Log.w("game","error");
}
try {
addDrills = Integer.parseInt((String) numberOfAddDrills.getText());
subDrils = Integer.parseInt((String) numberOfSubDrills.getText());
mulDrills = Integer.parseInt((String) numberOfMulDrills.getText());
divDrills = Integer.parseInt((String) numberOfDivDrills.getText());
} catch (NumberFormatException e) {
Log.w("GameDrills","string to int");
}
Log.w("add", "" + addDrills);
Log.w("add", "" + subDrils);
Log.w("add", "" + mulDrills);
Log.w("add", "" + divDrills);
}
}
Here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.simplemathgame"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme" >
<activity
android:name="com.simplemathgame.Splash"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.simplemathgame.MainActivity"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="com.simplemathgame.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.simplemathgame.GamePlayActivity"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
</activity>
</application>
</manifest>
here is the logCat:
12-21 22:05:53.949: D/dalvikvm(610): GC_EXTERNAL_ALLOC freed 42K, 53% free 2546K/5379K, external 1917K/2137K, paused 41ms
12-21 22:06:32.809: D/AndroidRuntime(610): Shutting down VM
12-21 22:06:32.809: W/dalvikvm(610): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-21 22:06:32.818: E/AndroidRuntime(610): FATAL EXCEPTION: main
12-21 22:06:32.818: E/AndroidRuntime(610): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simplemathgame/com.simplemathgame.GamePlayActivity}: java.lang.NullPointerException
12-21 22:06:32.818: E/AndroidRuntime(610): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-21 22:06:32.818: E/AndroidRuntime(610): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-21 22:06:32.818: E/AndroidRuntime(610): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-21 22:06:32.818: E/AndroidRuntime(610): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-21 22:06:32.818: E/AndroidRuntime(610): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 22:06:32.818: E/AndroidRuntime(610): at android.os.Looper.loop(Looper.java:123)
12-21 22:06:32.818: E/AndroidRuntime(610): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-21 22:06:32.818: E/AndroidRuntime(610): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 22:06:32.818: E/AndroidRuntime(610): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 22:06:32.818: E/AndroidRuntime(610): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-21 22:06:32.818: E/AndroidRuntime(610): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-21 22:06:32.818: E/AndroidRuntime(610): at dalvik.system.NativeStart.main(Native Method)
12-21 22:06:32.818: E/AndroidRuntime(610): Caused by: java.lang.NullPointerException
12-21 22:06:32.818: E/AndroidRuntime(610): at com.simplemathgame.GamePlayActivity.onCreate(GamePlayActivity.java:31)
12-21 22:06:32.818: E/AndroidRuntime(610): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 22:06:32.818: E/AndroidRuntime(610): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-21 22:06:32.818: E/AndroidRuntime(610): ... 11 more
Here is the layout of the GamePlayActivity:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#000044">
<TableRow
android:layout_marginTop="10dp"
android:gravity="center_vertical" >
<TextView
android:textColor="#FFFFFFFF"
android:textSize="16sp"
android:textStyle="bold"
android:text="Addition Drills:"/>
</TableRow>
</TableLayout>
Why does it crashes?
Have a look here:
12-21 22:06:32.818: E/AndroidRuntime(610): Caused by: java.lang.NullPointerException
12-21 22:06:32.818: E/AndroidRuntime(610): at com.simplemathgame.GamePlayActivity.onCreate(GamePlayActivity.java:31)
Line 31 of GamePlayActivity.java is this line:
addDrills = Integer.parseInt((String) numberOfAddDrills.getText());
Since the only thing on this line that you reference a member or method of is numberOfAddDrills, then it must be null.
Consider that you are checking for exceptions when using findViewById; however, if the view is not found it will just return null, not throw an exception.
Have a look at the activity_game_play.xml you posted; there is no TextView with android:id="#+id/add_drills_number". You need to create it, and the same deal for the other five TextViews.
Oh, and a hint: Don't just catch generic exceptions with } catch (Exception e1) {, especially if you have no intent of reading the logs. I can't tell you how many times people have missed errors from doing this.
If you want to pass values from another layout, you have two options: keep a reference to the View objects (this is a bit silly, don't do this); or pass the data you need from them to your new Activity:
startGameDrill.putExtra("myIntExtra", 5); // For example
Then, in GamePlayActivity.onCreate(), you can fetch it using getIntent()'s extras:
Bundle extras = getIntent().getExtras();
int myIntExtra = extras.getInt("myIntExtra");
Then use that value instead of relying on the view in the previous layout. There is a fuller example in this answer.
Follow the stacktrace until you find some references to your classes:
It shows:
12-21 22:06:32.818: E/AndroidRuntime(610): Caused by: java.lang.NullPointerException
12-21 22:06:32.818: E/AndroidRuntime(610): at com.simplemathgame.GamePlayActivity.onCreate(GamePlayActivity.java:31)
So you are creating a NullPointerException at line 31 in GamePlayActivity.java
Line 31:
addDrills = Integer.parseInt((String) numberOfAddDrills.getText());
so maybe numberOfAddDrills is null?

Categories