بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
مشکل اشتراک گذاری متن
سلام به همه
برای اشتراک گذاری متن از کد زیر استفاده کردم اما وقتی در کلاس main میذارم اجرا نمیکنه و زمانی که در کلاس های دیگه میذارم کرش میکنه ممنون میشم کسی راهنمایی کنه
txtSher = (ImageView) findViewById(R.id.img_stars);
txtSher.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, txt_text.getText());
startActivity(Intent.createChooser(share, "اشتراگ بگذارید ... :"));
--------------------------------------------------------------------------------------
07-15 15:44:57.827: E/AndroidRuntime(1558): java.lang.RuntimeException: Unable to start activity ComponentInfo{book/book.storys}: java.lang.NullPointerException
07-15 15:44:57.827: E/AndroidRuntime(1558): Caused by: java.lang.NullPointerException
07-15 15:44:57.827: E/AndroidRuntime(1558): at book.storys.onCreate(storys.java:34)
اینم کد صفحه storys
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class storys extends ListActivity {
private database db;
private String[] Name;
private String[] Star;
private ImageView txtSher;
private String season;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.storys);
db = new database(this);
Bundle ex = getIntent().getExtras();
season = ex.getString("seasone");
refresher();
setListAdapter(new AA());
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent intent = new Intent(storys.this, matn_asli_dastan.class);
intent.putExtra("seasone", season);
intent.putExtra("name", Name[position]);
storys.this.startActivity(intent);
}
class AA extends ArrayAdapter<String> {
public AA() {
super(storys.this, R.layout.row_storys, Name);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater in = getLayoutInflater();
View row = in.inflate(R.layout.row_storys, parent, false);
TextView name = (TextView) row.findViewById(R.id.txt_name_story);
final ImageView star = (ImageView) row.findViewById(R.id.star_of);
if (Star[position].equals("1")) {
star.setImageResource(R.drawable.star_on);
} else {
star.setImageResource(R.drawable.star_of);
}
star.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
db.open();
if (Star[position].equals("1")) {
db.broozresani_doostdashtaniha("contents", season, Name[position], "0");
star.setImageResource(R.drawable.star_of);
Star[position] = "0";
} else {
db.broozresani_doostdashtaniha("contents", season, Name[position], "1 ");
star.setImageResource(R.drawable.star_on);
Star[position] = "1";
}
}
});
txtSher = (ImageView) findViewById(R.id.img_stars);
txtSher.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "This is simple text to send ");
startActivity(Intent.createChooser(share, "Share with application :"));
}
});
name.setText(Name[position]);
name.setTypeface(BookxActivity.font);
return (row);
}
}
private void refresher() {
db.open();
int save = db.shomaresh_dastan("contents", season);
Name = new String[save];
Star = new String[save];
for (int i = 0; i < save; i++) {
Name[i] = db.namayesh_dastan("contents", i, season, 1);
Star[i] = db.namayesh_dastan("contents", i, season, 4);
}
db.open();
}
}
0
0
کسی هست راهنمایی کنه (11 سال پیش)
0
0
بچه ها خواهشا یه راهنمایی بکنید (11 سال پیش)
0
0
الان شکلت کدوم خطه ؟ (11 سال پیش)
0
0
میخوای یک متغیر رو از یک Activity ببری به یک Activity دیگه ؟ (11 سال پیش)
0
0
در یکی از اکتویتی ها به نام storys گذاشتم که کرش داشت (11 سال پیش)
0
0
شما داری اینو تو لیست ویو میذاری؟ کل کدتو اینجا بذار (11 سال پیش)
0
0
آره تو لیست ویو گذاشتم الان کل کد استوری رو میذارم (11 سال پیش)
0
0
چیو میخای اشتراک بذاری؟ متنشو یا عنوانشو؟ (11 سال پیش)
0
0
متن رو میخوام اشتراک بذارم (11 سال پیش)
0
0
این سورس بارانه، تو لیست ویو بخای بذاری خیلی وقت گیره، الان نمیرسم واقعیت. اشتراک گذاری رو تو صفحه متن بذاری بهتره که! (11 سال پیش)
0
0
اونجا هم گذاشتم بازم کرش کرد (11 سال پیش)
0
0
برای صفحه مطلب کدشو واست میذارم الان (11 سال پیش)
برای این سوال 5 پاسخ وجود دارد.
پاسخ به سوال
محسن علیزاده
11 سال پیش
+1
0
اینو بذار تو آنلکلیک، بعد از کدای دیگه اکتیوتیه matn_asli_dastan:
String shareBody = txt_text.getText().toString();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, name);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "اشتراک گذاری"));
موفق باشی
پاسخ به سوال
khajavi
11 سال پیش
0
0
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class matn_asli_dastan extends Activity {
private database db;
private TextView txt_text;
private TextView txt_title;
private String season;
private String name;
private ImageView txtSher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matn_asli_dastan);
db = new database(this);
txt_text = (TextView) findViewById(R.id.txt_text);
txt_title = (TextView) findViewById(R.id.txt_title);
Bundle ex = getIntent().getExtras();
season = ex.getString("seasone");
name = ex.getString("name");
txt_text.setTypeface(BookActivity.font);
txt_text.setTextSize(BookActivity.size);
txt_text.setLineSpacing(BookActivity.space, 1);
Typeface titr = Typeface.createFromAsset(getAssets(), "font/titr.ttf");
txt_title.setTypeface(titr);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.main_txt_layout);
if (BookActivity.mood.equals("day")) {
Resources res = getResources();
Drawable dr = res.getDrawable(R.drawable.light);
rl.setBackgroundDrawable(dr);
txt_text.setTextColor(Color.BLACK);
txt_title.setTextColor(Color.BLACK);
} else {
Resources res = getResources();
Drawable dr = res.getDrawable(R.drawable.dark);
rl.setBackgroundDrawable(dr);
txt_text.setTextColor(Color.WHITE);
txt_title.setTextColor(Color.WHITE);
}
txtSher = (ImageView) findViewById(R.id.img_stars);
txtSher.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String shareBody = txt_text.getText().toString();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, name);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "اشتراک گذاری"));
}
});
loader(season, name);
}
private void loader(String season, String Name) {
db.open();
txt_title.setText(name);
txt_text.setText(db.namayesh_matn("contents", season, Name));
db.close();
}
}
-----------------------------------------------------------------------------------------------------
=-------------------------------------
07-16 23:29:55.732: E/AndroidRuntime(2173): java.lang.RuntimeException: Unable to start activity ComponentInfo{book/book.matn_asli_dastan}: java.lang.NullPointerException 07-16 23:29:55.732: E/AndroidRuntime(2173): Caused by: java.lang.NullPointerException 07-16 23:29:55.732: E/AndroidRuntime(2173): at book.matn_asli_dastan.onCreate(matn_asli_dastan.java:48)
پاسخ به سوال
khajavi
11 سال پیش
0
0
پاسخ به سوال
khajavi
11 سال پیش
0
0
<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout android:orientation="vertical" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="@+id/main_txt_layout"
xmlns:android="http://schemas.android.com/apk/res/android"><ScrollView
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:id="@+id/scrollView1"><LinearLayout android:orientation="vertical"
android:layout_height="match_parent" android:layout_width="match_parent"><ImageView
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/txtSher" android:src="@drawable/share"/><TextView
android:layout_height="wrap_content" android:layout_width="match_parent"
android:id="@+id/txt_title" android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge" android:text="Large Text"
android:gravity="center" android:layout_marginTop="15dip"
android:layout_gravity="center"/><TextView android:layout_height="wrap_content"
android:layout_width="match_parent" android:id="@+id/txt_text"
android:textColor="#000000" android:text="TextView" android:gravity="right"
android:layout_gravity="right"/><ir.adad.AdView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/ad"
token="ef57c39fe64d5eadb2f4f3386d4e"/><ir.dgad.AdView
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/adView1"/></LinearLayout></ScrollView></RelativeLayout>
پاسخ به سوال
محسن علیزاده
11 سال پیش
+1
0
اینو:
txtSher =(ImageView) findViewById(R.id.txtSher);
جایگزین این کن:
txtSher =(ImageView) findViewById(R.id.img_stars);
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .