2 Replies - 867 Views - Last Post: 30 March 2014 - 11:38 PM

#1 adn258   User is offline

  • D.I.C Addict

Reputation: 12
  • View blog
  • Posts: 816
  • Joined: 31-August 11

I Can't Even Get Simple Android Applications To Work?

Posted 25 March 2014 - 11:49 AM

So I've just started programming with android; I've programmed in Java C# C++ and other languages before. Since I haven't had a lot of experience with android I figure I'd start with a simple app first.

I wanted to create an App with a button and when the button is clicked a standard alert or dialog would appear. Easy enough right? It's been a nightmare. I decided hey maybe the dialog is too complicated lets just display Hello World when a button is clicked using Toast text.

Here's my code:

package com.example.test;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction()
					.add(R.id.container, new PlaceholderFragment()).commit();
		}
		
		Button btn = (Button)findViewById(R.id.button1);  
	       btn.setonclickListener(new View.onclickListener(){
	    	  public void onclick(View v)
	    	  {
	    		 Toast.makeText(getBaseContext(), "Hello World", Toast.LENGTH_SHORT).show();
	    	  }
	       });

	}
}




Here is a simple output (I can't seem to get it all) of the errors as it's running. Note: I'm pretty sure this is being caused by something that I am doing due to the fact that when I create an App with NOTHING other than the default window created by default in Eclipse it runs just fine. What's the problem?



03-25 12:36:58.622: E/Trace(642): error opening trace file: No such file or directory (2)
03-25 12:36:59.112: D/AndroidRuntime(642): Shutting down VM
03-25 12:36:59.112: W/dalvikvm(642): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
03-25 12:36:59.132: E/AndroidRuntime(642): FATAL EXCEPTION: main
03-25 12:36:59.132: E/AndroidRuntime(642): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: java.lang.NullPointerException
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.os.Looper.loop(Looper.java:137)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.app.ActivityThread.main(ActivityThread.java:4745)
03-25 12:36:59.132: E/AndroidRuntime(642):  at java.lang.reflect.Method.invokeNative(Native Method)
03-25 12:36:59.132: E/AndroidRuntime(642):  at java.lang.reflect.Method.invoke(Method.java:511)
03-25 12:36:59.132: E/AndroidRuntime(642):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-25 12:36:59.132: E/AndroidRuntime(642):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-25 12:36:59.132: E/AndroidRuntime(642):  at dalvik.system.NativeStart.main(Native Method)
03-25 12:36:59.132: E/AndroidRuntime(642): Caused by: java.lang.NullPointerException
03-25 12:36:59.132: E/AndroidRuntime(642):  at com.example.test.MainActivity.onCreate(MainActivity.java:29)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.app.Activity.performCreate(Activity.java:5008)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-25 12:36:59.132: E/AndroidRuntime(642):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-25 12:36:59.132: E/AndroidRuntime(642):  ... 11 more



Is This A Good Question/Topic? 0
  • +

Replies To: I Can't Even Get Simple Android Applications To Work?

#2 AKMafia001   User is offline

  • </code.in.dream>
  • member icon

Reputation: 238
  • View blog
  • Posts: 738
  • Joined: 11-June 11

Re: I Can't Even Get Simple Android Applications To Work?

Posted 26 March 2014 - 11:26 AM

Did you include the android.support.v7 library to your project?

Edit: The camelCase problem in the code is in DIC editor.

This post has been edited by AKMafia001: 26 March 2014 - 11:29 AM

Was This Post Helpful? 0
  • +
  • -

#3 adn258   User is offline

  • D.I.C Addict

Reputation: 12
  • View blog
  • Posts: 816
  • Joined: 31-August 11

Re: I Can't Even Get Simple Android Applications To Work?

Posted 30 March 2014 - 11:38 PM

I figured this out there was some internal error that I fixed by re-installing eclipse (who knows what was wrong but things are working fine now)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1