ممنون اما بازم کرش کرد سود matn asli dastan رو میذارم ممنون میشم یه نگاه بندازید
بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ
مشکل اشتراک گذاری متن
مدیریت گفتگو
آخرین تغییر: 11 سال پیش
سلام به همه
برای اشتراک گذاری متن از کد زیر استفاده کردم اما وقتی در کلاس 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();
}
}
پاسخها 5
اینو بذار تو آنلکلیک، بعد از کدای دیگه اکتیوتیه 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, "اشتراک گذاری"));
موفق باشی
نظرات
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)
نظرات
اونجا چرا گذاشتی؟! بذار قبل از loader(season, name);
گذاشتم اما بارش null point رو دارم
سورس رو دوباره اصلاح کردم و گذاشتم
خب چی شد؟ درست شد؟ سورستو بذار اینجا ببینم
روی اشتراک گذاری کلیک می کنی ارور میده یا در شروع اکتیویتی؟
کد صفحه matn_asli_dastan.xml رو اینجا بذار
در شروع اکتیویتی متن اصلی کرش میکنه.کد متن اصلی رو هم بالا گذاشتم
فایل xmlشو بذار
<?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>
نظرات
مهدی جان کدتو ببین
اصلاحش کردم محسن جان.شرمنده
اینو:
txtSher =(ImageView) findViewById(R.id.txtSher);
جایگزین این کن:
txtSher =(ImageView) findViewById(R.id.img_stars);
نظرات
محسن جان ممنون وارد اکتیویتی شد حالا img stars رو کجا بذارم چون الان روی اشتراک گذاری که کلیک میکنم پیغام میده:
No apps can perform this action
خواهشم می کنم، توی دستگاه واقعی استفاده کن، احتمالا روی ایمولاتورت اپلیکیشنی با قابلیت اشتراک گذاری وجود نداره
محسن جان توی دستگاه واقعی هم همین پیغام رو میده
تو نت یه سرچ بزن کد اشتراک گذاری های مختلف رو تست بزن
ممنون بابت وقتی که گذاشتی محسن جان درست شد.
خواهش می کنم، در خدمتم موردی بود...
ممنون محبت داری شما
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
ویرایش
پیام
نظرات