I have a problem in String conversion here i pass a value through intent and access through bundle and now i want to convert into integer but it is showing force stopped ..........
MainActivity code:
btn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent in=new Intent(MainActivity.this,second.class);
in.putExtra("id", "12");
startActivity(in);
}
});
secondActivity code:
Bundle extras = getIntent().getExtras();
id=extras.getString("id");
btn=(Button)findViewById(R.id.button1);
tv=(TextView)findViewById(R.id.value);
btn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
int myid=Integer.parseInt(id);
//tv.setText(myid);
Toast.makeText(getApplicationContext(), myid,Toast.LENGTH_SHORT).show();
}
});
LogCat:>
09-25 18:21:52.045: E/AndroidRuntime(1555): FATAL EXCEPTION: main
09-25 18:21:52.045: E/AndroidRuntime(1555): android.content.res.Resources$NotFoundException: String resource ID #0xc
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.content.res.Resources.getText(Resources.java:230)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.widget.Toast.makeText(Toast.java:265)
09-25 18:21:52.045: E/AndroidRuntime(1555): at com.example.convert.second$1.onClick(second.java:34)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.view.View.performClick(View.java:4204)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.view.View$PerformClick.run(View.java:17355)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.os.Handler.handleCallback(Handler.java:725)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.os.Handler.dispatchMessage(Handler.java:92)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.os.Looper.loop(Looper.java:137)
09-25 18:21:52.045: E/AndroidRuntime(1555): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-25 18:21:52.045: E/AndroidRuntime(1555): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 18:21:52.045: E/AndroidRuntime(1555): at java.lang.reflect.Method.invoke(Method.java:511)
09-25 18:21:52.045: E/AndroidRuntime(1555): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-25 18:21:52.045: E/AndroidRuntime(1555): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-25 18:21:52.045: E/AndroidRuntime(1555): at dalvik.system.NativeStart.main(Native Method)
Don't do TextView.setText(int), do TextView.setText(String), that means skipping the conversation completely. There are multiple inputs setText() can take, as shown here.
What's happening in your case is that since you are converting your value over to an integer, you're inadvertently calling public final void setText (int resid) which assumes the integer passed into it is the R.id value of something in your strings.xml file.
That's clearly not what you want to be doing, so you can do one of two things to fix it:
Replace your setText() with setText("" + myid);
Stop converting your value to an int!
Related
I am attempting to add a Facebook Login to my Android application. When I launch the application at first, it logs in without any issues, but afterwards, anytime I try to log in, the application crashes.
The MainActivity.java is as follows:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.login_button);
List<String> permissionNeeds = Arrays.asList("public_profile", "user_friends");
loginButton.setReadPermissions(permissionNeeds);
try {
PackageInfo info = getPackageManager().getPackageInfo("com.example.ryans_000.facebooklogin", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
System.out.println("onSuccess");
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException exception) {
Log.v("LoginActivity", exception.getCause().toString()); }
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}}
The content_main contains the following piece of code for the button:
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />
The Logcat is showing up the following:
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: FATAL EXCEPTION: main
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: Process: com.example.ryans_000.facebooklogin, PID: 23263
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity {com.example.ryans_000.facebooklogin/com.example.ryans_000.facebooklogin.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Throwable.toString()' on a null object reference
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread.deliverResults(ActivityThread.java:3988)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread.handleSendResult(ActivityThread.java:4038)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread.access$1400(ActivityThread.java:150)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1443)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.os.Looper.loop(Looper.java:168)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5845)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Throwable.toString()' on a null object reference
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.example.ryans_000.facebooklogin.MainActivity$1.onError(MainActivity.java:92)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.facebook.login.LoginManager.finishLogin(LoginManager.java:579)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:216)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:159)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:82)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.example.ryans_000.facebooklogin.MainActivity.onActivityResult(MainActivity.java:100)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.Activity.dispatchActivityResult(Activity.java:6439)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread.deliverResults(ActivityThread.java:3984)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread.handleSendResult(ActivityThread.java:4038)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread.access$1400(ActivityThread.java:150)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1443)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.os.Looper.loop(Looper.java:168)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5845)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
02-29 09:34:45.306 23263-23263/com.example.ryans_000.facebooklogin E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
I think in your
#Override
public void onError(FacebookException exception) {
Log.v("LoginActivity", exception.getCause().toString()); }
exception.getCause is null hence trying to convert it to string is showing null pointer exception. Try fixing that.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Throwable.toString()' on a null object reference
Most probably,it points out to the line that has used toString() method which is in onError(), So try changing that.
Good Luck!
This is my update query,
ContentValues value = new ContentValues();
value.put(DBhelper.Amount, txtBudget.getText().toString());
db = helper.getWritableDatabase();
db.update(DBhelper.TABLE1, value," "+DBhelper.Description+"='"+value_in_tv,null);
db.close();
fetchData2();
Toast.makeText(this, "Update Successfully", Toast.LENGTH_LONG).show();
clearfield();
when click the button to update,it's giving fatal exception error.
value_in_tv this is the value I got from another class
Bundle data_from_list= getIntent().getExtras();
value_in_tv= data_from_list.getString("passed data key");
txr.setText(value_in_tv);
Error:
10-18 20:45:57.812 18632-18632/com.example.username.weddingplanning
E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.database.sqlite.SQLiteException: unrecognized token: "'suba" (code 1): , while compiling: UPDATE Category SET amount=?
WHERE description='suba
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:686)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1669)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1620)
at com.example.username.weddingplanning.addbudget.checkIfRowPresent(addbudget.java:134)
at com.example.username.weddingplanning.addbudget.onClick(addbudget.java:114)
at android.view.View.performClick(View.java:4439)
at android.view.View$PerformClick.run(View.java:18398)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
You forgot the closing ' in the where clause:
db.update(DBhelper.TABLE1, value," "+DBhelper.Description+"='"+value_in_tv + "'",null)
As I understood (from here) the LoopJ AndroidAsyncHttp does not uses the UI Thread, therefore i can execute its methods in the Main Thread.
but when i intilize a new instance of AsyncHttpClient the app crashes
(exception: java.lang.IllegalStateException: Could not execute method of the activity )
code :
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Send(View view) {
EditText editText = (EditText) findViewById(R.id.editText1);
String str = editText.getText().toString();
TextView div = (TextView) findViewById(R.id.textView1);
div.setText(str);
//crash
AsyncHttpClient client = new AsyncHttpClient();
}
#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);
}
}
Error:
09-25 09:58:07.427: W/dalvikvm(2514): threadid=1: thread exiting with uncaught exception (group=0xb1cb2b20)
09-25 09:58:07.477: E/AndroidRuntime(2514): FATAL EXCEPTION: main
09-25 09:58:07.477: E/AndroidRuntime(2514): Process: com.example.mysecondapp, PID: 2514
09-25 09:58:07.477: E/AndroidRuntime(2514): java.lang.IllegalStateException: Could not execute method of the activity
09-25 09:58:07.477: E/AndroidRuntime(2514): at android.view.View$1.onClick(View.java:3823)
09-25 09:58:07.477: E/AndroidRuntime(2514): at android.view.View.performClick(View.java:4438)
09-25 09:58:07.477: E/AndroidRuntime(2514): at android.view.View$PerformClick.run(View.java:18422)
09-25 09:58:07.477: E/AndroidRuntime(2514): at android.os.Handler.handleCallback(Handler.java:733)
09-25 09:58:07.477: E/AndroidRuntime(2514): at android.os.Handler.dispatchMessage(Handler.java:95)
09-25 09:58:07.477: E/AndroidRuntime(2514): at android.os.Looper.loop(Looper.java:136)
09-25 09:58:07.477: E/AndroidRuntime(2514): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-25 09:58:07.477: E/AndroidRuntime(2514): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 09:58:07.477: E/AndroidRuntime(2514): at java.lang.reflect.Method.invoke(Method.java:515)
09-25 09:58:07.477: E/AndroidRuntime(2514): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-25 09:58:07.477: E/AndroidRuntime(2514): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-25 09:58:07.477: E/AndroidRuntime(2514): at dalvik.system.NativeStart.main(Native Method)
09-25 09:58:07.477: E/AndroidRuntime(2514): Caused by: java.lang.reflect.InvocationTargetException
09-25 09:58:07.477: E/AndroidRuntime(2514): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 09:58:07.477: E/AndroidRuntime(2514): at java.lang.reflect.Method.invoke(Method.java:515)
09-25 09:58:07.477: E/AndroidRuntime(2514): at android.view.View$1.onClick(View.java:3818)
09-25 09:58:07.477: E/AndroidRuntime(2514): ... 11 more
09-25 09:58:07.477: E/AndroidRuntime(2514): Caused by: java.lang.NoClassDefFoundError: com.loopj.android.http.AsyncHttpClient
09-25 09:58:07.477: E/AndroidRuntime(2514): at com.example.mysecondapp.MainActivity.Send(MainActivity.java:46)
09-25 09:58:07.477: E/AndroidRuntime(2514): ... 14 more
You're getting a NoClassDefFoundError for com.loopj.android.http.AsyncHttpClient
If you are running from an IDE, make sure to add exported="true" to the classpathentry for android-async-http-1.4.6.jar in your .classpath file.
I had to move the jar file to the "libs" folder and then add the jar to the project... thanks everyone!
I'm trying to clean HTML with HtmlCleaner using AsyncTask. This is the code:
private class cleanHtml extends AsyncTask<Void, Void, Void>{
#Override
protected Void doInBackground(Void... arg0) {
try {
HtmlCleaner cleaner = new HtmlCleaner();
String url = "https://www.easistent.com/urniki/263/razredi/16515";
TagNode node = cleaner.clean(new URL(url));
CleanerProperties props = cleaner.getProperties();
new PrettyXmlSerializer(props).writeToFile(node, "cleaned.xml", "utf-8");
Log.i("TAG", "Executing AsyncTask");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
I'm executing AsyncTask in onCreate method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new cleanHtml().execute();
}//End of onCreate
However, nothing happens. As you can see I put log.i inside the AsyncTask to see if it is executing r not and I never see the log.i message inside logcat. What could I be doing wrong? Also, where in my phone will "cleaned.xml" appear? Since I didn't set any kind of destination folder.
Logcat (info):
09-25 20:23:31.739: W/System.err(19078): java.io.FileNotFoundException: /cleaned.xml: open failed: EROFS (Read-only file system)
09-25 20:23:31.747: W/System.err(19078): at libcore.io.IoBridge.open(IoBridge.java:409)
09-25 20:23:31.747: W/System.err(19078): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
09-25 20:23:31.747: W/System.err(19078): at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
09-25 20:23:31.755: W/System.err(19078): at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
09-25 20:23:31.755: W/System.err(19078): at org.htmlcleaner.Serializer.writeToFile(Serializer.java:131)
09-25 20:23:31.755: W/System.err(19078): at org.htmlcleaner.Serializer.writeToFile(Serializer.java:142)
09-25 20:23:31.755: W/System.err(19078): at com.whizzapps.stpsurniki.ScheudeleWithDesign$cleanHtml.doInBackground(ScheudeleWithDesign.java:36)
09-25 20:23:31.755: W/System.err(19078): at com.whizzapps.stpsurniki.ScheudeleWithDesign$cleanHtml.doInBackground(ScheudeleWithDesign.java:1)
09-25 20:23:31.755: W/System.err(19078): at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-25 20:23:31.755: W/System.err(19078): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
09-25 20:23:31.755: W/System.err(19078): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-25 20:23:31.755: W/System.err(19078): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-25 20:23:31.755: W/System.err(19078): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-25 20:23:31.755: W/System.err(19078): at java.lang.Thread.run(Thread.java:841)
09-25 20:23:31.755: W/System.err(19078): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
09-25 20:23:31.755: W/System.err(19078): at libcore.io.Posix.open(Native Method)
09-25 20:23:31.755: W/System.err(19078): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
09-25 20:23:31.763: W/System.err(19078): at libcore.io.IoBridge.open(IoBridge.java:393)
The AsncTask is executed. But the execution is not brought to an end because of an exception.
You are getting a FileNotFoundEcxeption in this line:
new PrettyXmlSerializer(props).writeToFile(node, "cleaned.xml", "utf-8");
which is caught by your catch-block preventing your app from crashing.
The Exception could be caused by:
The path to the "cleaned.xml" file not being correct.
Typos int he filename.
Here is the code I use to bring up the activity:
startActivity(new Intent(getApplicationContext(), Giveaway.class));
Here is the Activity that I am bringing up:
public class Giveaway extends Activity implements OnClickListener{
static SharedPreferences settings;
SharedPreferences.Editor prefEditor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.giveaway);
settings = getSharedPreferences("firsttime", 0);
LinearLayout facebook = (LinearLayout)findViewById(R.id.facebooklayout);
Button later = (Button)findViewById(R.id.later);
Button dontshowagain = (Button)findViewById(R.id.dontshowagain);
facebook.setOnClickListener(this);
later.setOnClickListener(this);
dontshowagain.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.facebooklayout:
Uri localuri = Uri.parse("http://www.facebook.com/pages/Bright-Design/366832480049386");
startActivity(new Intent("android.intent.action.VIEW", localuri));
break;
case R.id.later:
finish();
break;
case R.id.dontshowagain:
finish();
prefEditor = settings.edit();
prefEditor.putBoolean("showgiveaway", false);
prefEditor.commit();
break;
}
}
I have declared the Activity in my manifest folder:
<activity
android:name=".Giveaway"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog"
android:screenOrientation="portrait"/>
But I keep getting a java.lang.RuntimeException: Unable to start activity java.lang.NullPointerException error. Here is my logcat:
07-24 12:43:59.082: E/AndroidRuntime(7039): FATAL EXCEPTION: main
07-24 12:43:59.082: E/AndroidRuntime(7039): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brightdesign.blackops2/com.brightdesign.blackops2.Giveaway}: java.lang.NullPointerException
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.os.Looper.loop(Looper.java:123)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-24 12:43:59.082: E/AndroidRuntime(7039): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 12:43:59.082: E/AndroidRuntime(7039): at java.lang.reflect.Method.invoke(Method.java:521)
07-24 12:43:59.082: E/AndroidRuntime(7039): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-24 12:43:59.082: E/AndroidRuntime(7039): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-24 12:43:59.082: E/AndroidRuntime(7039): at dalvik.system.NativeStart.main(Native Method)
07-24 12:43:59.082: E/AndroidRuntime(7039): Caused by: java.lang.NullPointerException
07-24 12:43:59.082: E/AndroidRuntime(7039): at com.brightdesign.blackops2.Giveaway.onCreate(Giveaway.java:29)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-24 12:43:59.082: E/AndroidRuntime(7039): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
You need to post your layout code, but what is most likely happening is that one of these three lines is returning a null value:
LinearLayout facebook = (LinearLayout)findViewById(R.id.facebooklayout);
Button later = (Button)findViewById(R.id.later);
Button dontshowagain = (Button)findViewById(R.id.dontshowagain);
In the debugger step through those lines and if one is null, there is your problem because as soon as you try to set the on click listener it is going to fail.
Caused by: java.lang.NullPointerException
at com.brightdesign.blackops2.Giveaway.onCreate(Giveaway.java:29)
Tells us that there is a NullPointerException in Giveaway.onCreate(), specifically Giveaway.java line 29. Odds are facebook, later, and/or dontshowagain is really null. Do you have all three of these defined in giveaway.xml?
Try this...
1.
Intent i = new Intent(Your_Activity.this, Another_Activity.class);
startActivity(i);
2. This below lines points to the class and the lines which are null.
Class:
com.brightdesign.blackops2/com.brightdesign.blackops2.Giveaway}: java.lang.NullPointerException
Lines:
Please check the below four lines, i think you are getting null value here.
Uri localuri = Uri.parse("http://www.facebook.com/pages/Bright-Design/366832480049386");
LinearLayout facebook = (LinearLayout)findViewById(R.id.facebooklayout);
Button later = (Button)findViewById(R.id.later);
Button dontshowagain = (Button)findViewById(R.id.dontshowagain);