App Crashing instantly, unexplained - android

My code is written to first bring up a button in the LoginActivity and then when pressed load another activity. But as of right now, the app crashes both on my S4 and an emulator on launch. I have tried debugging mode but haven't received any useful information. Here is my LoginActivity code (main activity):
package com.JTInc.tag;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
public class LoginActivity extends FragmentActivity {
public void gotomap (View View){
Intent ii = new Intent(getActivity(), MapActivity.class);
startActivity(ii);
}
private void startActivity(Intent ii) {
// TODO Auto-generated method stub
}
private Context getActivity() {
//TODO Auto-generated method stub
return null;
}
}
Here is the mapviewer.xml code (the main layout)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/gotomap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gotomap"
android:onClick="gotomap" />
</LinearLayout>
Any and all help is appreciated, Thanks.

Related

List Crashes App when updated

I'm trying to get a ListView to show the contents of a simple array but my program crashes at the setAdapeter line. As I understand this is supposed to be because the final value comes out as null but I don't see why that would be the case or how to fix it. I have already tried using ArrayAdapeter instead as well as catching the null exception with a try block. The former changes nothing and the latter simply shows a blank activity with no list to speak of. Please help.
Here's Main Activity
package ballton.fowdeckbuilder;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ArrayAdapter;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnDecks = (Button) (findViewById(R.id.btnDecks));
Button btnCards = (Button) (findViewById(R.id.btnCards));
btnDecks.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, DeckCatalogue.class));
}
});
btnCards.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, CardCatalogue.class));
}
});
}
}
Here's the activity with the Problem
package ballton.fowdeckbuilder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class DeckCatalogue extends AppCompatActivity {
ListView Ldecks;
String TAG = "TAG";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deck_catalogue);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Ldecks = (ListView) (findViewById(R.id.DeckList));
String Decks[] = new String[] {"Faria","Melgis"};
ListAdapter feed = (new ArrayAdapter<String>(this, R.layout.show_deck, Decks));
Ldecks.setAdapter(feed);
}
}
Here's the Layout for that activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ballton.fowdeckbuilder.DeckCatalogue"
tools:showIn="#layout/activity_deck_catalogue">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/DeckList"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
And Here's the layout XML I use for the list times
<?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/Deck" />
</LinearLayout>
Use this code instead of yours:
ListAdapter feed = (new ArrayAdapter<String>(this, R.layout.show_deck, R.id.Deck, Decks));
This happened because you must supply the resource ID (as your xml: R.id.Deck) for the TextView you used for ListView.

Do not see any change on runtime eclipse android

I Change an activity background color in eclipse,but I don't any change in run time. why?
this is activity XML code,I use android:background="#ff0000" to change background cokor:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="vertical"
tools:content=".TestingDetailsActivity"
android:background="#ff0000">
<Button
android:id="#+id/btnExistsTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/ExamList" />
</LinearLayout>
and java code:
package com.tutecentral.restfulapiclient;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TestingDetailsActivity extends Activity {
Button btnExistsTest;
protected void onCreate() {
//super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testing);
btnExistsTest=(Button) findViewById(R.id.btnExistsTest);
btnExistsTest.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(TestingDetailsActivity.this,ExamListActivity.class);
startActivity(i);
}
}) ;
}
}
Manually uninstall the APK file from your phone and then re-run the app from your IDE. Sometimes these kind of glitches happen.

Android multi stroke gesture not working

I modified an existing app,GestureBuilder,to accept multiple strokes.Hence to accept the letter A,D, F and so on. I created a simple app which recognises if the letter is correct or not.My problem is:
1.I have successfully recorded multi stroke letter in a file called gesture with gestureBuilder.
2.My application does not accept multi stroke gesture.But i have set fadeoffset to 1000 and gesturestroketype as multiple.I do not know why this is happening.The moment I enter next xtroke to write capital A my previous stroke dissapears.I cant write multi stroke letters/symbols.
Code:
xml file:
<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"
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=".MainActivity"
>
<android.gesture.GestureOverlayView
android:id="#+id/gestures_overlay"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:fadeOffset="5000"
android:eventsInterceptionEnabled="true"
android:gestureStrokeType="multiple" />
</LinearLayout>
java file:
package com.example.gesture_letter;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGestureListener;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.gesture.Prediction;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity implements OnGesturePerformedListener {
GestureLibrary mLibrary;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GestureOverlayView gestureoverlayview=new GestureOverlayView(this);
View inflate=getLayoutInflater().inflate(R.layout.activity_main,null);
gestureoverlayview.setGestureColor(Color.rgb(0, 255, 0));
gestureoverlayview.setGestureVisible(true);
gestureoverlayview.setUncertainGestureColor(Color.rgb(0,0,255));
gestureoverlayview.addView(inflate);
gestureoverlayview.addOnGesturePerformedListener(this);
mLibrary=GestureLibraries.fromRawResource(this,R.raw.gestures);
if(!mLibrary.load())
{
Log.i("debug","FAILED");
}
else
{
Log.i("debug","LOADED");
}
Log.i("debug","OnCreate");
setContentView(gestureoverlayview);
}
#Override
public void onGesturePerformed(GestureOverlayView arg0, Gesture arg1) {
// TODO Auto-generated method stub
ArrayList<Prediction> predictions=mLibrary.recognize(arg1);
if(predictions.size()>0)
{
Prediction prediction=predictions.get(0);
if(prediction.score>1.0)
{
String s=prediction.name;
Toast.makeText(getApplicationContext(), s,Toast.LENGTH_LONG).show();
}
else
if(prediction.score<1.0)
{
Toast.makeText(getApplicationContext(), "None",Toast.LENGTH_LONG).show();
}
}
}
}
Thank you.
I also would like a good resource for gesture application building.thank you
I do not know why, android:GestureStrokeType="multiple" did not work. It struck me to try it from the java side. I set :
gestureoverlayview.setGestureStrokeType(GestureOverlayView.GESTURE_STROKE_TYPE_MULTIPLE);
gestureoverlayview is an object of GestureOverlayView(you can name it anything)
(in main_activity.java file for newbies)
Then you'll see it works.
I think its a bug, I'm not sure.I spent weeks hovering on this :(
The problem is that you create a new GestureOverlayView :
GestureOverlayView gestureoverlayview=new GestureOverlayView(this);
You should call the view defined in the xml with findViewById(R.id.gesture_overlay);

setOnClickListener makes Force Close

When I launch the application and click the button to go to the Activity, I suddenly get a Force Close. I've tried to erase it all and write it again, but it is still there. What could be the problem?
package com.alexgascon.formuladora;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Matematicas extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
BtnMCD.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
Intent MCDintent = new Intent(Matematicas.this,Maximocomun.class);
startActivity(MCDintent);
}
});
}
}
And here is the layout code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pizarramatesverde"
android:gravity="center" >
<Button
android:id="#+id/ecsegundogrado"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/ecsegundo"
android:textColor="#color/Negro"
/>
<Button
android:id="#+id/fracciones"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/fracciones"
android:layout_below="#id/ecsegundogrado"
android:textColor="#color/Negro"
/>
<Button
android:id="#+id/maximocomunBoton"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/maximocomun"
android:layout_below="#id/fracciones"
android:layout_marginBottom="80sp"
android:textColor="#color/Negro"
/>
</RelativeLayout>
You need to call setContentView before findViewById:
setContentView(R.layout.yourlayoutxmlname);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
You need to call setContentView(R.layout.yourxmlLayout); to have the layout being referenced on your activity class.
Try to pop a toast from the click listener and see if it works. If it does - then the problem is in the activity that you want to launch.
You need to add the setContentView(R.layout.yourlayoutxmlname);.
Try the following code:
package com.alexgascon.formuladora;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Matematicas extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayoutxmlname);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
BtnMCD.setOnClickListener( new OnClickListener(){
#Override
public void onClick(View arg0) {
Intent MCDintent = new Intent(Matematicas.this,Maximocomun.class);
startActivity(MCDintent);
}
});
}
}

Why do I get "unfortunately dialer has stopped working"?

When I run following code I see that "unfortunately dialer has stopped working".
Here is a snippet of my code:
DialerActivity.java
package com.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
import android.widget.Button;
import android.view.*;
public class DialerActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button callButton=(Button) findViewById(R.id.callButton);
callButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
try {
Intent CallIntent =
new Intent(Intent.ACTION_CALL,Uri.parse("tel:9563460376"));
CallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(CallIntent);
}
catch(Exception e)
{
}
}
});
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<button android:id="#+id/callButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ShowDialer"
android:background="#d3d3d3">
</button>
</LinearLayout>
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hell">sanjoy</string>
<string name="app_name">Test</string>
<string name="button">ShowDialer</string>
</resources>
Why would this be happening?
Intent serviceIntent = new Intent(context, YourClass.class);
serviceIntent.setAction("android.intent.action.NEW_OUTGOING_CALL");
serviceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceIntent);
try this one, and not forget to add permission in Manifest.

Categories

Resources